Skip to main content
gamedev.net
🔒 Locked

Shader tutorials

Started by CyberSlag5k Aug 3, 2006 at 7:11 PM 3 replies 1.3k views
Original Post
CyberSlag5k
CyberSlag5k
So I've been reading about shaders lately and have been accustomizing myself with GLSL. I've written 3 shaders on my own, and used a tutorial to write a 4th (a toon cel shader). I'm reading the orange book in my spare time, but alongside that I'd like to be getting a few more shaders cranked out, as I'm a hands-on learner. So I was wondering if anybody knew of any shader creation tutorials, similar to those found here. Lighthouse3d is wonderful for all things OpenGL, of course, and their shader examples are no different. They present the shader's code along with a step by step explanation of what is going on. Good stuff, but there's only a couple to be found there. Does anybody know of more? Straight up examples with no explanation are fine, but the ones that I really like are the ones that discuss the code rather than just show it. I can get by without the explanation, though, it just takes a bit longer. Thanks in advance!
Without order nothing can exist - without chaos nothing can evolve.
CyberSlag5k
CyberSlag5k
Perhaps this thread belongs in the graphics discussion forum? Or maybe even the beginner forum as I'm beginning shader creation? Or perhaps we'll let it marinade here a bit...
Without order nothing can exist - without chaos nothing can evolve.
_the_phantom_
_the_phantom_
what kind of examples are you after which aren't covered in other tutorials?

The thing about shaders is, once you get the basic ideas down, it's really just a matter of getting the maths right for the effect you are after.
Doggan
Doggan
I agree with phantom.

I would recommend just looking at existing shaders and playing with their parameters. Or, come up with an idea for a shader, and go out and read up on the maths.

ATI's RenderMonkey IDE comes with a bunch of shaders. You could take a look at the code and get some new ideas.
CyberSlag5k
CyberSlag5k
Quote:

t's really just a matter of getting the maths right for the effect you are after.


That's what I'm looking for, actually. Shader Designer comes with a bunch of examples, but I was hoping for something that would explain the shader, rather than having to extrapolate the thinking behind the shader's design.

For example, my toon shader (from Lighthouse3d) works by taking the dot product of a fragment's normal and the direction of a light source and storing that as an intensity level. Why the dot product? Because we're after the cosine of the angle between the two, because if the light is shining directly at the fragment, it should be at its highest intensity and if it's shining tangent to the surface of the normal, its intensity should be at its lowest. As cos(0) = 1 and cos(90) = 0, as the angle between the two becomes smaller, the light becomes more intense. So we know we need the cosine of the angle, and because dot(A, B) = |A||B|cos(theta), and because both the light's direction and the fragment's normal should be normalized, dot(A, B) = 1*1*cos(theta).

THAT I understand (and not just because I wrote it, heh), whereas I'd have an interesting time if all I had was:

// Vertex Shadervarying vec3 normal;void main(){	normal = gl_NormalMatrix * gl_Normal;	gl_Position = ftransform();} // Fragment Shadervarying vec3 normal;void main(){	float intensity;	vec3 normalized_normal = normalize(normal);		intensity = dot(vec3(gl_LightSource[0].position), normalized_normal);		if(intensity > 0.95)		gl_FragColor = vec4(0.5, 0.5, 1.0, 1.0);	else if(intensity > 0.50)		gl_FragColor = vec4(0.3, 0.3, 0.6, 1.0);	else if(intensity > 0.25)		gl_FragColor = vec4(0.2, 0.2, 0.4, 1.0);	else		gl_FragColor = vec4(0.1, 0.1, 0.2, 1.0);}


So, what I was hoping was for some more resources that would take an effect and explain what is being done. I have no problem finding shaders to use, but I want to write my own and having a few more examples to learn from would be a large help.
Without order nothing can exist - without chaos nothing can evolve.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.