Doom 3 engine release and game code
Moderator: InsideQC Admins
Re: Doom 3 engine release and game code
Ok got it running
just need to get this converted now.
thats a parralax bumpmapping shader it works quite nicely with ARB2 and is actually the only one of them out there that doesnt seem to bug out with some materials (uses offset limiting) the downside is that it doesnt raise textures as much as a parralax occlusion mapping one. this one uses the materia edit(interaction)l shader so should be possible but im starting to wonder if one could do a material based version so that the parralax occluded version could be used on materials that dont bug out and the offset limited one on materials that do ?.
- 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 };
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, program.env[5], 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
thats a parralax bumpmapping shader it works quite nicely with ARB2 and is actually the only one of them out there that doesnt seem to bug out with some materials (uses offset limiting) the downside is that it doesnt raise textures as much as a parralax occlusion mapping one. this one uses the materia edit(interaction)l shader so should be possible but im starting to wonder if one could do a material based version so that the parralax occluded version could be used on materials that dont bug out and the offset limited one on materials that do ?.
Last edited by revelator on Fri Jul 13, 2012 2:10 am, edited 1 time in total.
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
Remove the KIL instructions and you'll probably run faster. Early outs make sense on a CPU, but they're not going to play nice with a GPU. It's likely that the entire shader will always execute anyway, and they'll fuck with any early-Z optimizations that the hardware might be doing (worst case is that they'll disable early-Z altogether as the hardware can no longer predict what Z will be before the fragment shader runs).
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
We knew the words, we knew the score, we knew what we were fighting for
-

mh - Posts: 2292
- Joined: Sat Jan 12, 2008 1:38 am
- motorsep
- Posts: 231
- Joined: Wed Aug 02, 2006 11:46 pm
- Location: Texas, USA
Re: Doom 3 engine release and game code
Works with ARB but not with GLSL yet as i dont have any shaders for them
though the POM shader can be a bit buggy at times with some materials (they get a weird mirror effect if the texture source is not completely flat).
The offset limiting version works fine though.
Mh gonna try that thanks.
though the POM shader can be a bit buggy at times with some materials (they get a weird mirror effect if the texture source is not completely flat).
The offset limiting version works fine though.
Mh gonna try that thanks.
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
Heh ok it made it look a bit less weird when getting close to buggy materials but my framerate got killed somewhat.
heres a few shots to show the problem with POM.
at distance it looks ok

when you get closer you get this though.

heres a few shots to show the problem with POM.
at distance it looks ok
when you get closer you get this though.
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
hmm removing early out fixed some of it but not all unfortunatly its unplayable as you can see here

The frames pr sec here are with 2 560gtx ti overclocked in sli so say goodbye to any normal gfx card xD

The frames pr sec here are with 2 560gtx ti overclocked in sli so say goodbye to any normal gfx card xD
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
Heres the engine and shaders if someone wants to try it out.
http://code.google.com/p/realm/downloads/detail?name=Doom3-MH.zip&can=2&q=
All backends besides the Arb fallback and ARB2/GLSL backends have been removed.
Not included the parralax shader you can get that with sikkmod 1.2 but be warned im not liable if it kills your gfx from enabling a bit to much eyecandy
http://code.google.com/p/realm/downloads/detail?name=Doom3-MH.zip&can=2&q=
All backends besides the Arb fallback and ARB2/GLSL backends have been removed.
Not included the parralax shader you can get that with sikkmod 1.2 but be warned im not liable if it kills your gfx from enabling a bit to much eyecandy
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
// one-time only
glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
// each frame
glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, x, y, width, height);
if i where to access those from shaders how would i go about that ? can i specify GL_DEPTH_COMPONENT in a shader.
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
an amazing work you're making, guys. An amazing work.
Meadow Fun!! - my first commercial game, made with FTEQW game engine
- toneddu2000
- Posts: 1352
- Joined: Tue Feb 24, 2009 4:39 pm
- Location: Italy
Re: Doom 3 engine release and game code
reckless wrote:// one-time only
glTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
// each frame
glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, x, y, width, height);
if i where to access those from shaders how would i go about that ? can i specify GL_DEPTH_COMPONENT in a shader.
Call these from engine-side and then just sample the texture as normal after that. Let's see...
- Code: Select all
texture->Bind ();
glCopyTexSubImage2D (GL_TEXTURE_2D, 0, 0, 0, x, y, width, height);
DrawAmazingBrainMeltingStuff ();
And:
- Code: Select all
uniform sampler2D depthTexture;
float depthvalue = texture2D (depthTexture, coords);
Or:
- Code: Select all
TEX depthvalue, fragment.texcoord[0], texture[0], 2D;
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
We knew the words, we knew the score, we knew what we were fighting for
-

