Skip to content

Commit

Permalink
Because I can :)
Browse files Browse the repository at this point in the history
- Implemented soft shadows using PCF hardware shadow mapping

  The implementation uses sampler2DArrayShadow and PCF which usually
  requires Direct3D 10.1 however it is in the OpenGL 3.2 core so it should
  be widely supported.
  All 3 light types are supported which means parallel lights (sun) use
  scene independent cascaded shadow mapping.
  The implementation is very fast with single taps (400 fps average per
  scene on a GTX 660 ti OC) however I defaulted it to 16 taps so the shadows look
  really good which should you give stable 100 fps on todays hardware.

  The shadow filtering algorithm is based on Carmack's research which was
  released in the original Doom 3 GPL release draw_exp.cpp.

- Changed interaction shaders to use Half-Lambert lighting like in HL2 to
  make the game less dark

- Fixed some of the renderer debugging/development tools like r_showTris
  • Loading branch information
RobertBeckebans committed May 10, 2014
1 parent b983156 commit 277964f
Show file tree
Hide file tree
Showing 47 changed files with 4,144 additions and 1,010 deletions.
8 changes: 6 additions & 2 deletions base/renderprogs/_manifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ return
"color.vertex",
"colorProcess.pixel",
"colorProcess.vertex",
"debug_shadowmap.pixel",
"debug_shadowmap.vertex",
"depth.pixel",
"depth.vertex",
"depth_skinned.pixel",
Expand Down Expand Up @@ -54,12 +56,12 @@ return
"heatHazeWithMaskAndVertex.vertex",
"interaction.pixel",
"interaction.vertex",
"interactionSM.pixel",
"interactionSM.vertex",
"interactionAmbient.pixel",
"interactionAmbient.vertex",
"interactionAmbient_skinned.pixel",
"interactionAmbient_skinned.vertex",
"interaction_skinned.pixel",
"interaction_skinned.vertex",
"motionBlur.pixel",
"motionBlur.vertex",
"postprocess.pixel",
Expand Down Expand Up @@ -91,6 +93,8 @@ return
"texture_color_skinned.vertex",
"texture_color_texgen.pixel",
"texture_color_texgen.vertex",
"vertex_color.pixel",
"vertex_color.vertex",
"wobblesky.pixel",
"wobblesky.vertex",
"zcullReconstruct.pixel",
Expand Down
53 changes: 52 additions & 1 deletion base/renderprogs/color.vertex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2013-2014 Robert Beckebans

This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").

Expand All @@ -28,21 +29,71 @@ If you have questions concerning this license or the applicable additional terms

#include "global.inc"

#if defined(USE_GPU_SKINNING)
uniform matrices_ubo { float4 matrices[408]; };
#endif

struct VS_IN {
float4 position : POSITION;
float2 texcoord : TEXCOORD0;
float4 normal : NORMAL;
float4 tangent : TANGENT;
float4 color : COLOR0;
float4 color2 : COLOR1;
};

struct VS_OUT {
float4 position : POSITION;
};

