Doom 3 engine release and game code
Moderator: InsideQC Admins
Re: Doom 3 engine release and game code
Oh cool i see he put together his own version of the glsl backend
ill merge my changes with his and will post a diff to him if it works as expected.
Productivity is a state of mind.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
Re: Doom 3 engine release and game code
Hmm ok compiled his version which btw was a pita :S as he forgot to up the project files so i had to recreate them from my own project.
It loads but it seems im missing some externals. Old sikkpin data from his 1.2 version allows it to load a game but its very buggy (dark and colors are all wrong) the glsl backend is not working at all yet it seems
as it fails to compile the scripts in gl2progs. i couldnt get the game data to compile at all so i used the ones from my own which allready have sikks modifications from 1.2 but im not sure if he changed it further.
I noticed he extended the arb2 fragment path to get the depth data (i thought that to be impossible hmm but cool if it works).
Im going to see if i can move my changes for the glsl backend into his code (it autodestroys shaders after loading finished and uses pointers to determine if the program is valid).
It loads but it seems im missing some externals. Old sikkpin data from his 1.2 version allows it to load a game but its very buggy (dark and colors are all wrong) the glsl backend is not working at all yet it seems
as it fails to compile the scripts in gl2progs. i couldnt get the game data to compile at all so i used the ones from my own which allready have sikks modifications from 1.2 but im not sure if he changed it further.
I noticed he extended the arb2 fragment path to get the depth data (i thought that to be impossible hmm but cool if it works).
Im going to see if i can move my changes for the glsl backend into his code (it autodestroys shaders after loading finished and uses pointers to determine if the program is valid).
Productivity is a state of mind.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
Re: Doom 3 engine release and game code
Productivity is a state of mind.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
Re: Doom 3 engine release and game code
Had a talk with Sikkpin and there are a few issues before integration will work.
You will need updated shader code because some internals where moved from engine to shaders (pointlights etc).
Still needs some tweaking it does load if you use the shaders provided but it will crash on game load mostly and when it manages to load a game things will look a bit weird (dark and colors are odd).
The game code should not be used as it wont work yet.
Reason the project files where missing was that sikk backported them to vs2008 and he was not sure if they would work for others.
You will need updated shader code because some internals where moved from engine to shaders (pointlights etc).
Still needs some tweaking it does load if you use the shaders provided but it will crash on game load mostly and when it manages to load a game things will look a bit weird (dark and colors are odd).
The game code should not be used as it wont work yet.
Reason the project files where missing was that sikk backported them to vs2008 and he was not sure if they would work for others.
Productivity is a state of mind.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
Re: Doom 3 engine release and game code
Ok its getting there slowly. You should only use the parralax or relief shaders for testing as atm they cause bugs on non flat surfaces (will hopefully be fixed once i create a new path for it in the backend).
For now enjoy these shots which are taken with normalmaps instead they are actually quite nice though not as heavily detailed as the parralax ones.