mh - Posts: 2292
- Joined: Sat Jan 12, 2008 1:38 am
Re: Doom 3 engine release and game code
Got the answer from Sikk
doom3 actually has a function for accessing depthbuffer related stuff the downside is that the infinite far z volume calculations need some modifying else it would cause some disatorous things but real SSAO is possible allthough it will take some hacking about.
From his post.
There's already a function to capture the depth buffer to a texture, "CopyDepthbuffer(...)". You just need to add an idImage to call it. See "RB_STD_DrawView()" in my source. After the depth buffer is filled (with RB_STD_FillDepthBuffer( drawSurfs, numDrawSurfs );), I capture it. Right now, I only use it for things like soft water/particles and some other basic depth effects. Doing ssao or dof with it will be tricky because you'll have to linearize it which, because of the infinite far z that this engine uses, is not so simple.
I repacked my mod with a few additional tweaks (microstutter fix by jkriege) and added the ROE hd mod. Theres now also wrapper executables which will start them with the HD mod enabled.
I also added higher resolutions.
http://code.google.com/p/realm/downloads/detail?name=HD-Doom3.7z.torrent&can=2&q=
Lost a bit of weight in the process
From his post.
There's already a function to capture the depth buffer to a texture, "CopyDepthbuffer(...)". You just need to add an idImage to call it. See "RB_STD_DrawView()" in my source. After the depth buffer is filled (with RB_STD_FillDepthBuffer( drawSurfs, numDrawSurfs );), I capture it. Right now, I only use it for things like soft water/particles and some other basic depth effects. Doing ssao or dof with it will be tricky because you'll have to linearize it which, because of the infinite far z that this engine uses, is not so simple.
I repacked my mod with a few additional tweaks (microstutter fix by jkriege) and added the ROE hd mod. Theres now also wrapper executables which will start them with the HD mod enabled.
I also added higher resolutions.
http://code.google.com/p/realm/downloads/detail?name=HD-Doom3.7z.torrent&can=2&q=
Lost a bit of weight in the process
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
Oh you posted just as i did xD Thanks for the info though
going to try and see what happens if i replace the crytek ssao shader in sikks with a pointer to that.
Forgot to mention Sikk has been trying to get hold on Error for registering here but had no luck so far, i gave him the names of the other admins to contact and just wanted to let you know.
Forgot to mention Sikk has been trying to get hold on Error for registering here but had no luck so far, i gave him the names of the other admins to contact and just wanted to let you know.
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
You could consider using a different parallax mapping algorithm, POM is terribly slow.
Relaxed Cone Step Mapping, Anisotropic Cone Mapping and Quadtree Displacement Mapping converge much faster and don't suffer from the stairstepping effect.
Relaxed Cone Step Mapping, Anisotropic Cone Mapping and Quadtree Displacement Mapping converge much faster and don't suffer from the stairstepping effect.
- Spiney
- Posts: 63
- Joined: Mon Feb 13, 2012 1:35 pm
Who is online
Users browsing this forum: No registered users and 1 guest