void main( VS_IN vertex, out VS_OUT result ) {
void main( VS_IN vertex, out VS_OUT result )
{
#if defined(USE_GPU_SKINNING)
//--------------------------------------------------------------
// GPU transformation of the position
//
// multiplying with 255.1 give us the same result and is faster than floor( w * 255 + 0.5 )
//--------------------------------------------------------------
const float w0 = vertex.color2.x;
const float w1 = vertex.color2.y;
const float w2 = vertex.color2.z;
const float w3 = vertex.color2.w;

float4 matX, matY, matZ; // must be float4 for vec4
float joint = vertex.color.x * 255.1 * 3;
matX = matrices[int(joint+0)] * w0;
matY = matrices[int(joint+1)] * w0;
matZ = matrices[int(joint+2)] * w0;

joint = vertex.color.y * 255.1 * 3;
matX += matrices[int(joint+0)] * w1;
matY += matrices[int(joint+1)] * w1;
matZ += matrices[int(joint+2)] * w1;

joint = vertex.color.z * 255.1 * 3;
matX += matrices[int(joint+0)] * w2;
matY += matrices[int(joint+1)] * w2;
matZ += matrices[int(joint+2)] * w2;

joint = vertex.color.w * 255.1 * 3;
matX += matrices[int(joint+0)] * w3;
matY += matrices[int(joint+1)] * w3;
matZ += matrices[int(joint+2)] * w3;

float4 modelPosition;
modelPosition.x = dot4( matX, vertex.position );
modelPosition.y = dot4( matY, vertex.position );
modelPosition.z = dot4( matZ, vertex.position );
modelPosition.w = 1.0;

result.position.x = dot4( modelPosition, rpMVPmatrixX );
result.position.y = dot4( modelPosition, rpMVPmatrixY );
result.position.z = dot4( modelPosition, rpMVPmatrixZ );
result.position.w = dot4( modelPosition, rpMVPmatrixW );
#else
result.position.x = dot4( vertex.position, rpMVPmatrixX );
result.position.y = dot4( vertex.position, rpMVPmatrixY );
result.position.z = dot4( vertex.position, rpMVPmatrixZ );
result.position.w = dot4( vertex.position, rpMVPmatrixW );
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
===========================================================================

Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2014 Robert Beckebans

This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").

Doom 3 BFG Edition 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
Expand All @@ -25,8 +26,27 @@ If you have questions concerning this license or the applicable additional terms

===========================================================================
*/
#pragma hdrstop
#include "precompiled.h"
#include "tr_local.h"
#include "../sound/snd_local.h"

#include "renderprogs/global.inc"

uniform sampler2DArray samp0 : register(s0);

struct PS_IN
{
float4 position : VPOS;
float2 texcoord0 : TEXCOORD0_centroid;
};

struct PS_OUT
{
float4 color : COLOR;
};

void main( PS_IN fragment, out PS_OUT result )
{
float3 tc;
tc.xy = fragment.texcoord0.xy;
tc.z = rpScreenCorrectionFactor.x; // layer

result.color = texture( samp0, tc );// * rpColor;
}
58 changes: 58 additions & 0 deletions base/renderprogs/debug_shadowmap.vertex
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
===========================================================================

Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.

This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").

Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.

In addition, the Doom 3 BFG Edition 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 BFG Edition 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 "renderprogs/global.inc"

struct VS_IN {
float4 position : POSITION;
float2 texcoord : TEXCOORD0;
float4 normal : NORMAL;
float4 tangent : TANGENT;
float4 color : COLOR0;
};

struct VS_OUT {
float4 position : POSITION;
float2 texcoord0 : TEXCOORD0;
};

void main( VS_IN vertex, out VS_OUT result ) {
result.position.x = dot4( vertex.position, rpMVPmatrixX );
result.position.y = dot4( vertex.position, rpMVPmatrixY );
result.position.z = dot4( vertex.position, rpMVPmatrixZ );
result.position.w = dot4( vertex.position, rpMVPmatrixW );

// compute oldschool texgen or multiply by texture matrix
BRANCH if ( rpTexGen0Enabled.x > 0.0 ) {
result.texcoord0.x = dot4( vertex.position, rpTexGen0S );
result.texcoord0.y = dot4( vertex.position, rpTexGen0T );
} else {
result.texcoord0.x = dot4( vertex.texcoord.xy, rpTextureMatrixS );
result.texcoord0.y = dot4( vertex.texcoord.xy, rpTextureMatrixT );
}
}
17 changes: 15 additions & 2 deletions base/renderprogs/global.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2013 Robert Beckebans
Copyright (C) 2013-2014 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
Expand Down Expand Up @@ -97,6 +97,20 @@ uniform float4 rpOverbright : register(c50);
uniform float4 rpEnableSkinning : register(c51);
uniform float4 rpAlphaTest : register(c52);

// RB begin
uniform float4 rpAmbientColor : register(c53);
uniform float4 rpGlobalLightOrigin : register(c54);
uniform float4 rpJitterTexScale : register(c55);
uniform float4 rpJitterTexOffset : register(c56);
uniform float4 rpCascadeDistances : register(c57);

#if defined( USE_UNIFORM_ARRAYS )
uniform float4 rpShadowMatrices : register(c58);
#else
uniform float4 rpShadowMatrices[6*4] : register(c59);
#endif
// RB end

static float dot2( float2 a, float2 b ) { return dot( a, b ); }
static float dot3( float3 a, float3 b ) { return dot( a, b ); }
static float dot3( float3 a, float4 b ) { return dot( a, b.xyz ); }
Expand Down Expand Up @@ -180,6 +194,5 @@ static float4 idtex2Dproj( sampler2D samp, float4 texCoords ) { return tex2Dproj
static float4 swizzleColor( float4 c ) { return c; }
static float2 vposToScreenPosTexCoord( float2 vpos ) { return vpos.xy * rpWindowCoord.xy; }


#define BRANCH
#define IFANY
22 changes: 18 additions & 4 deletions base/renderprogs/interaction.pixel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2013-2014 Robert Beckebans

This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").

Expand All @@ -26,7 +27,7 @@ If you have questions concerning this license or the applicable additional terms
===========================================================================
*/

#include "global.inc"
#include "renderprogs/global.inc"

uniform sampler2D samp0 : register(s0); // texture 1 is the per-surface bump map
uniform sampler2D samp1 : register(s1); // texture 2 is the light falloff texture
Expand Down Expand Up @@ -64,15 +65,28 @@ void main( PS_IN fragment, out PS_OUT result ) {
localNormal.xy = bumpMap.wy - 0.5;
localNormal.z = sqrt( abs( dot( localNormal.xy, localNormal.xy ) - 0.25 ) );
localNormal = normalize( localNormal );

// RB: http://developer.valvesoftware.com/wiki/Half_Lambert
float halfLdotN = dot3( localNormal, lightVector ) * 0.5 + 0.5;
halfLdotN *= halfLdotN;

// traditional very dark Lambert light model used in Doom 3
//float ldotN = clamp( dot3( localNormal, lightVector ), 0.0, 1.0 );
float ldotN = dot3( localNormal, lightVector );

const half specularPower = 10.0f;
half hDotN = dot3( normalize( fragment.texcoord6.xyz ), localNormal );
half3 specularContribution = _half3( pow( hDotN, specularPower ) );
// RB: added abs
half3 specularContribution = _half3( pow( abs( hDotN ), specularPower ) );

half3 diffuseColor = diffuseMap * rpDiffuseModifier.xyz;
half3 specularColor = specMap.xyz * specularContribution * rpSpecularModifier.xyz;
half3 lightColor = dot3( lightVector, localNormal ) * lightProj.xyz * lightFalloff.xyz;
half3 lightColor = lightProj.xyz * lightFalloff.xyz;

half rim = 1.0f - saturate( hDotN );
half rimPower = 16.0f;
half3 rimColor = diffuseColor * lightProj.xyz * lightFalloff.xyz * 1.0f * pow( rim, rimPower ) * fragment.color.rgb;// * halfLdotN;

result.color.xyz = ( diffuseColor + specularColor ) * lightColor * fragment.color.xyz;
result.color.xyz = ( diffuseColor + specularColor ) * halfLdotN * lightColor * fragment.color.rgb;// + rimColor;
result.color.w = 1.0;
}

0 comments on commit 277964f

Please sign in to comment.