Jump to content
  • Advertisement
Sign in to follow this  
Bobboau

some extreemly basic GLSL questions

This topic is 3717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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:


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;
}

Share this post


Link to post
Share on other sites
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);
}


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
wouldn't it make more sence to just extend the current shaders to have the ability to read what was there before them? it seems adding another shader stage would be just waistful.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!