Sign in to follow this  

GLSL - first shader

This topic is 3592 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

Hi I wrote simple 3D game. Now I want to leran shader programming - and I chose glsl. For begining I want to write simple shader like greyscale or sepia. I serach net for some tutorials ( http://www.lighthouse3d.com/ ) but I can't write this shader :( Can anyone write it for me :) ? ( I konw that greyscale = (color.r color.g + color.b)/ 3.0 but how I cant take color of every pixel gl_Color (in fragment shader) dosn't work for me ) Maybe u konw where I can find some GLSL tutorials ? One more question :) I know that I must start shader program with glUseProgramObjectARB(GLhandleARB prog) but how can I stop it :) ??? PS. Every objec on my scene (in game) has tekxture.

Share this post


Link to post
Share on other sites
You can sample a texture with texture2D(0,xy); where 0 is your first texture unit and xy is your texture coordinates. In order to use gl_Color you pass the color along in the vertex shader, this is commonly forgotten.

www.lighthouse3d.com has some basic tutorials for glsl.

And your last question, call glUseProgramObjectARB( 0 ); to use the default shader.

edit: I see you've already found light house, dig around in there, there is some good stuff. Also, www.codesampler.com.

This should get you started.

//vertex shader
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}

//fragment shader
uniform sampler2D tex;

void main()
{
vec4 texel = texture2D(tex, gl_TexCoord[0].st);

vec4 tempcolor = gl_FrontMaterial.diffuse.rgba * texel.rgba;

gl_FragColor = tempcolor;
}






I uploaded this package of shaders for your to browse through. Almost everything in the scene is rendered with the "simple" shader.
Click here.

These shaders were used to create this demo.
Click Here Too.

Share this post


Link to post
Share on other sites

This topic is 3592 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this