Jump to content
  • Advertisement
Sign in to follow this  
Marty666

Shaders

This topic is 4891 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I'm using GL_ARB_shading_language_100 from an example in combination with glut. Glutgamemode won't work... it just exits. I've got a ATI radeon 9600XT. Framerates are pretty low in full screen mode compared to windowed mode. I've got two questions: 1: Why does GLUT just exit when i try to enter game mode. 2: Is this an old extension to use when i'd like to get into pixel shaders, or still nice to start a project with? And... What kind of shaders does doom III use for the normal mapping? Is it DirectX or OGL? Thanx, Marty

Share this post


Link to post
Share on other sites
Advertisement
Well, as GLSL is the current and future shading language of OpenGL, GL_ARB_shading_language_100 is a good extension to get familiar with, along with the others which GLSL relies on.

Doom 3 uses a range of different rendering paths in OpenGL. The bumpmapping, and other effects, seem to be done through the ARB_vertex_program and ARB_fragment_program extensions (with instructions in the style of assembly language)...

Share this post


Link to post
Share on other sites
Doom 3 uses standard ARB_vertex/fragment_program shaders for most of it's effects. The shaders themselves are even plainly visible in the resource files:

interactions.vfp (condensed verison)

!!ARBvp1.0 OPTION ARB_position_invariant ;

TEMP R0, R1, R2;

PARAM defaultTexCoord = { 0, 0.5, 0, 1 };

# calculate vector to light in R0
SUB R0, program.env[4], vertex.position;

# put into texture space for TEX0
DP3 result.texcoord[0].x, vertex.attrib[9], R0;
DP3 result.texcoord[0].y, vertex.attrib[10], R0;
DP3 result.texcoord[0].z, vertex.attrib[11], R0;

# textures 1 takes the base coordinates by the texture matrix
MOV result.texcoord[1], defaultTexCoord;
DP4 result.texcoord[1].x, vertex.attrib[8], program.env[10];
DP4 result.texcoord[1].y, vertex.attrib[8], program.env[11];

# texture 2 has one texgen
MOV result.texcoord[2], defaultTexCoord;
DP4 result.texcoord[2].x, vertex.position, program.env[9];

# texture 3 has three texgens
DP4 result.texcoord[3].x, vertex.position, program.env[6];
DP4 result.texcoord[3].y, vertex.position, program.env[7];
DP4 result.texcoord[3].w, vertex.position, program.env[8];

# textures 4 takes the base coordinates by the texture matrix
MOV result.texcoord[4], defaultTexCoord;
DP4 result.texcoord[4].x, vertex.attrib[8], program.env[12];
DP4 result.texcoord[4].y, vertex.attrib[8], program.env[13];

# textures 5 takes the base coordinates by the texture matrix
MOV result.texcoord[5], defaultTexCoord;
DP4 result.texcoord[5].x, vertex.attrib[8], program.env[14];
DP4 result.texcoord[5].y, vertex.attrib[8], program.env[15];

# texture 6's texcoords will be the halfangle in texture space

# calculate normalized vector to light in R0
SUB R0, program.env[4], vertex.position;
DP3 R1, R0, R0;
RSQ R1, R1.x;
MUL R0, R0, R1.x;

# calculate normalized vector to viewer in R1
SUB R1, program.env[5], vertex.position;
DP3 R2, R1, R1;
RSQ R2, R2.x;
MUL R1, R1, R2.x;

# add together to become the half angle vector in object space (non-normalized)
ADD R0, R0, R1;

# put into texture space
DP3 result.texcoord[6].x, vertex.attrib[9], R0;
DP3 result.texcoord[6].y, vertex.attrib[10], R0;
DP3 result.texcoord[6].z, vertex.attrib[11], R0;

# generate the vertex color, which can be 1.0, color, or 1.0 - color
# for 1.0 : env[16] = 0, env[17] = 1
# for color : env[16] = 1, env[17] = 0
# for 1.0-color : env[16] = -1, env[17] = 1
MAD result.color, vertex.color, program.env[16], program.env[17];

END

#======================================================================

!!ARBfp1.0
OPTION ARB_precision_hint_fastest;

TEMP light, color, R1, R2, localNormal, specular;

PARAM subOne = { -1, -1, -1, -1 };
PARAM scaleTwo = { 2, 2, 2, 2 };


# instead of using the normalization cube map, normalize with math
DP3 specular, fragment.texcoord[6],fragment.texcoord[6];
RSQ specular, specular.x;
MUL specular, specular.x, fragment.texcoord[6];

# perform the diffuse bump mapping
TEX light, fragment.texcoord[0], texture[0], CUBE;
MAD light, light, scaleTwo, subOne;

TEX localNormal, fragment.texcoord[1], texture[1], 2D;
MOV localNormal.x, localNormal.a;
MAD localNormal, localNormal, scaleTwo, subOne;
DP3 light, light, localNormal;

# modulate by the light projection
TXP R1, fragment.texcoord[3], texture[3], 2D;
MUL light, light, R1;

# modulate by the light falloff
TXP R1, fragment.texcoord[2], texture[2], 2D;
MUL light, light, R1;

# modulate by the diffuse map and constant diffuse factor
TEX R1, fragment.texcoord[4], texture[4], 2D;
MUL color, R1, program.env[0];

# perform the specular bump mapping
DP3 specular, specular, localNormal;

# perform a dependent table read for the specular falloff
TEX R1, specular, texture[6], 2D;

# modulate by the constant specular factor
MUL R1, R1, program.env[1];

# modulate by the specular map * 2
TEX R2, fragment.texcoord[5], texture[5], 2D;
ADD R2, R2, R2;
MAD color, R1, R2, color;

MUL color, light, color;

# modify by the vertex color
MUL result.color, color, fragment.color;

END

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!