For now enjoy these shots which are taken with normalmaps instead they are actually quite nice though not as heavily detailed as the parralax ones.
Productivity is a state of mind.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
Re: Doom 3 engine release and game code
glsl backend updated by raynor
but small whoops in the code was destroying the same shader twice instead of vertexshader/fragmentshader.
Works pretty well now but still some problems interacting with the ARB2 backend when custom shaders in use.
The commit can be found at the dhewm3 site.
Works pretty well now but still some problems interacting with the ARB2 backend when custom shaders in use.
The commit can be found at the dhewm3 site.
Productivity is a state of mind.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
Re: Doom 3 engine release and game code
When did he updated? I don't see any commits in his git repo :/
- motorsep
- Posts: 231
- Joined: Wed Aug 02, 2006 11:46 pm
- Location: Texas, USA
Re: Doom 3 engine release and game code
He committed the new backend to dhewm3
not to his own repo.
Productivity is a state of mind.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
Re: Doom 3 engine release and game code
Those who allready had his old version in code can just replace the contents of draw_glsl.cpp with this.
- Code: Select all
/*
===========================================================================
Doom 3 GPL Source Code
Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
This file is part of the Doom 3 GPL Source Code ("Doom 3 Source Code").
Doom 3 Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Doom 3 Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "../idlib/precompiled.h"
#pragma hdrstop
#include "tr_local.h"
shaderProgram_t interactionShader = { -1 };
shaderProgram_t ambientInteractionShader = { -1 };
shaderProgram_t stencilShadowShader = { -1 };
/*
====================
GL_SelectTextureNoClient
====================
*/
static void GL_SelectTextureNoClient(int unit)
{
backEnd.glState.currenttmu = unit;
qglActiveTextureARB(GL_TEXTURE0_ARB + unit);
RB_LogComment( "glActiveTextureARB( %i )\n", unit );
}
/*
==================
RB_GLSL_DrawInteraction
==================
*/
static void RB_GLSL_DrawInteraction(const drawInteraction_t *din)
{
// load all the shader parameters
if (din->ambientLight)
{
qglUniform4fvARB(ambientInteractionShader.localLightOrigin, 1, din->localLightOrigin.ToFloatPtr());
qglUniform4fvARB(ambientInteractionShader.lightProjectionS, 1, din->lightProjection[0].ToFloatPtr());
qglUniform4fvARB(ambientInteractionShader.lightProjectionT, 1, din->lightProjection[1].ToFloatPtr());
qglUniform4fvARB(ambientInteractionShader.lightProjectionQ, 1, din->lightProjection[2].ToFloatPtr());
qglUniform4fvARB(ambientInteractionShader.lightFalloff, 1, din->lightProjection[3].ToFloatPtr());
qglUniform4fvARB(ambientInteractionShader.bumpMatrixS, 1, din->bumpMatrix[0].ToFloatPtr());
qglUniform4fvARB(ambientInteractionShader.bumpMatrixT, 1, din->bumpMatrix[1].ToFloatPtr());
qglUniform4fvARB(ambientInteractionShader.diffuseMatrixS, 1, din->diffuseMatrix[0].ToFloatPtr());
qglUniform4fvARB(ambientInteractionShader.diffuseMatrixT, 1, din->diffuseMatrix[1].ToFloatPtr());
static const float zero[4] = { 0, 0, 0, 0 };
static const float one[4] = { 1, 1, 1, 1 };
static const float negOne[4] = { -1, -1, -1, -1 };
switch (din->vertexColor)
{
case SVC_IGNORE:
qglUniform4fARB(ambientInteractionShader.colorModulate, zero[0], zero[1], zero[2], zero[3]);
qglUniform4fARB(ambientInteractionShader.colorAdd, one[0], one[1], one[2], one[3]);
break;
case SVC_MODULATE:
qglUniform4fARB(ambientInteractionShader.colorModulate, one[0], one[1], one[2], one[3]);
qglUniform4fARB(ambientInteractionShader.colorAdd, zero[0], zero[1], zero[2], zero[3]);
break;
case SVC_INVERSE_MODULATE:
qglUniform4fARB(ambientInteractionShader.colorModulate, negOne[0], negOne[1], negOne[2], negOne[3]);
qglUniform4fARB(ambientInteractionShader.colorAdd, one[0], one[1], one[2], one[3]);
break;
}
// set the constant color
qglUniform4fvARB(ambientInteractionShader.diffuseColor, 1, din->diffuseColor.ToFloatPtr());
}
else
{
qglUniform4fvARB(interactionShader.localLightOrigin, 1, din->localLightOrigin.ToFloatPtr());
qglUniform4fvARB(interactionShader.localViewOrigin, 1, din->localViewOrigin.ToFloatPtr());
qglUniform4fvARB(interactionShader.lightProjectionS, 1, din->lightProjection[0].ToFloatPtr());
qglUniform4fvARB(interactionShader.lightProjectionT, 1, din->lightProjection[1].ToFloatPtr());
qglUniform4fvARB(interactionShader.lightProjectionQ, 1, din->lightProjection[2].ToFloatPtr());
qglUniform4fvARB(interactionShader.lightFalloff, 1, din->lightProjection[3].ToFloatPtr());
qglUniform4fvARB(interactionShader.bumpMatrixS, 1, din->bumpMatrix[0].ToFloatPtr());
qglUniform4fvARB(interactionShader.bumpMatrixT, 1, din->bumpMatrix[1].ToFloatPtr());
qglUniform4fvARB(interactionShader.diffuseMatrixS, 1, din->diffuseMatrix[0].ToFloatPtr());
qglUniform4fvARB(interactionShader.diffuseMatrixT, 1, din->diffuseMatrix[1].ToFloatPtr());
qglUniform4fvARB(interactionShader.specularMatrixS, 1, din->specularMatrix[0].ToFloatPtr());
qglUniform4fvARB(interactionShader.specularMatrixT, 1, din->specularMatrix[1].ToFloatPtr());
static const float zero[4] = { 0, 0, 0, 0 };
static const float one[4] = { 1, 1, 1, 1 };
static const float negOne[4] = { -1, -1, -1, -1 };
switch (din->vertexColor)
{
case SVC_IGNORE:
qglUniform4fARB(interactionShader.colorModulate, zero[0], zero[1], zero[2], zero[3]);
qglUniform4fARB(interactionShader.colorAdd, one[0], one[1], one[2], one[3]);
break;
case SVC_MODULATE:
qglUniform4fARB(interactionShader.colorModulate, one[0], one[1], one[2], one[3]);
qglUniform4fARB(interactionShader.colorAdd, zero[0], zero[1], zero[2], zero[3]);
break;
case SVC_INVERSE_MODULATE:
qglUniform4fARB(interactionShader.colorModulate, negOne[0], negOne[1], negOne[2], negOne[3]);
qglUniform4fARB(interactionShader.colorAdd, one[0], one[1], one[2], one[3]);
break;
}
// set the constant colors
qglUniform4fvARB(interactionShader.diffuseColor, 1, din->diffuseColor.ToFloatPtr());
qglUniform4fvARB(interactionShader.specularColor, 1, din->specularColor.ToFloatPtr());
}
// set the textures
// texture 0 will be the per-surface bump map
GL_SelectTextureNoClient(0);
din->bumpImage->Bind();
// texture 1 will be the light falloff texture
GL_SelectTextureNoClient(1);
din->lightFalloffImage->Bind();
// texture 2 will be the light projection texture
GL_SelectTextureNoClient(2);
din->lightImage->Bind();
// texture 3 is the per-surface diffuse map
GL_SelectTextureNoClient(3);
din->diffuseImage->Bind();
if (!din->ambientLight)
{
// texture 4 is the per-surface specular map
GL_SelectTextureNoClient(4);
din->specularImage->Bind();
}
// draw it
RB_DrawElementsWithCounters(din->surf->geo);
}
/*
=============
RB_GLSL_CreateDrawInteractions
=============
*/
static void RB_GLSL_CreateDrawInteractions(const drawSurf_t *surf)
{
if (!surf) return;
// perform setup here that will be constant for all interactions
GL_State(GLS_SRCBLEND_ONE | GLS_DSTBLEND_ONE | GLS_DEPTHMASK | backEnd.depthFunc);
// bind the vertex and fragment program
if (backEnd.vLight->lightShader->IsAmbientLight())
{
if (ambientInteractionShader.program == -1)
qglUseProgramObjectARB(0);
else
qglUseProgramObjectARB(ambientInteractionShader.program);
}
else
{
if (interactionShader.program == -1)
qglUseProgramObjectARB(0);
else
qglUseProgramObjectARB(interactionShader.program);
}
// enable the vertex arrays
qglEnableVertexAttribArrayARB(8);
qglEnableVertexAttribArrayARB(9);
qglEnableVertexAttribArrayARB(10);
qglEnableVertexAttribArrayARB(11);
qglEnableClientState(GL_COLOR_ARRAY);
for (/**/; surf; surf = surf->nextOnLight)
{
// set the vertex pointers
idDrawVert *ac = (idDrawVert *)vertexCache.Position(surf->geo->ambientCache);
qglColorPointer(4, GL_UNSIGNED_BYTE, sizeof(idDrawVert), ac->color);
qglVertexAttribPointerARB(11, 3, GL_FLOAT, false, sizeof(idDrawVert), ac->normal.ToFloatPtr());
qglVertexAttribPointerARB(10, 3, GL_FLOAT, false, sizeof(idDrawVert), ac->tangents[1].ToFloatPtr());
qglVertexAttribPointerARB(9, 3, GL_FLOAT, false, sizeof(idDrawVert), ac->tangents[0].ToFloatPtr());
qglVertexAttribPointerARB(8, 2, GL_FLOAT, false, sizeof(idDrawVert), ac->st.ToFloatPtr());
qglVertexPointer(3, GL_FLOAT, sizeof(idDrawVert), ac->xyz.ToFloatPtr());
// set model matrix
if (backEnd.vLight->lightShader->IsAmbientLight())
qglUniformMatrix4fvARB(ambientInteractionShader.modelMatrix, 1, false, surf->space->modelMatrix);
else
qglUniformMatrix4fvARB(interactionShader.modelMatrix, 1, false, surf->space->modelMatrix);
// this may cause RB_GLSL_DrawInteraction to be executed multiple
// times with different colors and images if the surface or light have multiple layers
RB_CreateSingleDrawInteractions(surf, RB_GLSL_DrawInteraction);
}
qglDisableVertexAttribArrayARB(8);
qglDisableVertexAttribArrayARB(9);
qglDisableVertexAttribArrayARB(10);
qglDisableVertexAttribArrayARB(11);
qglDisableClientState(GL_COLOR_ARRAY);
// disable features
GL_SelectTextureNoClient(4);
globalImages->BindNull();
GL_SelectTextureNoClient(3);
globalImages->BindNull();
GL_SelectTextureNoClient(2);
globalImages->BindNull();
GL_SelectTextureNoClient(1);
globalImages->BindNull();
backEnd.glState.currenttmu = -1;
GL_SelectTexture(0);
qglUseProgramObjectARB(0);
}
/*
==================
RB_GLSL_DrawInteractions
==================
*/
void RB_GLSL_DrawInteractions(void)
{
viewLight_t *vLight;
GL_SelectTexture(0);
qglDisableClientState(GL_TEXTURE_COORD_ARRAY);
// for each light, perform adding and shadowing
for (vLight = backEnd.viewDef->viewLights; vLight ;vLight = vLight->next)
{
backEnd.vLight = vLight;
// do fogging later
if (vLight->lightShader->IsFogLight()) continue;
if (vLight->lightShader->IsBlendLight()) continue;
// if there are no interactions, get out!
if (!vLight->localInteractions && !vLight->globalInteractions && !vLight->translucentInteractions)
{
continue;
}
// clear the stencil buffer if needed
if (vLight->globalShadows || vLight->localShadows)
{
backEnd.currentScissor = vLight->scissorRect;
if (r_useScissor.GetBool())
{
qglScissor(backEnd.viewDef->viewport.x1 + backEnd.currentScissor.x1,
backEnd.viewDef->viewport.y1 + backEnd.currentScissor.y1,
backEnd.currentScissor.x2 + 1 - backEnd.currentScissor.x1,
backEnd.currentScissor.y2 + 1 - backEnd.currentScissor.y1);
}
qglClear(GL_STENCIL_BUFFER_BIT);
}
else
{
// no shadows, so no need to read or write the stencil buffer
// we might in theory want to use GL_ALWAYS instead of disabling
// completely, to satisfy the invarience rules
qglStencilFunc(GL_ALWAYS, 128, 255);
}
if (r_useShadowVertexProgram.GetBool())
{
qglUseProgramObjectARB(stencilShadowShader.program);
RB_StencilShadowPass(vLight->globalShadows);
RB_GLSL_CreateDrawInteractions(vLight->localInteractions);
qglUseProgramObjectARB(stencilShadowShader.program);
RB_StencilShadowPass(vLight->localShadows);
RB_GLSL_CreateDrawInteractions(vLight->globalInteractions);
// if there weren't any globalInteractions, it would have stayed on
qglUseProgramObjectARB(0);
}
else
{
RB_StencilShadowPass(vLight->globalShadows);
RB_GLSL_CreateDrawInteractions(vLight->localInteractions);
RB_StencilShadowPass(vLight->localShadows);
RB_GLSL_CreateDrawInteractions(vLight->globalInteractions);
}
// translucent surfaces never get stencil shadowed
if (r_skipTranslucent.GetBool()) continue;
qglStencilFunc(GL_ALWAYS, 128, 255);
backEnd.depthFunc = GLS_DEPTHFUNC_LESS;
RB_GLSL_CreateDrawInteractions(vLight->translucentInteractions);
backEnd.depthFunc = GLS_DEPTHFUNC_EQUAL;
}
// disable stencil shadow test
qglStencilFunc(GL_ALWAYS, 128, 255);
GL_SelectTexture(0);
qglEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
/*
=================
RB_DeleteShader
=================
*/
static void RB_DeleteShader(GLhandleARB *shader)
{
if (*shader != -1)
{
qglDeleteShader(*shader);
*shader = -1;
}
}
/*
=================
RB_LoadShader
=================
*/
static bool RB_LoadShader(const char *path, GLhandleARB *shader, GLenum type)
{
void *buf;
if (!glConfig.isInitialized)
{
return false;
}
RB_DeleteShader(shader);
// load the program even if we don't support it, so
// fs_copyfiles can generate cross-platform data dumps
fileSystem->ReadFile(path, &buf, NULL);
if (!buf)
{
common->Printf("%s: File not found\n", path);
return false;
}
*shader = qglCreateShaderObjectARB( type );
qglShaderSourceARB( *shader, 1, (const GLcharARB **)&buf, 0 );
qglCompileShaderARB( *shader );
fileSystem->FreeFile( buf );
GLint logLength;
qglGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength);
if (logLength > 1)
{
GLchar *log = (GLchar *)malloc(logLength);
qglGetShaderInfoLog(*shader, logLength, &logLength, log);
common->Printf("glGetShaderInfoLog: %s\n", log);
free(log);
}
GLint status;
qglGetShaderiv(*shader, GL_COMPILE_STATUS, &status);
if (status == 0)
{
RB_DeleteShader(shader);
return false;
}
return true;
}
/*
=================
RB_DeleteShaderProgram
=================
*/
static void RB_DeleteShaderProgram(shaderProgram_t *shaderProgram)
{
qglDetachObjectARB(shaderProgram->program, shaderProgram->fragmentShader);
qglDetachObjectARB(shaderProgram->program, shaderProgram->vertexShader);
RB_DeleteShader(&shaderProgram->vertexShader);
RB_DeleteShader(&shaderProgram->fragmentShader);
}
/*
=================
RB_LinkShaderProgram
links the GLSL vertex and fragment programs together to form a GLSL program
=================
*/
static bool RB_LinkShaderProgram(shaderProgram_t *shaderProgram, bool needsAttributes)
{
GLint linked;
shaderProgram->program = qglCreateProgramObjectARB( );
qglAttachObjectARB(shaderProgram->program, shaderProgram->vertexShader);
qglAttachObjectARB(shaderProgram->program, shaderProgram->fragmentShader);
if (needsAttributes)
{
qglBindAttribLocationARB(shaderProgram->program, 8, "attr_TexCoord");
qglBindAttribLocationARB(shaderProgram->program, 9, "attr_Tangent");
qglBindAttribLocationARB(shaderProgram->program, 10, "attr_Bitangent");
qglBindAttribLocationARB(shaderProgram->program, 11, "attr_Normal");
}
qglLinkProgramARB( shaderProgram->program );
qglGetObjectParameterivARB( shaderProgram->program, GL_OBJECT_LINK_STATUS_ARB, &linked );
if (!linked)
{
RB_DeleteShaderProgram(shaderProgram);
common->Printf( "RB_LinkShaderProgram: program failed to link\n" );
return false;
}
return true;
}
/*
=================
RB_ValidateShaderProgram
makes sure GLSL shader is valid
=================
*/
static bool RB_ValidateShaderProgram(shaderProgram_t *shaderProgram)
{
GLint validProgram;
qglValidateProgramARB(shaderProgram->program);
qglGetObjectParameterivARB(shaderProgram->program, GL_OBJECT_VALIDATE_STATUS_ARB, &validProgram);
if (!validProgram)
{
RB_DeleteShaderProgram(shaderProgram);
common->Printf( "RB_ValidateShaderProgram: program invalid\n" );
return false;
}
return true;
}
/*
=================
RB_LoadGLSLShader
loads GLSL vertex or fragment shaders
=================
*/
static bool RB_LoadGLSLShader(const char *basename, shaderProgram_t *shaderProgram, bool needsAttributes)
{
char path[1024];
common->Printf("%s\n", basename);
RB_DeleteShaderProgram(shaderProgram);
idStr::snPrintf(path, sizeof(path), "gl2progs/%s.vertex", basename);
if (!RB_LoadShader(path, &shaderProgram->vertexShader, GL_VERTEX_SHADER_ARB))
{
RB_DeleteShader(&shaderProgram->vertexShader);
common->Printf( ": Vertex shader not found\n" );
return false;
}
idStr::snPrintf(path, sizeof(path), "gl2progs/%s.fragment", basename);
if (!RB_LoadShader(path, &shaderProgram->fragmentShader, GL_FRAGMENT_SHADER_ARB))
{
RB_DeleteShader(&shaderProgram->fragmentShader);
common->Printf( ": Fragment shader not found\n" );
return false;
}
if (!RB_LinkShaderProgram(shaderProgram, needsAttributes))
{
common->Printf("program failed to link\n" );
return false;
}
if (!RB_ValidateShaderProgram(shaderProgram))
{
common->Printf("program is invalid.\n" );
return false;
}
return true;
}
/*
=================
RB_GLSL_DeleteAllGLSLShaders
=================
*/
static void RB_GLSL_DeleteAllGLSLShaders(void)
{
qglUseProgramObjectARB(0);
RB_DeleteShaderProgram(&interactionShader);
RB_DeleteShaderProgram(&ambientInteractionShader);
RB_DeleteShaderProgram(&stencilShadowShader);
}
/*
=================
RB_GLSL_InitShaders
=================
*/
static bool RB_GLSL_InitShaders(void)
{
// destroy previous runs first
RB_GLSL_DeleteAllGLSLShaders();
// load interation shaders
if (!RB_LoadGLSLShader("interaction", &interactionShader, true))
{
common->Printf("GLSL interactionShader unavailable.\n");
RB_GLSL_DeleteAllGLSLShaders();
return false;
}
// set uniform locations
interactionShader.u_normalTexture = qglGetUniformLocationARB(interactionShader.program, "u_normalTexture");
interactionShader.u_lightFalloffTexture = qglGetUniformLocationARB(interactionShader.program, "u_lightFalloffTexture");
interactionShader.u_lightProjectionTexture = qglGetUniformLocationARB(interactionShader.program, "u_lightProjectionTexture");
interactionShader.u_diffuseTexture = qglGetUniformLocationARB(interactionShader.program, "u_diffuseTexture");
interactionShader.u_specularTexture = qglGetUniformLocationARB(interactionShader.program, "u_specularTexture");
interactionShader.modelMatrix = qglGetUniformLocationARB(interactionShader.program, "u_modelMatrix");
interactionShader.localLightOrigin = qglGetUniformLocationARB(interactionShader.program, "u_lightOrigin");
interactionShader.localViewOrigin = qglGetUniformLocationARB(interactionShader.program, "u_viewOrigin");
interactionShader.lightProjectionS = qglGetUniformLocationARB(interactionShader.program, "u_lightProjectionS");
interactionShader.lightProjectionT = qglGetUniformLocationARB(interactionShader.program, "u_lightProjectionT");
interactionShader.lightProjectionQ = qglGetUniformLocationARB(interactionShader.program, "u_lightProjectionQ");
interactionShader.lightFalloff = qglGetUniformLocationARB(interactionShader.program, "u_lightFalloff");
interactionShader.bumpMatrixS = qglGetUniformLocationARB(interactionShader.program, "u_bumpMatrixS");
interactionShader.bumpMatrixT = qglGetUniformLocationARB(interactionShader.program, "u_bumpMatrixT");
interactionShader.diffuseMatrixS = qglGetUniformLocationARB(interactionShader.program, "u_diffuseMatrixS");
interactionShader.diffuseMatrixT = qglGetUniformLocationARB(interactionShader.program, "u_diffuseMatrixT");
interactionShader.specularMatrixS = qglGetUniformLocationARB(interactionShader.program, "u_specularMatrixS");
interactionShader.specularMatrixT = qglGetUniformLocationARB(interactionShader.program, "u_specularMatrixT");
interactionShader.colorModulate = qglGetUniformLocationARB(interactionShader.program, "u_colorModulate");
interactionShader.colorAdd = qglGetUniformLocationARB(interactionShader.program, "u_colorAdd");
interactionShader.diffuseColor = qglGetUniformLocationARB(interactionShader.program, "u_diffuseColor");
interactionShader.specularColor = qglGetUniformLocationARB(interactionShader.program, "u_specularColor");
// set texture locations
qglUseProgramObjectARB(interactionShader.program);
qglUniform1iARB(interactionShader.u_normalTexture, 0);
qglUniform1iARB(interactionShader.u_lightFalloffTexture, 1);
qglUniform1iARB(interactionShader.u_lightProjectionTexture, 2);
qglUniform1iARB(interactionShader.u_diffuseTexture, 3);
qglUniform1iARB(interactionShader.u_specularTexture, 4);
qglUseProgramObjectARB(0);
// load ambient interation shaders
if (!RB_LoadGLSLShader("ambientInteraction", &ambientInteractionShader, true))
{
common->Printf("GLSL ambientInteractionShader unavailable.\n");
RB_GLSL_DeleteAllGLSLShaders();
return false;
}
// set uniform locations
ambientInteractionShader.u_normalTexture = qglGetUniformLocationARB(ambientInteractionShader.program, "u_normalTexture");
ambientInteractionShader.u_lightFalloffTexture = qglGetUniformLocationARB(ambientInteractionShader.program, "u_lightFalloffTexture");
ambientInteractionShader.u_lightProjectionTexture = qglGetUniformLocationARB(ambientInteractionShader.program, "u_lightProjectionTexture");
ambientInteractionShader.u_diffuseTexture = qglGetUniformLocationARB(ambientInteractionShader.program, "u_diffuseTexture");
ambientInteractionShader.modelMatrix = qglGetUniformLocationARB(ambientInteractionShader.program, "u_modelMatrix");
ambientInteractionShader.localLightOrigin = qglGetUniformLocationARB(ambientInteractionShader.program, "u_lightOrigin");
ambientInteractionShader.lightProjectionS = qglGetUniformLocationARB(ambientInteractionShader.program, "u_lightProjectionS");
ambientInteractionShader.lightProjectionT = qglGetUniformLocationARB(ambientInteractionShader.program, "u_lightProjectionT");
ambientInteractionShader.lightProjectionQ = qglGetUniformLocationARB(ambientInteractionShader.program, "u_lightProjectionQ");
ambientInteractionShader.lightFalloff = qglGetUniformLocationARB(ambientInteractionShader.program, "u_lightFalloff");
ambientInteractionShader.bumpMatrixS = qglGetUniformLocationARB(ambientInteractionShader.program, "u_bumpMatrixS");
ambientInteractionShader.bumpMatrixT = qglGetUniformLocationARB(ambientInteractionShader.program, "u_bumpMatrixT");
ambientInteractionShader.diffuseMatrixS = qglGetUniformLocationARB(ambientInteractionShader.program, "u_diffuseMatrixS");
ambientInteractionShader.diffuseMatrixT = qglGetUniformLocationARB(ambientInteractionShader.program, "u_diffuseMatrixT");
ambientInteractionShader.colorModulate = qglGetUniformLocationARB(ambientInteractionShader.program, "u_colorModulate");
ambientInteractionShader.colorAdd = qglGetUniformLocationARB(ambientInteractionShader.program, "u_colorAdd");
ambientInteractionShader.diffuseColor = qglGetUniformLocationARB(ambientInteractionShader.program, "u_diffuseColor");
// set texture locations
qglUseProgramObjectARB(ambientInteractionShader.program);
qglUniform1iARB(ambientInteractionShader.u_normalTexture, 0);
qglUniform1iARB(ambientInteractionShader.u_lightFalloffTexture, 1);
qglUniform1iARB(ambientInteractionShader.u_lightProjectionTexture, 2);
qglUniform1iARB(ambientInteractionShader.u_diffuseTexture, 3);
qglUseProgramObjectARB(0);
// load stencil shadow extrusion shaders
if (!RB_LoadGLSLShader("stencilshadow", &stencilShadowShader, true))
{
common->Printf("GLSL stencilShadowShader unavailable\n.");
RB_GLSL_DeleteAllGLSLShaders();
return false;
}
// set uniform locations
stencilShadowShader.localLightOrigin = qglGetUniformLocationARB(stencilShadowShader.program, "u_lightOrigin");
return true;
}
/*
==================
R_ReloadGLSLShaders_f
==================
*/
void R_ReloadGLSLShaders_f(const idCmdArgs &args)
{
common->Printf( "----- R_ReloadGLSLShaders -----\n" );
if ( !RB_GLSL_InitShaders() )
{
common->Printf( "GLSL shaders failed to reload.\n" );
return;
}
common->Printf( "-------------------------------\n" );
// see if we messed anything up
GL_CheckErrors();
}
/*
==================
R_GLSL_Init
==================
*/
void R_GLSL_Init(void)
{
glConfig.allowGLSLPath = false;
if ( !glConfig.GLSLAvailable )
{
common->Printf( "Not available.\n" );
return;
}
else if ( !RB_GLSL_InitShaders() )
{
common->Printf( "GLSL shaders failed to init.\n" );
return;
}
common->Printf( "Available.\n" );
common->Printf( "---------------------------------\n" );
// see if we messed anything up
GL_CheckErrors();
glConfig.allowGLSLPath = true;
}
Productivity is a state of mind.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
Re: Doom 3 engine release and game code
I don't see that in dhewm3. This is a GLSL backend patch for dhewm3 from dhewg himself https://github.com/dhewm/dhewm3/issues/15
- motorsep
- Posts: 231
- Joined: Wed Aug 02, 2006 11:46 pm
- Location: Texas, USA
Re: Doom 3 engine release and game code
I modified it a bit
after changing the whoops with deleting the same shader twice.
The functions are just renamed so even though it doesnt look the same it is
Unessesary but i find it easier to read like that
i seem to have fixed the parralax shader btw took me quite some reading up on it.
You will have to use the one with offset limiting and its not as heavy on raising the stone surfaces as the pom one but you wont get any artifacts atleast.
heres the interaction.vfp
and the test.vfp
Warning its very very slow even on modern cards hehe.
The functions are just renamed so even though it doesnt look the same it is
Unessesary but i find it easier to read like that
i seem to have fixed the parralax shader btw took me quite some reading up on it.
You will have to use the one with offset limiting and its not as heavy on raising the stone surfaces as the pom one but you wont get any artifacts atleast.
heres the interaction.vfp
- Code: Select all
###==============================================================================
# Doom 3 Interaction Vertex/Fragment Program
#
# Custom Blinn-Phong Lighting Model w/ Parallax Mapping (Isotropic)
###==============================================================================
#
# --------------------------------------
# input:
#
# attrib[8] = texture coordinates
# attrib[9] = global tangent
# attrib[10] = global bitangent
# attrib[11] = global normal
#
# env[0] = diffuse modifier
# env[1] = specular modifier
# env[2] = ?
# env[3] = ?
# env[4] = localLightOrigin
# env[5] = localViewOrigin
# env[6] = lightProjection S
# env[7] = lightProjection T
# env[8] = lightProjection Q
# env[9] = lightFalloff S
# env[10] = bumpMatrix S
# env[11] = bumpMatrix T
# env[12] = diffuseMatrix S
# env[13] = diffuseMatrix T
# env[14] = specularMatrix S
# env[15] = specularMatrix T
# env[16] = vertex color modulate
# env[17] = vertex color add
#
#--------------------------------------
# output:
#
# texture 0 = normalization cube map
# texture 1 = per-surface normal map
# texture 2 = 1D light falloff texture
# texture 3 = 2D light projection texture
# texture 4 = per-surface diffuse map
# texture 5 = per-surface specular map
# texture 6 = specular lookup table
#
#--------------------------------------
###==============================================================================
!!ARBvp1.0
OPTION ARB_position_invariant;
# Instruction Count: 29
PARAM defaultTC = { 0.0, 0.5, 0.0, 1.0 };
# get eye vector from the driver instead of from doom3
PARAM invTrans[4] = {state.matrix.modelview.invtrans};
TEMP R0;
# calculate vector to light in R0
ADD 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;
# texture 1 takes the base coordinates by the texture matrix
MOV result.texcoord[1], defaultTC;
DP4 result.texcoord[1].x, vertex.attrib[8], program.env[10];
DP4 result.texcoord[1].y, vertex.attrib[8], program.env[11];
# texture 2 takes the base coordinates by the texture matrix
DP4 result.texcoord[2].x, vertex.attrib[8], program.env[12];
DP4 result.texcoord[2].y, vertex.attrib[8], program.env[13];
DP4 result.texcoord[2].z, vertex.attrib[8], program.env[14];
DP4 result.texcoord[2].w, vertex.attrib[8], program.env[15];
# 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].z, vertex.position, program.env[9];
DP4 result.texcoord[3].w, vertex.position, program.env[8];
# calculate vector to viewer in R0 use SUB instead of ADD
SUB R0, invTrans[3], vertex.position;
# put into texture space for TEX6
DP3 result.texcoord[4].x, vertex.attrib[9], R0;
DP3 result.texcoord[4].y, vertex.attrib[10], R0;
DP3 result.texcoord[4].z, vertex.attrib[11], R0;
# tangent space -> world space conversion matrix
DP3 result.texcoord[5].x, vertex.attrib[9], program.env[6];
DP3 result.texcoord[5].y, vertex.attrib[10], program.env[6];
DP3 result.texcoord[5].z, vertex.attrib[11], program.env[6];
DP3 result.texcoord[6].x, vertex.attrib[9], program.env[7];
DP3 result.texcoord[6].y, vertex.attrib[10], program.env[7];
DP3 result.texcoord[6].z, vertex.attrib[11], program.env[7];
DP3 result.texcoord[7].x, vertex.attrib[9], program.env[9];
DP3 result.texcoord[7].y, vertex.attrib[10], program.env[9];
DP3 result.texcoord[7].z, vertex.attrib[11], program.env[9];
# generate the vertex color, which can be 1.0, color, or 1.0 - color
# for 1.0 : env[16] = 0.0, env[17] = 1.0
# for color : env[16] = 1.0, env[17] = 0.0
# for 1.0 - color : env[16] = -1.0, env[17] = 1.0
MAD result.color.xyz, vertex.color, program.env[16], program.env[17];
END
#==================================================================================
!!ARBfp1.0
OPTION ARB_precision_hint_nicest;
# Instruction Count: ALU: 97 TEX: 6 Total: 103
OUTPUT oColor = result.color;
ATTRIB vColor = fragment.color;
ATTRIB lightVecTC = fragment.texcoord[0];
ATTRIB normalTC = fragment.texcoord[1];
ATTRIB diffspecTC = fragment.texcoord[2];
ATTRIB lightProjTC = fragment.texcoord[3];
ATTRIB viewVecTC = fragment.texcoord[4];
ATTRIB tangent = fragment.texcoord[5];
ATTRIB bitangent = fragment.texcoord[6];
ATTRIB normal = fragment.texcoord[7];
PARAM lightColor = program.env[0];
PARAM specColor = program.env[1];
PARAM const = { 1.0, 2.0, 4.0, 5.0 };
PARAM const2 = { 0.25, 0.5, 0.75, 0.75 };
PARAM skyColor = { 1.0, 1.0, 1.0 };
PARAM grndColor = { 0.1, 0.1, 0.1 };
PARAM lumVec = { 0.212671, 0.715160, 0.072169 };
PARAM specExp = 256.0;
PARAM M_PI = 3.1415926535897932384626433832795;
PARAM M_8PI = 25.132741228718345907701147066236;
PARAM M_inv2PI = 0.15915494309189533576888376337251;
PARAM e = 2.7182818284590452353602874713527;
PARAM gamma = { 2.4, 0.94786729857819905213270142180095, 0.41666666666666666666666666666667, 0.077399380804953560371517027863777 };
PARAM heightScale = { 0.06, -0.03 };
TEMP lightVec, viewVec, halfVec, normalVec, wNormalVec;
TEMP diffuse, specular, gloss, rough, fresnel, color, ambient, shadow;
TEMP light, hemi, atten, rim, lightFall, lightProj, lightCube, lightCol;
TEMP NdotL, NdotV, NdotH, VdotH, VdotL;
TEMP R1, R2;
# load falloff/projection maps
TEX lightFall, lightProjTC.zzzz, texture[2], 2D;
TXP lightProj, lightProjTC.xyzw, texture[3], 2D;
# calculate attenuation
MUL lightProj, lightProj, lightProj;
MUL atten, lightFall, lightProj;
# early out - attenuation
DP3 atten.w, atten, const.x;
SGE atten.w, 0.0, atten.w;
KIL -atten.w;
# normalize the vector to the viewer
DP3 viewVec.w, viewVecTC, viewVecTC;
RSQ viewVec.w, viewVec.w;
MUL viewVec.xyz, viewVecTC, viewVec.w;
# load height map then scale & bias
TEX R1, diffspecTC.zwzw, texture[5], 2D;
MAD R1.w, R1.w, heightScale.x, heightScale.y;
# calculate new texcoords
MAD R1.xy, R1.w, viewVec.xyxy, normalTC;
MAD R2, R1.w, viewVec.xyxy, diffspecTC;
# load texture maps
TEX ambient, lightVecTC, texture[0], CUBE;
TEX normalVec, R1, texture[1], 2D;
TEX diffuse, R2.xyxy, texture[4], 2D;
TEX gloss, R2.zwzw, texture[5], 2D;
DP3 rough, gloss, lumVec;
# normalize the vector to the light
DP3 lightVec.w, lightVecTC, lightVecTC;
RSQ lightVec.w, lightVec.w;
MUL lightVec.xyz, lightVecTC, lightVec.w;
# scale normal vector to -1.0<->1.0 range and normalize
MAD normalVec.xyz, normalVec.wyzx, const.y, -const.x;
DP3 normalVec.w, normalVec, normalVec;
RSQ normalVec.w, normalVec.w;
MUL normalVec.xyz, normalVec, normalVec.w;
# calculate diffuse cosine
DP3 NdotL.x, normalVec, lightVec;
# calculate light w/ self shadowing
ADD_SAT R1.x, lightVec.z, const2.y;
ADD_SAT R1.x, R1.x, R1.x;
MUL_SAT R1.x, R1.x, R1.x;
MOV_SAT R1.y, NdotL.x;
MUL R1.y, R1.y, R1.y;
LRP R1.y, rough.w, R1.y, NdotL.x;
MUL light, R1.x, R1.y;
# early out - NdotL
SLT ambient.w, ambient.w, const.x;
SGE R1.w, 0.0, light.x;
CMP R1.w, -ambient.w, 0.0, R1.w;
KIL -R1.w;
# calculate the half angle vector and normalize
ADD halfVec, lightVec, viewVec;
DP3 halfVec.w, halfVec, halfVec;
RSQ halfVec.w, halfVec.w;
MUL halfVec.xyz, halfVec, halfVec.w;
# transform normal to world space
DP3 wNormalVec.x, normalVec, tangent;
DP3 wNormalVec.y, normalVec, bitangent;
DP3 wNormalVec.z, normalVec, normal;
# normalize world space normal vector
DP3 wNormalVec.w, wNormalVec, wNormalVec;
RSQ wNormalVec.w, wNormalVec.w;
MUL wNormalVec.xyz, wNormalVec, wNormalVec.w;
# calculate vector dot products
DP3 NdotV.x, normalVec, viewVec;
DP3_SAT NdotH.x, normalVec, halfVec;
DP3_SAT VdotH.x, viewVec, halfVec;
DP3_SAT VdotL.x, viewVec, -lightVec;
# sRGB -> Linear
MUL R1, diffuse, gamma.w;
ADD R2, diffuse, 0.055;
MUL R2, R2, gamma.y;
POW R2.x, R2.x, gamma.x;
POW R2.y, R2.y, gamma.x;
POW R2.z, R2.z, gamma.x;
SGE diffuse, 0.04045, diffuse;
CMP diffuse.xyz, -diffuse, R1, R2;
# sikk - fix for materials with no diffuse map (e.g. Hellknight gob)
DP3 R1.x, lightColor, -const.x;
CMP lightCol, R1.x, lightColor, specColor;
# sRGB -> Linear
MUL R1, lightCol, gamma.w;
ADD R2, lightCol, 0.055;
MUL R2, R2, gamma.y;
POW R2.x, R2.x, gamma.x;
POW R2.y, R2.y, gamma.x;
POW R2.z, R2.z, gamma.x;
SGE lightCol, 0.04045, lightCol;
CMP lightCol.xyz, -lightCol, R1, R2;
# calculate specular term
MUL rough.x, rough.x, specExp.x;
MUL rough.y, VdotH.x, VdotH.x;
RCP rough.y, rough.y;
ADD R1.xy, rough.x, { 2.0, 4.0 };
MUL R1.x, R1.x, R1.y;
MUL R1.y, rough.x, 0.5;
EX2 R1.y, -R1.y;
ADD R1.y, R1.y, rough.x;
MUL R1.y, R1.y, M_8PI;
RCP R1.y, R1.y;
MUL rough.z, R1.x, R1.y;
ADD fresnel.x, const.x, -VdotH.x;
POW fresnel, fresnel.x, const.w;
LRP fresnel, gloss, const.x, fresnel;
CMP fresnel, -rough.x, fresnel, 0.0;
MAX NdotH.x, NdotH.x, 0.00001;
POW specular, NdotH.x, rough.x;
MUL specular, specular, rough.y;
MUL specular, specular, rough.z;
# modulate specular by fresnel and add diffuse color
MAD color, specular, fresnel, diffuse;
# calculate hemisphere lighting ambient term
MAD hemi.w, wNormalVec.z, const2.y, const2.y;
LRP hemi, hemi.w, skyColor, grndColor;
CMP light, -ambient.w, hemi, light;
# rim light
ABS R1.x, NdotV.x; # use abs since some translucent materials use light interaction
ADD R1.x, const.x, -R1.x;
POW R1.x, R1.x, const.w;
MUL_SAT R1.y, VdotL.x, VdotL.x;
MAD_SAT R1.z, rough.w, -2.0, const.x;
MUL_SAT R1, R1.xzzz, R1.yzzz;
MUL rim, R1.x, R1.y;
LRP rim, color, 1.0, rim;
CMP color, -ambient.w, color, rim; # cancel rim lighting for ambient lights
# final modulation
MUL color, color, light;
MUL color, color, lightCol;
MUL color, color, atten;
# Linear -> sRGB
MUL R1, color, 12.92;
POW R2.x, color.x, gamma.z;
POW R2.y, color.y, gamma.z;
POW R2.z, color.z, gamma.z;
MAD R2, R2, 1.055, -0.055;
SGE color, 0.0031308, color;
CMP color.xyz, -color, R1, R2;
# modify by the vertex color
MUL oColor.xyz, color, vColor;
END
and the test.vfp
- Code: Select all
###==============================================================================
# Doom 3 Interaction Vertex/Fragment Program
#
# Custom Blinn-Phong Lighting Model (Isotropic)
###==============================================================================
#
# --------------------------------------
# input:
#
# attrib[8] = texture coordinates
# attrib[9] = global tangent
# attrib[10] = global bitangent
# attrib[11] = global normal
#
# env[0] = diffuse modifier
# env[1] = specular modifier
# env[2] = ?
# env[3] = ?
# env[4] = localLightOrigin
# env[5] = localViewOrigin
# env[6] = lightProjection S
# env[7] = lightProjection T
# env[8] = lightProjection Q
# env[9] = lightFalloff S
# env[10] = bumpMatrix S
# env[11] = bumpMatrix T
# env[12] = diffuseMatrix S
# env[13] = diffuseMatrix T
# env[14] = specularMatrix S
# env[15] = specularMatrix T
# env[16] = vertex color modulate
# env[17] = vertex color add
#
#--------------------------------------
# output:
#
# texture 0 = normalization cube map
# texture 1 = per-surface normal map
# texture 2 = 1D light falloff texture
# texture 3 = 2D light projection texture
# texture 4 = per-surface diffuse map
# texture 5 = per-surface specular map
# texture 6 = specular lookup table
#
#--------------------------------------
###==============================================================================
!!ARBvp1.0
OPTION ARB_position_invariant;
# Instruction Count: 29
PARAM defaultTC = { 0.0, 0.5, 0.0, 1.0 };
PARAM invTrans[4] = {state.matrix.modelview.invtrans};
TEMP R0;
# calculate vector to light in R0
ADD 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;
# texture 1 takes the base coordinates by the texture matrix
MOV result.texcoord[1], defaultTC;
DP4 result.texcoord[1].x, vertex.attrib[8], program.env[10];
DP4 result.texcoord[1].y, vertex.attrib[8], program.env[11];
# texture 2 takes the base coordinates by the texture matrix
DP4 result.texcoord[2].x, vertex.attrib[8], program.env[12];
DP4 result.texcoord[2].y, vertex.attrib[8], program.env[13];
DP4 result.texcoord[2].z, vertex.attrib[8], program.env[14];
DP4 result.texcoord[2].w, vertex.attrib[8], program.env[15];
# 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].z, vertex.position, program.env[9];
DP4 result.texcoord[3].w, vertex.position, program.env[8];
# calculate vector to viewer in R0
SUB R0, invTrans[3], vertex.position;
# put into texture space for TEX6
DP3 result.texcoord[4].x, vertex.attrib[9], R0;
DP3 result.texcoord[4].y, vertex.attrib[10], R0;
DP3 result.texcoord[4].z, vertex.attrib[11], R0;
# tangent space -> world space conversion matrix
DP3 result.texcoord[5].x, vertex.attrib[9], program.env[6];
DP3 result.texcoord[5].y, vertex.attrib[10], program.env[6];
DP3 result.texcoord[5].z, vertex.attrib[11], program.env[6];
DP3 result.texcoord[6].x, vertex.attrib[9], program.env[7];
DP3 result.texcoord[6].y, vertex.attrib[10], program.env[7];
DP3 result.texcoord[6].z, vertex.attrib[11], program.env[7];
DP3 result.texcoord[7].x, vertex.attrib[9], program.env[9];
DP3 result.texcoord[7].y, vertex.attrib[10], program.env[9];
DP3 result.texcoord[7].z, vertex.attrib[11], program.env[9];
# generate the vertex color, which can be 1.0, color, or 1.0 - color
# for 1.0 : env[16] = 0.0, env[17] = 1.0
# for color : env[16] = 1.0, env[17] = 0.0
# for 1.0 - color : env[16] = -1.0, env[17] = 1.0
MAD result.color.xyz, vertex.color, program.env[16], program.env[17];
END
#==================================================================================
!!ARBfp1.0
OPTION ARB_precision_hint_nicest;
# Instruction Count: ALU: 97 TEX: 6 Total: 103
OUTPUT oColor = result.color;
ATTRIB vColor = fragment.color;
ATTRIB lightVecTC = fragment.texcoord[0];
ATTRIB normalTC = fragment.texcoord[1];
ATTRIB diffspecTC = fragment.texcoord[2];
ATTRIB lightProjTC = fragment.texcoord[3];
ATTRIB viewVecTC = fragment.texcoord[4];
ATTRIB tangent = fragment.texcoord[5];
ATTRIB bitangent = fragment.texcoord[6];
ATTRIB normal = fragment.texcoord[7];
PARAM lightColor = program.env[0];
PARAM specColor = program.env[1];
PARAM const = { 1.0, 2.0, 4.0, 5.0 };
PARAM const2 = { 0.25, 0.5, 0.75, 0.75 };
PARAM skyColor = { 1.0, 1.0, 1.0 };
PARAM grndColor = { 0.1, 0.1, 0.1 };
PARAM lumVec = { 0.212671, 0.715160, 0.072169 };
PARAM specExp = 256.0;
PARAM M_PI = 3.1415926535897932384626433832795;
PARAM M_8PI = 25.132741228718345907701147066236;
PARAM M_inv2PI = 0.15915494309189533576888376337251;
PARAM e = 2.7182818284590452353602874713527;
PARAM gamma = { 2.4, 0.94786729857819905213270142180095, 0.41666666666666666666666666666667, 0.077399380804953560371517027863777 };
PARAM heightScale = { 0.06, -0.03 };
TEMP lightVec, viewVec, halfVec, normalVec, wNormalVec;
TEMP diffuse, specular, gloss, rough, fresnel, color, ambient;
TEMP light, hemi, atten, rim, lightFall, lightProj, lightCube, lightCol;
TEMP NdotL, NdotV, NdotH, VdotH, VdotL;
TEMP R1, R2;
# load falloff/projection maps
TEX lightFall, lightProjTC.zzzz, texture[2], 2D;
TXP lightProj, lightProjTC.xyzw, texture[3], 2D;
# calculate attenuation
MUL lightProj, lightProj, lightProj;
MUL atten, lightFall, lightProj;
# early out - attenuation
DP3 atten.w, atten, const.x;
SGE atten.w, 0.0, atten.w;
KIL -atten.w;
# normalize the vector to the viewer
DP3 viewVec.w, viewVecTC, viewVecTC;
RSQ viewVec.w, viewVec.w;
MUL viewVec.xyz, viewVecTC, viewVec.w;
# load height map then scale & bias
TEX R1, diffspecTC.zwzw, texture[5], 2D;
MAD R1.w, R1.w, heightScale.x, heightScale.y;
# calculate new texcoords
MAD R1.xy, R1.w, viewVec.xyxy, normalTC;
MAD R2, R1.w, viewVec.xyxy, diffspecTC;
# load texture maps
TEX ambient, lightVecTC, texture[0], CUBE;
TEX normalVec, R1, texture[1], 2D;
TEX diffuse, R2.xyxy, texture[4], 2D;
TEX gloss, R2.zwzw, texture[5], 2D;
DP3 rough, gloss, lumVec;
# normalize the vector to the light
DP3 lightVec.w, lightVecTC, lightVecTC;
RSQ lightVec.w, lightVec.w;
MUL lightVec.xyz, lightVecTC, lightVec.w;
# scale normal vector to -1.0<->1.0 range and normalize
MAD normalVec.xyz, normalVec.wyzx, const.y, -const.x;
DP3 normalVec.w, normalVec, normalVec;
RSQ normalVec.w, normalVec.w;
MUL normalVec.xyz, normalVec, normalVec.w;
# calculate diffuse cosine
DP3 NdotL.x, normalVec, lightVec;
# calculate light w/ self shadowing
ADD_SAT R1.x, lightVec.z, const2.y;
ADD_SAT R1.x, R1.x, R1.x;
MUL_SAT R1.x, R1.x, R1.x;
MOV_SAT R1.y, NdotL.x;
MUL R1.y, R1.y, R1.y;
LRP R1.y, rough.w, R1.y, NdotL.x;
MUL light, R1.x, R1.y;
# early out - NdotL
SLT ambient.w, ambient.w, const.x;
SGE R1.w, 0.0, light.x;
CMP R1.w, -ambient.w, 0.0, R1.w;
KIL -R1.w;
# calculate the half angle vector and normalize
ADD halfVec, lightVec, viewVec;
DP3 halfVec.w, halfVec, halfVec;
RSQ halfVec.w, halfVec.w;
MUL halfVec.xyz, halfVec, halfVec.w;
# transform normal to world space
DP3 wNormalVec.x, normalVec, tangent;
DP3 wNormalVec.y, normalVec, bitangent;
DP3 wNormalVec.z, normalVec, normal;
# normalize world space normal vector
DP3 wNormalVec.w, wNormalVec, wNormalVec;
RSQ wNormalVec.w, wNormalVec.w;
MUL wNormalVec.xyz, wNormalVec, wNormalVec.w;
# calculate vector dot products
DP3 NdotV.x, normalVec, viewVec;
DP3_SAT NdotH.x, normalVec, halfVec;
DP3_SAT VdotH.x, viewVec, halfVec;
DP3_SAT VdotL.x, viewVec, -lightVec;
# sRGB -> Linear
MUL R1, diffuse, gamma.w;
ADD R2, diffuse, 0.055;
MUL R2, R2, gamma.y;
POW R2.x, R2.x, gamma.x;
POW R2.y, R2.y, gamma.x;
POW R2.z, R2.z, gamma.x;
SGE diffuse, 0.04045, diffuse;
CMP diffuse.xyz, -diffuse, R1, R2;
# sikk - fix for materials with no diffuse map (e.g. Hellknight gob)
DP3 R1.x, lightColor, -const.x;
CMP lightCol, R1.x, lightColor, specColor;
# sRGB -> Linear
MUL lightCol, lightCol, 0.5;
MUL R1, lightCol, gamma.w;
ADD R2, lightCol, 0.055;
MUL R2, R2, gamma.y;
POW R2.x, R2.x, gamma.x;
POW R2.y, R2.y, gamma.x;
POW R2.z, R2.z, gamma.x;
SGE lightCol, 0.04045, lightCol;
CMP lightCol.xyz, -lightCol, R1, R2;
# multiply light by its scaled luminance
DP3_SAT lightCol.w, lightCol, lumVec;
MAD_SAT lightCol.w, lightCol.w, 0.25, 0.25;
MAD_SAT lightCol.w, lightCol.w, -lightCol.w, lightCol.w;
MUL lightCol, lightCol, lightCol.w;
# calculate specular term
MUL rough.x, rough.x, specExp.x;
MUL rough.y, VdotH.x, VdotH.x;
RCP rough.y, rough.y;
ADD R1.xy, rough.x, { 2.0, 4.0 };
MUL R1.x, R1.x, R1.y;
MUL R1.y, rough.x, 0.5;
EX2 R1.y, -R1.y;
ADD R1.y, R1.y, rough.x;
MUL R1.y, R1.y, M_8PI;
RCP R1.y, R1.y;
MUL rough.z, R1.x, R1.y;
ADD fresnel.x, const.x, -VdotH.x;
POW fresnel, fresnel.x, const.w;
LRP fresnel, gloss, const.x, fresnel;
CMP fresnel, -rough.x, fresnel, 0.0;
MAX NdotH.x, NdotH.x, 0.00001;
POW specular, NdotH.x, rough.x;
MUL specular, specular, rough.y;
MUL specular, specular, rough.z;
# modulate specular by fresnel and add diffuse color
MAD color, specular, fresnel, diffuse;
# calculate hemisphere lighting ambient term
MAD hemi.w, wNormalVec.z, const2.y, const2.y;
LRP hemi, hemi.w, skyColor, grndColor;
CMP light, -ambient.w, hemi, light;
# rim light
ABS R1.x, NdotV.x; # use abs since some translucent materials use light interaction
ADD R1.x, const.x, -R1.x;
POW R1.x, R1.x, const.w;
MUL_SAT R1.y, VdotL.x, VdotL.x;
MAD_SAT R1.z, rough.w, -2.0, const.x;
MUL_SAT R1, R1.xzzz, R1.yzzz;
MUL rim, R1.x, R1.y;
LRP rim, color, 1.0, rim;
CMP color, -ambient.w, color, rim; # cancel rim lighting for ambient lights
# final modulation
MUL color, color, light;
MUL color, color, lightCol;
MUL color, color, atten;
# Linear -> sRGB
MUL R1, color, 12.92;
POW R2.x, color.x, gamma.z;
POW R2.y, color.y, gamma.z;
POW R2.z, color.z, gamma.z;
MAD R2, R2, 1.055, -0.055;
SGE color, 0.0031308, color;
CMP color.xyz, -color, R1, R2;
# encode HDR ;)
ADD R1, color, -1.0;
POW R1.x, e.x, R1.x;
POW R1.y, e.x, R1.y;
POW R1.z, e.x, R1.z;
MOV_SAT R2, color;
RSQ R2.x, R2.x;
RSQ R2.y, R2.y;
RSQ R2.z, R2.z;
RCP R2.x, R2.x;
RCP R2.y, R2.y;
RCP R2.z, R2.z;
LRP_SAT color, color, R1, R2;
# modify by the vertex color
MUL oColor.xyz, color, vColor;
END
Warning its very very slow even on modern cards hehe.
Productivity is a state of mind.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
Re: Doom 3 engine release and game code
Post some screenshots please 
- motorsep
- Posts: 231
- Joined: Wed Aug 02, 2006 11:46 pm
- Location: Texas, USA
Re: Doom 3 engine release and game code
Productivity is a state of mind.
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
Re: Doom 3 engine release and game code
So, red is the new brown, huh ? j/k, looks great. I miss fantasy FPS games like Hexen and Heretic.
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC
(LordHavoc)
-

frag.machine - Posts: 2090
- Joined: Sat Nov 25, 2006 1:49 pm
Who is online
Users browsing this forum: No registered users and 1 guest