A vp means rewrite all functions in vertex transformation stage?

I’m a beginner in OGSL, I don’t understand the following extraction from the OGSL Tutorial in http://www.lighthouse3d.com/opengl/glsl/index.php?vertexp. Does it mean if I want to use vp/fp to improve the light source shading, I can’t use OpenGL fixed functions to do texture mapping at the same time, and have to rewrite it in OGSL too?
Anybody can help to answer? Thank you!

“Once you write a vertex shader you are replacing the full functionality of the vertex processor, hence you can’t perform normal transformation and expect the fixed functionality to perform texture coordinate generation.
When a vertex shader is used it becomes responsible for replacing all the needed functionality of this stage of the pipeline.”

"As in the vertex processor, when you write a fragment shader it replaces all the fixed functionality. Therefore it is not possible to have a fragment shader texturing the fragment and leave the fog for the fixed functionality. The programmer must code all effects that the application requires. "

If you’re concerned about correct texture mapping and you’re only using a vertex program, simply pass the texture coordinates to the correct interpolants.

MOV result.texcoord[0], vertex.texcoord[0]
.
.
.
MOV result.texcoord[n], vertex.texcoord[n]

On the other hand if you’re using fragment program, then you need to manually fetch your texture fragment via TEX, TXP, TXB.

Edit: ooops, you’re talking about shaders, not programs, this is how you do it:

gl_TexCoord[0] = gl_MultiTexCoord0;
.
.
.
gl_TexCoord[n] = gl_MultiTexCoordn;

Now regarding texture mapping in the fragment shader, you need to declare Samplers corresponding to your targets type and then use the appropriate texture{2D|3D|Cube|Rect} to fetch your values.

It seems there’s no way to improve the light source shading only using OGSL without touching the texture mapping part.

In a 3D scene I created, I have already used many special texture mapping like View-Dependent Texture Mapping and Animated Texture Mapping using OpenGL fixed functionality. And I just want to improve the gouraud shading to phong shading by OGSL. It seems not as easy as I thought.

Thank you very much for the reply anyway.

You could just disable your vp/fp when you render textured objects, then enable it to do the rest.

Thank you! That seems what I want, but it comes back to my original confusion about the quotation in the OGSL tutorial,“When a vertex shader is used it becomes responsible for replacing all the needed functionality of this stage of the pipeline…”(see 1st post)
If you can just enable and disable, is it contradictory to the above quotation?

It’s quite simple, really. The moment you call glUseProgramObject(), certain bits of fixed functionality are bypassed. More specifically, if your program object contains a vertex shader, things like transforms, lighting or texgen will be bypassed. If your program object contains a fragment shader, things like texturing and fog are disabled.

If you want any of the aforementioned stuff done while your shaders are in effect, you have to do them yourself, in your shaders. The moment you disable your shaders (by calling “glUseProgramObject(0)”), however, all fixed functionality immediately returns to its normal behaviour.

Finally, note that vertex and fragment shaders are independent of each other. If you just have a vertex shader, for instance, you can still use fixed function texturing. Likewise, if you only have a fragment shader, you can still use fixed function transforms and lighting.

Although I agree with the majority of your above post, I must say that fragment and vertex shaders are not totally independant of each other in a sense where you need to manually transmit color and texture coordinates from one onto the other for the fixed functions to work properly after rasterization.
PS: that being valid where he only uses a vertex shader or program for that matter
:stuck_out_tongue:

you can get the answer form the book <OpenGL Shading Languge>.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.