I am trying to learn shader programming in RenderMonkey, if I took a picture and want to apply some light interaction to that object.
How should I do this in a good way, I do not want to use the default openGL light, want do define one by myself.
Let say I create a color from the variable lightColor, a float shininess coefficient
and a vec3 lightPos with the x
, y
and z
position of the light source. In the default pipeline, light positions are expressed in camera coordinates. How should I do this in the best way?
And if I want a pixel shader in best quality which shader should I to to implement the shading calculation?
Let's see if this answers your question. This is old version 1.1 code, but should be easily adapted to newer versions. I've edited this code heavily from it's initial version, so I don't guarantee there are not errors in it, but I did at least compile and link it without errors.
The vertex shader:
The fragment shader:
EDIT:
To illustrate the use of the keyword "discard" (which can only be used in the fragment shader) I modified the last few lines of the fragment shader to be:
This created a cross shaped hole in the texture. You can, of course, use any condition you want in the if statement.