Vertex Shader part of a Fragment Shader?

Toxic Orb

New member
Hi,

I think basic N.L bumpmapping with fragment shaders is done like this:

normal map in GL_TEXTURE0_ARB and
light vector in tangent space in GL_TEXTURE1_ARB

glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
glSampleMapATI(GL_REG_1_ATI, GL_TEXTURE1_ARB, GL_SWIZZLE_STR_ATI);

glColorFragmentOp2ATI(GL_DOT3_ATI,
GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
GL_REG_0_ATI, GL_NONE, GL_BIAS_BIT_ATI|GL_2X_BIT_ATI,
GL_REG_1_ATI, GL_NONE, GL_BIAS_BIT_ATI|GL_2X_BIT_ATI);


Correct me if this is not right.
But how does the vertex shader part of this look like?
 
Re: Vertex Shader part of a Fragment Shader?

Toxic Orb said:
Hi,

I think basic N.L bumpmapping with fragment shaders is done like this:

normal map in GL_TEXTURE0_ARB and
light vector in tangent space in GL_TEXTURE1_ARB

glSampleMapATI(GL_REG_0_ATI, GL_TEXTURE0_ARB, GL_SWIZZLE_STR_ATI);
glSampleMapATI(GL_REG_1_ATI, GL_TEXTURE1_ARB, GL_SWIZZLE_STR_ATI);

glColorFragmentOp2ATI(GL_DOT3_ATI,
GL_REG_0_ATI, GL_NONE, GL_SATURATE_BIT_ATI,
GL_REG_0_ATI, GL_NONE, GL_BIAS_BIT_ATI|GL_2X_BIT_ATI,
GL_REG_1_ATI, GL_NONE, GL_BIAS_BIT_ATI|GL_2X_BIT_ATI);


Correct me if this is not right.
But how does the vertex shader part of this look like?

My vertex shader setup for N.L lighting goes as follows:
Code:
unsigned int ModelView, Projection;
unsigned int EyeVertex, Vertex, Normal, Binormal, TexCoord, Color, Light0;
unsigned int Mag, r0, r1, r2;

ModelView=glBindParameterEXT(GL_MODELVIEW_MATRIX);
Projection=glBindParameterEXT(GL_PROJECTION_MATRIX);
Vertex=glBindParameterEXT(GL_CURRENT_VERTEX_EXT);
Normal=glBindParameterEXT(GL_CURRENT_NORMAL);
Color=glBindParameterEXT(GL_CURRENT_COLOR);
Light0=glBindLightParameterEXT(GL_LIGHT0, GL_POSITION);
TexCoord=glBindTextureUnitParameterEXT(GL_TEXTURE0_ARB, GL_CURRENT_TEXTURE_COORDS);

ShaderID=glGenVertexShadersEXT(1);
glBindVertexShaderEXT(ShaderID);
glBeginVertexShaderEXT();

EyeVertex=glGenSymbolsEXT(GL_VECTOR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 1);
Binormal=glGenSymbolsEXT(GL_VECTOR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 1);
r0=glGenSymbolsEXT(GL_VECTOR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 1);
r1=glGenSymbolsEXT(GL_VECTOR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 1);
r2=glGenSymbolsEXT(GL_VECTOR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 1);
Mag=glGenSymbolsEXT(GL_SCALAR_EXT, GL_LOCAL_EXT, GL_FULL_RANGE_EXT, 1);

Tangent=glGenSymbolsEXT(GL_VECTOR_EXT, GL_VARIANT_EXT, GL_FULL_RANGE_EXT, 1);

glShaderOp2EXT(GL_OP_MULTIPLY_MATRIX_EXT, EyeVertex, ModelView, Vertex);
glShaderOp2EXT(GL_OP_MULTIPLY_MATRIX_EXT, GL_OUTPUT_VERTEX_EXT, Projection, EyeVertex);

glShaderOp2EXT(GL_OP_CROSS_PRODUCT_EXT, Binormal, Tangent, Normal);
glShaderOp2EXT(GL_OP_DOT3_EXT, Mag, Binormal, Binormal);
glShaderOp1EXT(GL_OP_RECIP_SQRT_EXT, Mag, Mag);
glShaderOp2EXT(GL_OP_MUL_EXT, Binormal, Binormal, Mag);

glShaderOp1EXT(GL_OP_MOV_EXT, GL_OUTPUT_COLOR0_EXT, Color);

glShaderOp1EXT(GL_OP_MOV_EXT, GL_OUTPUT_TEXTURE_COORD0_EXT, TexCoord);

glShaderOp2EXT(GL_OP_SUB_EXT, r0, Light0, Vertex);
glShaderOp2EXT(GL_OP_DOT3_EXT, Mag, r0, r0);
glShaderOp1EXT(GL_OP_RECIP_SQRT_EXT, Mag, Mag);
glShaderOp2EXT(GL_OP_MUL_EXT, r0, r0, Mag);

glShaderOp2EXT(GL_OP_DOT3_EXT, r1, Tangent, r0);
glWriteMaskEXT(r2, r1, GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
glShaderOp2EXT(GL_OP_DOT3_EXT, r1, Binormal, r0);
glWriteMaskEXT(r2, r1, GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
glShaderOp2EXT(GL_OP_DOT3_EXT, r1, Normal, r0);
glWriteMaskEXT(r2, r1, GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE);

glShaderOp1EXT(GL_OP_MOV_EXT, GL_OUTPUT_TEXTURE_COORD1_EXT, r2);

glEndVertexShaderEXT();

You'll need to do some changes to it for your application of corse. Also the neat thing about the way I do the setup, is that you just set the light position via glLightfv(GL_LIGHT0, GL_POSITION, lightposition).
 
Back
Top