some extreemly basic GLSL questions
ok, I'm wanting to write a fragment shader that uses the results of the fixed function vertex proccessor for texture coords, I have 2d coords assigned currently and a 1d texture bound, how do I get the texture coords generated by the fixed function and use them to look up my texture? I am extremely new to GLSL and I couldn't find any examples of a texture lookup for a stand alone fragment shader.
I am wanting to have the lookup of the texture be based on the distance of the UV coords, i.e. something like texture1d(currently_bound_stage0_texture, sqrt(coord.u^2+coord.v^2)). I am hopping this is possible.
With GLSL, you must specify both a vertex-shader and a fragment-shader, and link them, afaik.
The only way to make use of the "fixed function" is to compile with cgc.exe into an ARB shader (asm code), instead of using the GLSL extension.... and then hope the driver generates a vertex-shader that suits you. You can't rely on that, maybe.
Your frag-shader:
And if you were to make your code reliable, here's the vertex-shader you need to have:
The only way to make use of the "fixed function" is to compile with cgc.exe into an ARB shader (asm code), instead of using the GLSL extension.... and then hope the driver generates a vertex-shader that suits you. You can't rely on that, maybe.
Your frag-shader:
uniform sampler1D tex0;void main(){ float coord0 = length(gl_TexCoord[0].xy); gl_FragColor = texture1D(tex0,coord0);}
And if you were to make your code reliable, here's the vertex-shader you need to have:
void main(){ gl_Position = ftransform(); gl_TexCoord[0] = gl_MultiTexCoord0;}
Quote:Original post by Bobboau
ok, I'm wanting to write a fragment shader that uses the results of the fixed function vertex proccessor for texture coords, I have 2d coords assigned currently and a 1d texture bound, how do I get the texture coords generated by the fixed function and use them to look up my texture? I am extremely new to GLSL and I couldn't find any examples of a texture lookup for a stand alone fragment shader.
I am wanting to have the lookup of the texture be based on the distance of the UV coords, i.e. something like texture1d(currently_bound_stage0_texture, sqrt(coord.u^2+coord.v^2)). I am hopping this is possible.
You would just create a fs and compile, link, get uniform locations.
There are plenty of example but if you want one, here it is
uniform sampler2D Texture0;void main(){ gl_FragColor = texture2D(Texture0, gl_TexCoord[0].xy);}
yeah,I knew that was simple, I just hadn't found the proper references.
a few more hours of looking and I found the document with all the answers on it. it was of course while I was looking for something completely different though.
one last quick question, is there a reliable way of getting a fragment's previous color? from what I see gl_FragColor is undefined before you write to it.
a few more hours of looking and I found the document with all the answers on it. it was of course while I was looking for something completely different though.
one last quick question, is there a reliable way of getting a fragment's previous color? from what I see gl_FragColor is undefined before you write to it.
Quote:Original post by Bobboau
one last quick question, is there a reliable way of getting a fragment's previous color? from what I see gl_FragColor is undefined before you write to it.
The specs doesn't say anything about reading from gl_FragColor.
You should write to a render to texture and then in the next pass, bind the texture and sample it. That's the standard way of doing it.
the spec sheet I found said it was undefined.
and unfortunately rendering to a texture and using it the next frame doesn't seem to be an option, but fortunately I was able to get my desired effect with a little manipulation of alpha blending.
and unfortunately rendering to a texture and using it the next frame doesn't seem to be an option, but fortunately I was able to get my desired effect with a little manipulation of alpha blending.
It's possible the next generation of hw will have blending shader support. It would be a new stage I image so you create a small shader just for blending.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement