PDA

View Full Version : Vertex program, NV_register_combiners AND fog.



Ixox
03-25-2002, 12:04 AM
Hi there,

I have a set of vertex program / NV_register_combiners that work rather well.
My problem is that i cannot manage to use the FOG.

If i use vertex programs, should i fill the o[FOGC] register. I tried and it seems it doesn't change the content of GL_FOG in the combiners.
If i disable the vertex program, the FOG works with the openGL classical equation.

My question is: how to send fog coordinate from vertex program to NV_register_combiners

Thanks for the answer,
Regards,

Xavier


P.S :
My final combiner fog entry is :
glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_FOG, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);

Nutty
03-25-2002, 12:22 AM
You do realize the FOGC register accepts values between 0 and 1?

Nutty

Ixox
03-25-2002, 12:27 AM
Yes. I tried with constant value.
Where must i write the fog coordinate in the vertex program : o[FOGC].x,o[FOGC].y, o[FOGC].z, o[FOGC].w ?

In the combiners then, Do i do right where i'm using the ALPHA value of GL_FOG ? (I don't need FOG color).

I fell i'm missing something important.

Nutty
03-25-2002, 12:31 AM
You write it to o[FOGC].x

I dont think I've ever accessed fog in the RC's before.

Try removing the register combiners, so that the OpenGL pipe will add in the fog itself, and see if that works. If it does, then it's your RC's, if not then you still haven't setup fog correctly.

Are you doing a glEnable(GL_FOG); for vertex program fog? I can't remember if this is needed, tho it probably is.

Nutty

Ixox
03-25-2002, 01:04 AM
When i disable vertex program and still use RCs the fog work.

So i think the RCs are OK as well as the fog setting.

I thought i found the solution by adding : glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
to enable fog coordinate, so that i can specify them in the vertex program but it doesn't change anything :-(

Nutty
03-25-2002, 04:55 AM
No you dont need to do that.

Are you sure you're setting a fog color and everything?

Heres how I set my vertex program fog up.




glEnable(GL_FOG);

glFogi (GL_FOG_MODE, GL_LINEAR);

glFogfv(GL_FOG_COLOR, fogColor);

glHint (GL_FOG_HINT, GL_NICEST);//Probably wont make a difference as we're computing via vertex program.



Do that, then write your value to o[FOGC].x with a value between 0 and 1. It should work!

What drivers are you using? There was an instance were vertex program fog was inverted or something, around driver 23.xxish.. Make sure your have the latest drivers.

Nutty

Ixox
03-25-2002, 05:40 AM
First, Thank you Nutty for your help :-)

I use last Linux driver 28.02.

Here is my Rcs:
-----------------------------
float halfMul[] = {.6,.6,.6,0}; // L.N coef
float halfAdd[] = {.4,.4,.4,0}; // ambiant

glCombinerParameterfvNV( GL_CONSTANT_COLOR0_NV,halfMul);
glCombinerParameterfvNV( GL_CONSTANT_COLOR1_NV,halfAdd);

glCombinerParameteriNV( GL_NUM_GENERAL_COMBINERS_NV,2);

glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV, GL_PRIMARY_COLOR_NV, GL_EXPAND_NORMAL_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV, GL_TEXTURE1_ARB, GL_EXPAND_NORMAL_NV, GL_RGB);
glCombinerOutputNV(GL_COMBINER0_NV, GL_RGB, GL_SPARE0_NV, GL_DISCARD_NV, GL_DISCARD_NV, GL_NONE, GL_NONE , GL_TRUE, GL_FALSE, GL_FALSE);

glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_A_NV, GL_SPARE0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_B_NV, GL_CONSTANT_COLOR0_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_INVERT_NV, GL_RGB);
glCombinerInputNV(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_D_NV, GL_CONSTANT_COLOR1_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glCombinerOutputNV(GL_COMBINER1_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV, GL_SPARE1_NV, GL_NONE, GL_NONE, GL_FALSE, GL_FALSE, GL_FALSE);

glFinalCombinerInputNV(GL_VARIABLE_A_NV, GL_FOG, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);
glFinalCombinerInputNV(GL_VARIABLE_B_NV, GL_E_TIMES_F_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_C_NV, GL_ZERO, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_D_NV, GL_SECONDARY_COLOR_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);

glFinalCombinerInputNV(GL_VARIABLE_E_NV, GL_SPARE1_NV, GL_UNSIGNED_IDENTITY_NV, GL_RGB);
glFinalCombinerInputNV(GL_VARIABLE_F_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_RGB);

glFinalCombinerInputNV(GL_VARIABLE_G_NV, GL_TEXTURE0_ARB, GL_UNSIGNED_IDENTITY_NV, GL_ALPHA);

glEnable(GL_REGISTER_COMBINERS_NV);

----------------------------------

When i enable vertex program, whatever i put from 0 to 1 in o[FOGC] the result is the same.
I disable vertex program and the fog works. The other things computed in the vertex program TEX0, TEX1, HPOS, COL0, COL1 work and it doesn't produce any error in openGL.

Here is the fog i enable:
glEnable(GL_FOG);
glFogf(GL_FOG_MODE,GL_LINEAR);
glFogf(GL_FOG_START, 40);
glFogf(GL_FOG_END, 70);
glFogfv(GL_FOG_COLOR,GLvar->nothing);


Xavier

Nutty
03-25-2002, 11:20 AM
Can't see anything wrong, although in Combiner stage 1, your muxsum is doing

(A*B) + (C*D), and C is 0, so you're losing D.

Your fog start and end values of course wont be used when Vertex program fog is produced. And what is GLvar->nothing?? Surely you should be setting a fog color? Or is that your way of setting it to black?

If your RC's work without VP's, then the only thing I can thinkof, is that your drivers have a problem with Vertex Program fog in the linux version.

Are you running this on GF3+, or in VP emulation?

Sorry, but I can't think of anything else.

Send a small app that shows the fog not working to Matt at nvidia. You can find his email address in his profile on these boards.

Nutty

P.S. If you can create a small app, you can send it to me, and I will try to compile it under windows, where I know VP fog works, and see what happens.

[This message has been edited by Nutty (edited 03-25-2002).]

Ixox
03-25-2002, 01:27 PM
Thanks again for your time Nutty,

In fact there were something VERY wrong in what I did ;-)

o[FOGC].x is not a [0,1] value. It is the distance that is used by the FOG equation.

So in VP, you don't directly set the value you get in RCs. You just overwrite the Z vertex value (which is used by default in the fog equation).

The result, the VP/RCs i talked about concerns the groud (bump map, light effect under the space ship AND FOG :-)
http://xhosxe.free.fr/glaxium.jpg

The Hardware is a Geforce 2MX.

Regards,
Xavier

Nutty
03-25-2002, 02:11 PM
Hmmm last time I did Fog in VP, I used a value of 0 to 1.

Perhaps fog start and end, default to 0,1, which would explain why it worked for me. I dunno, I can't find any docs, that document what range of value this should be.

But if you have it working, then all is well.

Nutty

Ixox
03-25-2002, 11:40 PM
The solution is in NV_Vertex_program extension:

2.14.1.5 The Vertex Result Register Set
....
FOGC is the transformed vertex's fog coordinate. The register's
first floating-point component is interpolated across the assembled
primitive during rasterization and used as the fog distance to
compute per-fragment the fog factor when fog is enabled. However,
if both fog and vertex program mode are enabled, but the FOGC vertex
result register is not written, the fog factor is overridden to 1.0.
The register's other three components are ignored.
.....

Regards,
Xavier