Multiple (2+) mapping coordinates in a shader.

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Mel
Competition winner
Posts: 2293
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Multiple (2+) mapping coordinates in a shader.

Post by Mel »

This is a selfquote of something i wrote elsewhere in the boards. It is a small way to have more than 2 mapping coordinates inside a shader. It is written in HSLS, but i guess that the counterpart in GLSL shouldn't be very diferent.

It also needs that you fill the correct data in your meshes BEFORE obviously. It doesn't work if you don't write the proper mapping coordinates in the meshes, in their right place, this doesn't do that kind of miracles... still...

This is the input of the vertex shader:

Code: Select all

struct{
float4 position:POSITION0;
float3 normal:NORMAL0;
float3 tangent:TEXCOORD1;
float3 binormal:TEXCOORD2;
float2 texCoord0:TEXCOORD0;
float4 color:COLOR0
};VS_INPUT
That is the layout of the current S3DVertexTangent. Yep, tangent and binormals aren't placed where they should! and their semantics don't work at least in DirectX. And indeed, it is not documented anywhere. I think it is desirable that they were used instead of placing them elsewhere.

this is the output of the vertex shader:

Code: Select all

struct{
float4 position:POSITION0;
float2 texCoord0:TEXCOORD0;
float3 normal:TEXCOORD1;
float2 texCoord1:TEXCOORD2;
float2 texCoord2:TEXCOORD3;
float2 texCoord3:TEXCOORD4;
float4 color:TEXCOORD5
};PS_INPUT
In the Vertex shader, for instance i do this....

Code: Select all

PS_INPUT vs_main(VS_INPUT IN){

PS_INPUT OUT;

OUT.Position... (whatever you want to put in the position...)
OUT.normal... (whatever you want to put in the normal...)

OUT.texCoord0 = IN.texCoord0;
OUT.texCoord1 = IN.tangent.xy;
OUT.texCoord2 = float2(IN.tangent.z,IN.binormal.x);
OUT.texCoord3 = IN.binormal.yz;

OUT.color = IN.color;

return OUT;
}
And that way you can have multiple texture coordinates in your pixel shaders.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Post Reply