struct vertex_input
{
float4 position : POSITION;
float2 uv : TEXCOORD0;
};
struct vertex_output
{
float4 position : POSITION;
float4 color : COLOR;
};
vertex_output main(
vertex_input IN
, uniform float4x4 ModelViewProj
, uniform sampler2D texture
)
{
vertex_output OUT;
OUT.position = mul(ModelViewProj, IN.position);
float tone = tex2D(texture, IN.uv);
OUT.color =(0.5, 0.5, 0.5)*tone;
OUT.color.a = 1;
return OUT;
}
Using textures in shaders
Lets assume I would like to render an Object A with a shader using a texture T (to tone the color). I supply T and the (u,v) coordinates to the vertex program (I know this might not make any sense). An example would be something like this:
But when the object is rendered are the same index (u,v) not used for all the vertices? Even though uv is supplied for each vertex I don't understand which value it has for each vertex.
But whats inside that texcoord? When it enters the vertex program I have from the view from the vertex program no control of the content of the texcoord.
When I do a lookup in a texture using that texcoord I have no idea where in the texture I am "looking".
When I do a lookup in a texture using that texcoord I have no idea where in the texture I am "looking".
I am not exactly sure what you are trying to say.
Normally, you would supply texture coordinates. Either through the glBegin/glTexCoord/glVertex/glEnd method which can be considered dead end now or via the glTexCoordPointer.
In.uv is suppose to be texcoord. If you are unsure and you want to do some debugging, make a floating point render target and change your shader slightly.
OUT.color = float4(IN.uv, 0.0, 0.0);
and in your fragment shader, output that color.
PS, I'm not a Cg user so I don't know if the code will compile or not.
What gets rendered are the texcoords of all the pixels.
Normally, you would supply texture coordinates. Either through the glBegin/glTexCoord/glVertex/glEnd method which can be considered dead end now or via the glTexCoordPointer.
In.uv is suppose to be texcoord. If you are unsure and you want to do some debugging, make a floating point render target and change your shader slightly.
OUT.color = float4(IN.uv, 0.0, 0.0);
and in your fragment shader, output that color.
PS, I'm not a Cg user so I don't know if the code will compile or not.
What gets rendered are the texcoords of all the pixels.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement