mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 00:54:54 +00:00
Empty Template for ticket #1
This commit is contained in:
parent
8337cad7ee
commit
40220512d3
1573 changed files with 141028 additions and 0 deletions
37
Templates/Empty/game/shaders/common/basicCloudsP.hlsl
Normal file
37
Templates/Empty/game/shaders/common/basicCloudsP.hlsl
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "torque.hlsl"
|
||||
|
||||
struct ConnectData
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
uniform sampler2D diffuseMap : register(S0);
|
||||
|
||||
float4 main( ConnectData IN ) : COLOR
|
||||
{
|
||||
float4 col = tex2D( diffuseMap, IN.texCoord );
|
||||
return hdrEncode( col );
|
||||
}
|
||||
58
Templates/Empty/game/shaders/common/basicCloudsV.hlsl
Normal file
58
Templates/Empty/game/shaders/common/basicCloudsV.hlsl
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct CloudVert
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float3 binormal : BINORMAL;
|
||||
float3 tangent : TANGENT;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct ConnectData
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
uniform float4x4 modelview;
|
||||
uniform float accumTime;
|
||||
uniform float texScale;
|
||||
uniform float2 texDirection;
|
||||
uniform float2 texOffset;
|
||||
|
||||
ConnectData main( CloudVert IN )
|
||||
{
|
||||
ConnectData OUT;
|
||||
|
||||
OUT.hpos = mul(modelview, IN.pos);
|
||||
|
||||
float2 uv = IN.uv0;
|
||||
uv += texOffset;
|
||||
uv *= texScale;
|
||||
uv += accumTime * texDirection;
|
||||
|
||||
OUT.texCoord = uv;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
145
Templates/Empty/game/shaders/common/cloudLayerP.hlsl
Normal file
145
Templates/Empty/game/shaders/common/cloudLayerP.hlsl
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "torque.hlsl"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ConnectData
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float4 texCoord12 : TEXCOORD0;
|
||||
float4 texCoord34 : TEXCOORD1;
|
||||
float3 vLightTS : TEXCOORD2; // light vector in tangent space, denormalized
|
||||
float3 vViewTS : TEXCOORD3; // view vector in tangent space, denormalized
|
||||
float worldDist : TEXCOORD4;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uniforms
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform sampler2D normalHeightMap : register(S0);
|
||||
uniform float3 ambientColor;
|
||||
uniform float3 sunColor;
|
||||
uniform float cloudCoverage;
|
||||
uniform float3 cloudBaseColor;
|
||||
uniform float cloudExposure;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Globals
|
||||
//-----------------------------------------------------------------------------
|
||||
// The per-color weighting to be used for luminance calculations in RGB order.
|
||||
static const float3 LUMINANCE_VECTOR = float3(0.2125f, 0.7154f, 0.0721f);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Calculates the Rayleigh phase function
|
||||
float getRayleighPhase( float angle )
|
||||
{
|
||||
return 0.75 * ( 1.0 + pow( angle, 2 ) );
|
||||
}
|
||||
|
||||
// Returns the output rgb color given a texCoord and parameters it uses
|
||||
// for lighting calculation.
|
||||
float3 ComputeIllumination( float2 texCoord,
|
||||
float3 vLightTS,
|
||||
float3 vViewTS,
|
||||
float3 vNormalTS )
|
||||
{
|
||||
//return noiseNormal;
|
||||
//return vNormalTS;
|
||||
|
||||
float3 vLightTSAdj = float3( -vLightTS.x, -vLightTS.y, vLightTS.z );
|
||||
|
||||
float dp = dot( vNormalTS, vLightTSAdj );
|
||||
|
||||
// Calculate the amount of illumination (lightTerm)...
|
||||
|
||||
// We do both a rim lighting effect and a halfLambertian lighting effect
|
||||
// and combine the result.
|
||||
float halfLambertTerm = saturate( pow( dp * 0.5 + 0.5, 1 ) );
|
||||
float rimLightTerm = pow( ( 1.0 - dp ), 1.0 );
|
||||
float lightTerm = saturate( halfLambertTerm * 1.0 + rimLightTerm * dp );
|
||||
lightTerm *= 0.5;
|
||||
|
||||
// Use a simple RayleighPhase function to simulate single scattering towards
|
||||
// the camera.
|
||||
float angle = dot( vLightTS, vViewTS );
|
||||
lightTerm *= getRayleighPhase( angle );
|
||||
|
||||
// Combine terms and colors into the output color.
|
||||
//float3 lightColor = ( lightTerm * sunColor * fOcclusionShadow ) + ambientColor;
|
||||
float3 lightColor = lerp( ambientColor, sunColor, lightTerm );
|
||||
//lightColor = lerp( lightColor, ambientColor, cloudCoverage );
|
||||
float3 finalColor = cloudBaseColor * lightColor;
|
||||
|
||||
return finalColor;
|
||||
}
|
||||
|
||||
float4 main( ConnectData IN ) : COLOR
|
||||
{
|
||||
// Normalize the interpolated vectors:
|
||||
float3 vViewTS = normalize( IN.vViewTS );
|
||||
float3 vLightTS = normalize( IN.vLightTS );
|
||||
|
||||
float4 cResultColor = float4( 0, 0, 0, 1 );
|
||||
|
||||
float2 texSample = IN.texCoord12.xy;
|
||||
|
||||
float4 noise1 = tex2D( normalHeightMap, IN.texCoord12.zw );
|
||||
noise1 = normalize( ( noise1 - 0.5 ) * 2.0 );
|
||||
//return noise1;
|
||||
|
||||
float4 noise2 = tex2D( normalHeightMap, IN.texCoord34.xy );
|
||||
noise2 = normalize( ( noise2 - 0.5 ) * 2.0 );
|
||||
//return noise2;
|
||||
|
||||
float3 noiseNormal = normalize( noise1 + noise2 ).xyz;
|
||||
//return float4( noiseNormal, 1.0 );
|
||||
|
||||
float noiseHeight = noise1.a * noise2.a * ( cloudCoverage / 2.0 + 0.5 );
|
||||
|
||||
float3 vNormalTS = normalize( tex2D( normalHeightMap, texSample ).xyz * 2.0 - 1.0 );
|
||||
vNormalTS += noiseNormal;
|
||||
vNormalTS = normalize( vNormalTS );
|
||||
|
||||
// Compute resulting color for the pixel:
|
||||
cResultColor.rgb = ComputeIllumination( texSample, vLightTS, vViewTS, vNormalTS );
|
||||
|
||||
float coverage = ( cloudCoverage - 0.5 ) * 2.0;
|
||||
cResultColor.a = tex2D( normalHeightMap, texSample ).a + coverage + noiseHeight;
|
||||
|
||||
if ( cloudCoverage > -1.0 )
|
||||
cResultColor.a /= 1.0 + coverage;
|
||||
|
||||
cResultColor.a = saturate( cResultColor.a * pow( saturate(cloudCoverage), 0.25 ) );
|
||||
|
||||
cResultColor.a = lerp( cResultColor.a, 0.0, 1.0 - pow(IN.worldDist,2.0) );
|
||||
|
||||
cResultColor.rgb *= cloudExposure;
|
||||
|
||||
return hdrEncode( cResultColor );
|
||||
}
|
||||
106
Templates/Empty/game/shaders/common/cloudLayerV.hlsl
Normal file
106
Templates/Empty/game/shaders/common/cloudLayerV.hlsl
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct CloudVert
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float3 binormal : BINORMAL;
|
||||
float3 tangent : TANGENT;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct ConnectData
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float4 texCoord12 : TEXCOORD0;
|
||||
float4 texCoord34 : TEXCOORD1;
|
||||
float3 vLightTS : TEXCOORD2; // light vector in tangent space, denormalized
|
||||
float3 vViewTS : TEXCOORD3; // view vector in tangent space, denormalized
|
||||
float worldDist : TEXCOORD4;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uniforms
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform float4x4 modelview;
|
||||
uniform float3 eyePosWorld;
|
||||
uniform float3 sunVec;
|
||||
uniform float2 texOffset0;
|
||||
uniform float2 texOffset1;
|
||||
uniform float2 texOffset2;
|
||||
uniform float3 texScale;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
ConnectData main( CloudVert IN )
|
||||
{
|
||||
ConnectData OUT;
|
||||
|
||||
OUT.hpos = mul(modelview, IN.pos);
|
||||
|
||||
// Offset the uv so we don't have a seam directly over our head.
|
||||
float2 uv = IN.uv0 + float2( 0.5, 0.5 );
|
||||
|
||||
OUT.texCoord12.xy = uv * texScale.x;
|
||||
OUT.texCoord12.xy += texOffset0;
|
||||
|
||||
OUT.texCoord12.zw = uv * texScale.y;
|
||||
OUT.texCoord12.zw += texOffset1;
|
||||
|
||||
OUT.texCoord34.xy = uv * texScale.z;
|
||||
OUT.texCoord34.xy += texOffset2;
|
||||
|
||||
OUT.texCoord34.z = IN.pos.z;
|
||||
OUT.texCoord34.w = 0.0;
|
||||
|
||||
// Transform the normal, tangent and binormal vectors from object space to
|
||||
// homogeneous projection space:
|
||||
float3 vNormalWS = -IN.normal;
|
||||
float3 vTangentWS = -IN.tangent;
|
||||
float3 vBinormalWS = -IN.binormal;
|
||||
|
||||
// Compute position in world space:
|
||||
float4 vPositionWS = IN.pos + float4( eyePosWorld, 1 ); //mul( IN.pos, objTrans );
|
||||
|
||||
// Compute and output the world view vector (unnormalized):
|
||||
float3 vViewWS = eyePosWorld - vPositionWS.xyz;
|
||||
|
||||
// Compute denormalized light vector in world space:
|
||||
float3 vLightWS = -sunVec;
|
||||
|
||||
// Normalize the light and view vectors and transform it to the tangent space:
|
||||
float3x3 mWorldToTangent = float3x3( vTangentWS, vBinormalWS, vNormalWS );
|
||||
|
||||
// Propagate the view and the light vectors (in tangent space):
|
||||
OUT.vLightTS = mul( vLightWS, mWorldToTangent );
|
||||
OUT.vViewTS = mul( mWorldToTangent, vViewWS );
|
||||
|
||||
OUT.worldDist = saturate( pow( max( IN.pos.z, 0 ), 2 ) );
|
||||
|
||||
return OUT;
|
||||
}
|
||||
53
Templates/Empty/game/shaders/common/debugInteriorsP.hlsl
Normal file
53
Templates/Empty/game/shaders/common/debugInteriorsP.hlsl
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ConnectData
|
||||
{
|
||||
float2 texCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
|
||||
struct Fragout
|
||||
{
|
||||
float4 col : COLOR0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
Fragout main( ConnectData IN,
|
||||
uniform sampler2D diffuseMap : register(S0),
|
||||
uniform float4 shadeColor : register(C0)
|
||||
|
||||
)
|
||||
{
|
||||
Fragout OUT;
|
||||
|
||||
OUT.col = shadeColor;
|
||||
OUT.col *= tex2D(diffuseMap, IN.texCoord);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
49
Templates/Empty/game/shaders/common/debugInteriorsV.hlsl
Normal file
49
Templates/Empty/game/shaders/common/debugInteriorsV.hlsl
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hlslStructs.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct ConnectData
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float2 outTexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
ConnectData main( VertexIn_PNTTTB IN,
|
||||
uniform float4x4 modelview : register(C0)
|
||||
)
|
||||
{
|
||||
ConnectData OUT;
|
||||
|
||||
OUT.hpos = mul(modelview, IN.pos);
|
||||
OUT.outTexCoord = IN.uv0;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
float4 main( float4 color_in : COLOR0,
|
||||
float2 texCoord_in : TEXCOORD0,
|
||||
uniform sampler2D diffuseMap : register(S0) ) : COLOR0
|
||||
{
|
||||
return float4(color_in.rgb, color_in.a * tex2D(diffuseMap, texCoord_in).a);
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
float4 position : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
};
|
||||
struct Conn
|
||||
{
|
||||
float4 HPOS : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
};
|
||||
Conn main( Appdata In, uniform float4x4 modelview : register(C0) )
|
||||
{
|
||||
Conn Out;
|
||||
Out.HPOS = mul(modelview, In.position);
|
||||
Out.color = In.color;
|
||||
Out.texCoord = In.texCoord;
|
||||
return Out;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
float4 main( float4 color_in : COLOR0, uniform sampler2D diffuseMap : register(S0) ) : COLOR0
|
||||
{
|
||||
return color_in;
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
float4 position : POSITION;
|
||||
float4 color : COLOR;
|
||||
};
|
||||
struct Conn
|
||||
{
|
||||
float4 HPOS : POSITION;
|
||||
float4 color : COLOR;
|
||||
};
|
||||
Conn main( Appdata In, uniform float4x4 modelview : register(C0) )
|
||||
{
|
||||
Conn Out;
|
||||
Out.HPOS = mul(modelview, In.position);
|
||||
Out.color = In.color;
|
||||
return Out;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
float4 main( float4 color_in : COLOR0,
|
||||
float2 texCoord_in : TEXCOORD0,
|
||||
uniform sampler2D diffuseMap : register(S0) ) : COLOR0
|
||||
{
|
||||
return tex2D(diffuseMap, texCoord_in) * color_in;
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct Appdata
|
||||
{
|
||||
float4 position : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
};
|
||||
struct Conn
|
||||
{
|
||||
float4 HPOS : POSITION;
|
||||
float4 color : COLOR;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
};
|
||||
Conn main( Appdata In, uniform float4x4 modelview : register(C0) )
|
||||
{
|
||||
Conn Out;
|
||||
Out.HPOS = mul(modelview, In.position);
|
||||
Out.color = In.color;
|
||||
Out.texCoord = In.texCoord;
|
||||
return Out;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform sampler2D colorTarget0Texture : register(s0);
|
||||
|
||||
float4 main( float2 ScreenPos : VPOS ) : COLOR0
|
||||
{
|
||||
float2 TexCoord = ScreenPos;
|
||||
float4 diffuse;
|
||||
asm { tfetch2D diffuse, TexCoord, colorTarget0Texture, UnnormalizedTextureCoords = true };
|
||||
return diffuse;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
float4 main( const float2 inPosition : POSITION ) : POSITION
|
||||
{
|
||||
return float4( inPosition, 0, 1 );
|
||||
}
|
||||
186
Templates/Empty/game/shaders/common/foliage.hlsl
Normal file
186
Templates/Empty/game/shaders/common/foliage.hlsl
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// CornerId corresponds to this arrangement
|
||||
// from the perspective of the camera.
|
||||
//
|
||||
// 3 ---- 2
|
||||
// | |
|
||||
// 0 ---- 1
|
||||
//
|
||||
|
||||
#define MAX_COVERTYPES 8
|
||||
|
||||
uniform float3 gc_camRight;
|
||||
uniform float3 gc_camUp;
|
||||
uniform float4 gc_typeRects[MAX_COVERTYPES];
|
||||
uniform float2 gc_fadeParams;
|
||||
uniform float2 gc_windDir;
|
||||
|
||||
// .x = gust length
|
||||
// .y = premultiplied simulation time and gust frequency
|
||||
// .z = gust strength
|
||||
uniform float3 gc_gustInfo;
|
||||
|
||||
// .x = premultiplied simulation time and turbulance frequency
|
||||
// .y = turbulance strength
|
||||
uniform float2 gc_turbInfo;
|
||||
|
||||
|
||||
static float sCornerRight[4] = { -0.5, 0.5, 0.5, -0.5 };
|
||||
|
||||
static float sCornerUp[4] = { 0, 0, 1, 1 };
|
||||
|
||||
static float sMovableCorner[4] = { 0, 0, 1, 1 };
|
||||
|
||||
static float2 sUVCornerExtent[4] =
|
||||
{
|
||||
float2( 0, 1 ),
|
||||
float2( 1, 1 ),
|
||||
float2( 1, 0 ),
|
||||
float2( 0, 0 )
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// The following wind effect was derived from the GPU Gems 3 chapter...
|
||||
//
|
||||
// "Vegetation Procedural Animation and Shading in Crysis"
|
||||
// by Tiago Sousa, Crytek
|
||||
//
|
||||
|
||||
float2 smoothCurve( float2 x )
|
||||
{
|
||||
return x * x * ( 3.0 - 2.0 * x );
|
||||
}
|
||||
|
||||
float2 triangleWave( float2 x )
|
||||
{
|
||||
return abs( frac( x + 0.5 ) * 2.0 - 1.0 );
|
||||
}
|
||||
|
||||
float2 smoothTriangleWave( float2 x )
|
||||
{
|
||||
return smoothCurve( triangleWave( x ) );
|
||||
}
|
||||
|
||||
float windTurbulence( float bbPhase, float frequency, float strength )
|
||||
{
|
||||
// We create the input value for wave generation from the frequency and phase.
|
||||
float2 waveIn = bbPhase.xx + frequency.xx;
|
||||
|
||||
// We use two square waves to generate the effect which
|
||||
// is then scaled by the overall strength.
|
||||
float2 waves = ( frac( waveIn.xy * float2( 1.975, 0.793 ) ) * 2.0 - 1.0 );
|
||||
waves = smoothTriangleWave( waves );
|
||||
|
||||
// Sum up the two waves into a single wave.
|
||||
return ( waves.x + waves.y ) * strength;
|
||||
}
|
||||
|
||||
float2 windEffect( float bbPhase,
|
||||
float2 windDirection,
|
||||
float gustLength,
|
||||
float gustFrequency,
|
||||
float gustStrength,
|
||||
float turbFrequency,
|
||||
float turbStrength )
|
||||
{
|
||||
// Calculate the ambient wind turbulence.
|
||||
float turbulence = windTurbulence( bbPhase, turbFrequency, turbStrength );
|
||||
|
||||
// We simulate the overall gust via a sine wave.
|
||||
float gustPhase = clamp( sin( ( bbPhase - gustFrequency ) / gustLength ) , 0, 1 );
|
||||
float gustOffset = ( gustPhase * gustStrength ) + ( ( 0.2 + gustPhase ) * turbulence );
|
||||
|
||||
// Return the final directional wind effect.
|
||||
return gustOffset.xx * windDirection.xy;
|
||||
}
|
||||
|
||||
void foliageProcessVert( inout float3 position,
|
||||
inout float4 diffuse,
|
||||
inout float4 texCoord,
|
||||
inout float3 normal,
|
||||
inout float3 T,
|
||||
in float3 eyePos )
|
||||
{
|
||||
// Assign the normal and tagent values.
|
||||
//normal = float3( 0, 0, 1 );//cross( gc_camUp, gc_camRight );
|
||||
T = gc_camRight;
|
||||
|
||||
// Pull out local vars we need for work.
|
||||
int corner = ( diffuse.a * 255.0f ) + 0.5f;
|
||||
float2 size = texCoord.xy;
|
||||
int type = texCoord.z;
|
||||
|
||||
// The billboarding is based on the camera direction.
|
||||
float3 rightVec = gc_camRight * sCornerRight[corner];
|
||||
float3 upVec = gc_camUp * sCornerUp[corner];
|
||||
|
||||
// Figure out the corner position.
|
||||
float3 outPos = ( upVec * size.y ) + ( rightVec * size.x );
|
||||
float len = length( outPos.xyz );
|
||||
|
||||
// We derive the billboard phase used for wind calculations from its position.
|
||||
float bbPhase = dot( position.xyz, 1 );
|
||||
|
||||
// Get the overall wind gust and turbulence effects.
|
||||
float3 wind;
|
||||
wind.xy = windEffect( bbPhase,
|
||||
gc_windDir,
|
||||
gc_gustInfo.x, gc_gustInfo.y, gc_gustInfo.z,
|
||||
gc_turbInfo.x, gc_turbInfo.y );
|
||||
wind.z = 0;
|
||||
|
||||
// Add the summed wind effect into the point.
|
||||
outPos.xyz += wind.xyz * texCoord.w;
|
||||
|
||||
// Do a simple spherical clamp to keep the foliage
|
||||
// from stretching too much by wind effect.
|
||||
outPos.xyz = normalize( outPos.xyz ) * len;
|
||||
|
||||
// Move the point into world space.
|
||||
position += outPos;
|
||||
|
||||
// Grab the uv set and setup the texture coord.
|
||||
float4 uvSet = gc_typeRects[type];
|
||||
texCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
|
||||
texCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
|
||||
|
||||
// Animate the normal to get lighting changes
|
||||
// across the the wind swept foliage.
|
||||
//
|
||||
// TODO: Expose the 10x as a factor to control
|
||||
// how much the wind effects the lighting on the grass.
|
||||
//
|
||||
normal.xy += wind.xy * ( 10.0 * texCoord.w );
|
||||
normal = normalize( normal );
|
||||
|
||||
// Get the alpha fade value.
|
||||
|
||||
float fadeStart = gc_fadeParams.x;
|
||||
float fadeEnd = gc_fadeParams.y;
|
||||
const float fadeRange = fadeEnd - fadeStart;
|
||||
|
||||
float dist = distance( eyePos, position.xyz ) - fadeStart;
|
||||
diffuse.a = 1 - clamp( dist / fadeRange, 0, 1 );
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shdrConsts.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ConnectData
|
||||
{
|
||||
float2 texCoord : TEXCOORD0;
|
||||
float4 lum : COLOR0;
|
||||
float4 groundAlphaCoeff : COLOR1;
|
||||
float2 alphaLookup : TEXCOORD1;
|
||||
};
|
||||
|
||||
struct Fragout
|
||||
{
|
||||
float4 col : COLOR0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
Fragout main( ConnectData IN,
|
||||
uniform sampler2D diffuseMap : register(S0),
|
||||
uniform sampler2D alphaMap : register(S1),
|
||||
uniform float4 groundAlpha,
|
||||
uniform float4 ambient )
|
||||
{
|
||||
Fragout OUT;
|
||||
|
||||
float4 alpha = tex2D(alphaMap, IN.alphaLookup);
|
||||
OUT.col = float4( ambient.rgb * IN.lum.rgb, 1.0 ) * tex2D(diffuseMap, IN.texCoord);
|
||||
OUT.col.a = OUT.col.a * min(alpha, groundAlpha + IN.groundAlphaCoeff.x).x;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
126
Templates/Empty/game/shaders/common/fxFoliageReplicatorV.hlsl
Normal file
126
Templates/Empty/game/shaders/common/fxFoliageReplicatorV.hlsl
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures
|
||||
//-----------------------------------------------------------------------------
|
||||
struct VertData
|
||||
{
|
||||
float2 texCoord : TEXCOORD0;
|
||||
float2 waveScale : TEXCOORD1;
|
||||
float3 normal : NORMAL;
|
||||
float4 position : POSITION;
|
||||
};
|
||||
|
||||
struct ConnectData
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float2 outTexCoord : TEXCOORD0;
|
||||
float4 color : COLOR0;
|
||||
float4 groundAlphaCoeff : COLOR1;
|
||||
float2 alphaLookup : TEXCOORD1;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
ConnectData main( VertData IN,
|
||||
uniform float4x4 projection : register(C0),
|
||||
uniform float4x4 world : register(C4),
|
||||
uniform float GlobalSwayPhase : register(C8),
|
||||
uniform float SwayMagnitudeSide : register(C9),
|
||||
uniform float SwayMagnitudeFront : register(C10),
|
||||
uniform float GlobalLightPhase : register(C11),
|
||||
uniform float LuminanceMagnitude : register(C12),
|
||||
uniform float LuminanceMidpoint : register(C13),
|
||||
uniform float DistanceRange : register(C14),
|
||||
uniform float3 CameraPos : register(C15),
|
||||
uniform float TrueBillboard : register(C16)
|
||||
)
|
||||
{
|
||||
ConnectData OUT;
|
||||
|
||||
// Init a transform matrix to be used in the following steps
|
||||
float4x4 trans = 0;
|
||||
trans[0][0] = 1;
|
||||
trans[1][1] = 1;
|
||||
trans[2][2] = 1;
|
||||
trans[3][3] = 1;
|
||||
trans[0][3] = IN.position.x;
|
||||
trans[1][3] = IN.position.y;
|
||||
trans[2][3] = IN.position.z;
|
||||
|
||||
// Billboard transform * world matrix
|
||||
float4x4 o = world;
|
||||
o = mul(o, trans);
|
||||
|
||||
// Keep only the up axis result and position transform.
|
||||
// This gives us "cheating" cylindrical billboarding.
|
||||
o[0][0] = 1;
|
||||
o[1][0] = 0;
|
||||
o[2][0] = 0;
|
||||
o[3][0] = 0;
|
||||
o[0][1] = 0;
|
||||
o[1][1] = 1;
|
||||
o[2][1] = 0;
|
||||
o[3][1] = 0;
|
||||
|
||||
// Unless the user specified TrueBillboard,
|
||||
// in which case we want the z axis to also be camera facing.
|
||||
|
||||
#ifdef TRUE_BILLBOARD
|
||||
|
||||
o[0][2] = 0;
|
||||
o[1][2] = 0;
|
||||
o[2][2] = 1;
|
||||
o[3][2] = 0;
|
||||
|
||||
#endif
|
||||
|
||||
// Handle sway. Sway is stored in a texture coord. The x coordinate is the sway phase multiplier,
|
||||
// the y coordinate determines if this vertex actually sways or not.
|
||||
float xSway, ySway;
|
||||
float wavePhase = GlobalSwayPhase * IN.waveScale.x;
|
||||
sincos(wavePhase, ySway, xSway);
|
||||
xSway = xSway * IN.waveScale.y * SwayMagnitudeSide;
|
||||
ySway = ySway * IN.waveScale.y * SwayMagnitudeFront;
|
||||
float4 p;
|
||||
p = mul(o, float4(IN.normal.x + xSway, ySway, IN.normal.z, 1));
|
||||
|
||||
// Project the point
|
||||
OUT.hpos = mul(projection, p);
|
||||
|
||||
// Lighting
|
||||
float Luminance = LuminanceMidpoint + LuminanceMagnitude * cos(GlobalLightPhase + IN.normal.y);
|
||||
|
||||
// Alpha
|
||||
float3 worldPos = float3(IN.position.x, IN.position.y, IN.position.z);
|
||||
float alpha = abs(distance(worldPos, CameraPos)) / DistanceRange;
|
||||
alpha = clamp(alpha, 0.0f, 1.0f); //pass it through
|
||||
|
||||
OUT.alphaLookup = float2(alpha, 0.0f);
|
||||
OUT.groundAlphaCoeff = all(IN.normal.z);
|
||||
OUT.outTexCoord = IN.texCoord;
|
||||
OUT.color = float4(Luminance, Luminance, Luminance, 1.0f);
|
||||
|
||||
return OUT;
|
||||
}
|
||||
37
Templates/Empty/game/shaders/common/gl/blurP.glsl
Normal file
37
Templates/Empty/game/shaders/common/gl/blurP.glsl
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//*****************************************************************************
|
||||
// Glow Shader
|
||||
//*****************************************************************************
|
||||
uniform vec4 kernel;
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
varying vec2 texc0, texc1, texc2, texc3;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(diffuseMap, texc0) * kernel.x;
|
||||
gl_FragColor += texture2D(diffuseMap, texc1) * kernel.y;
|
||||
gl_FragColor += texture2D(diffuseMap, texc2) * kernel.z;
|
||||
gl_FragColor += texture2D(diffuseMap, texc3) * kernel.w;
|
||||
}
|
||||
43
Templates/Empty/game/shaders/common/gl/blurV.glsl
Normal file
43
Templates/Empty/game/shaders/common/gl/blurV.glsl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//*****************************************************************************
|
||||
// Glow shader
|
||||
//*****************************************************************************
|
||||
|
||||
uniform mat4 modelview;
|
||||
uniform vec2 offset0, offset1, offset2, offset3;
|
||||
|
||||
varying vec2 texc0, texc1, texc2, texc3;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
|
||||
vec2 tc = gl_MultiTexCoord0.st;
|
||||
tc.y = 1.0 - tc.y;
|
||||
|
||||
texc0 = tc + offset0;
|
||||
texc1 = tc + offset1;
|
||||
texc2 = tc + offset2;
|
||||
texc3 = tc + offset3;
|
||||
}
|
||||
139
Templates/Empty/game/shaders/common/gl/cloudLayerP.glsl
Normal file
139
Templates/Empty/game/shaders/common/gl/cloudLayerP.glsl
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hlslCompat.glsl"
|
||||
|
||||
varying vec4 texCoord12;
|
||||
varying vec4 texCoord34;
|
||||
varying vec3 vLightTS; // light vector in tangent space, denormalized
|
||||
varying vec3 vViewTS; // view vector in tangent space, denormalized
|
||||
varying vec3 vNormalWS; // Normal vector in world space
|
||||
varying float worldDist;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uniforms
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform sampler2D normalHeightMap;
|
||||
uniform vec3 ambientColor;
|
||||
uniform vec3 sunColor;
|
||||
uniform float cloudCoverage;
|
||||
uniform vec3 cloudBaseColor;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Globals
|
||||
//-----------------------------------------------------------------------------
|
||||
// The per-color weighting to be used for luminance calculations in RGB order.
|
||||
const vec3 LUMINANCE_VECTOR = vec3(0.2125f, 0.7154f, 0.0721f);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Calculates the Rayleigh phase function
|
||||
float getRayleighPhase( float angle )
|
||||
{
|
||||
return 0.75 * ( 1.0 + pow( angle, 2.0 ) );
|
||||
}
|
||||
|
||||
// Returns the output rgb color given a texCoord and parameters it uses
|
||||
// for lighting calculation.
|
||||
vec3 ComputeIllumination( vec2 texCoord,
|
||||
vec3 vLightTS,
|
||||
vec3 vViewTS,
|
||||
vec3 vNormalTS )
|
||||
{
|
||||
//return noiseNormal;
|
||||
//return vNormalTS;
|
||||
|
||||
vec3 vLightTSAdj = vec3( -vLightTS.x, -vLightTS.y, vLightTS.z );
|
||||
|
||||
float dp = dot( vNormalTS, vLightTSAdj );
|
||||
|
||||
// Calculate the amount of illumination (lightTerm)...
|
||||
|
||||
// We do both a rim lighting effect and a halfLambertian lighting effect
|
||||
// and combine the result.
|
||||
float halfLambertTerm = clamp( pow( dp * 0.5 + 0.5, 1.0 ), 0.0, 1.0 );
|
||||
float rimLightTerm = pow( ( 1.0 - dp ), 1.0 );
|
||||
float lightTerm = clamp( halfLambertTerm * 1.0 + rimLightTerm * dp, 0.0, 1.0 );
|
||||
lightTerm *= 0.5;
|
||||
|
||||
// Use a simple RayleighPhase function to simulate single scattering towards
|
||||
// the camera.
|
||||
float angle = dot( vLightTS, vViewTS );
|
||||
lightTerm *= getRayleighPhase( angle );
|
||||
|
||||
// Combine terms and colors into the output color.
|
||||
//vec3 lightColor = ( lightTerm * sunColor * fOcclusionShadow ) + ambientColor;
|
||||
vec3 lightColor = mix( ambientColor, sunColor, lightTerm );
|
||||
//lightColor = mix( lightColor, ambientColor, cloudCoverage );
|
||||
vec3 finalColor = cloudBaseColor * lightColor;
|
||||
|
||||
return finalColor;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Normalize the interpolated vectors:
|
||||
vec3 vViewTS = normalize( vViewTS );
|
||||
vec3 vLightTS = normalize( vLightTS );
|
||||
vec3 vNormalWS = normalize( vNormalWS );
|
||||
|
||||
vec4 cResultColor = float4( 0, 0, 0, 1 );
|
||||
|
||||
vec2 texSample = texCoord12.xy;
|
||||
|
||||
vec4 noise1 = texture2D( normalHeightMap, texCoord12.zw );
|
||||
noise1 = normalize( ( noise1 - 0.5 ) * 2.0 );
|
||||
//return noise1;
|
||||
|
||||
vec4 noise2 = texture2D( normalHeightMap, texCoord34.xy );
|
||||
noise2 = normalize( ( noise2 - 0.5 ) * 2.0 );
|
||||
//return noise2;
|
||||
|
||||
vec3 noiseNormal = normalize( noise1 + noise2 ).xyz;
|
||||
//return float4( noiseNormal, 1.0 );
|
||||
|
||||
float noiseHeight = noise1.a * noise2.a * ( cloudCoverage / 2.0 + 0.5 );
|
||||
|
||||
vec3 vNormalTS = normalize( texture2D( normalHeightMap, texSample ).xyz * 2.0 - 1.0 );
|
||||
vNormalTS += noiseNormal;
|
||||
vNormalTS = normalize( vNormalTS );
|
||||
|
||||
// Compute resulting color for the pixel:
|
||||
cResultColor.rgb = ComputeIllumination( texSample, vLightTS, vViewTS, vNormalTS );
|
||||
|
||||
float coverage = ( cloudCoverage - 0.5 ) * 2.0;
|
||||
cResultColor.a = texture2D( normalHeightMap, texSample ).a + coverage + noiseHeight;
|
||||
|
||||
if ( cloudCoverage > -1.0 )
|
||||
cResultColor.a /= 1.0 + coverage;
|
||||
|
||||
cResultColor.a = saturate( cResultColor.a * pow( saturate(cloudCoverage), 0.25 ) );
|
||||
|
||||
cResultColor.a = mix( cResultColor.a, 0.0, 1.0 - pow(worldDist,2.0) );
|
||||
|
||||
// If using HDR rendering, make sure to tonemap the resuld color prior to outputting it.
|
||||
// But since this example isn't doing that, we just output the computed result color here:
|
||||
gl_FragColor = cResultColor;
|
||||
}
|
||||
92
Templates/Empty/game/shaders/common/gl/cloudLayerV.glsl
Normal file
92
Templates/Empty/game/shaders/common/gl/cloudLayerV.glsl
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
varying vec4 texCoord12;
|
||||
varying vec4 texCoord34;
|
||||
varying vec3 vLightTS; // light vector in tangent space, denormalized
|
||||
varying vec3 vViewTS; // view vector in tangent space, denormalized
|
||||
varying vec3 vNormalWS; // Normal vector in world space
|
||||
varying float worldDist;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uniforms
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform mat4 modelview;
|
||||
uniform vec3 eyePosWorld;
|
||||
uniform vec3 sunVec;
|
||||
uniform vec2 texOffset0;
|
||||
uniform vec2 texOffset1;
|
||||
uniform vec2 texOffset2;
|
||||
uniform vec3 texScale;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
vec4 pos = gl_Vertex;
|
||||
vec3 normal = gl_Normal;
|
||||
vec3 binormal = gl_MultiTexCoord0.xyz;
|
||||
vec3 tangent = gl_MultiTexCoord1.xyz;
|
||||
vec2 uv0 = gl_MultiTexCoord2.st;
|
||||
|
||||
gl_Position = modelview * pos;
|
||||
|
||||
// Offset the uv so we don't have a seam directly over our head.
|
||||
vec2 uv = uv0 + vec2( 0.5, 0.5 );
|
||||
|
||||
texCoord12.xy = uv * texScale.x;
|
||||
texCoord12.xy += texOffset0;
|
||||
|
||||
texCoord12.zw = uv * texScale.y;
|
||||
texCoord12.zw += texOffset1;
|
||||
|
||||
texCoord34.xy = uv * texScale.z;
|
||||
texCoord34.xy += texOffset2;
|
||||
|
||||
texCoord34.z = pos.z;
|
||||
texCoord34.w = 0.0;
|
||||
|
||||
// Transform the normal, tangent and binormal vectors from object space to
|
||||
// homogeneous projection space:
|
||||
vNormalWS = -normal;
|
||||
vec3 vTangentWS = -tangent;
|
||||
vec3 vBinormalWS = -binormal;
|
||||
|
||||
// Compute position in world space:
|
||||
vec4 vPositionWS = pos + vec4( eyePosWorld, 1 ); //mul( pos, objTrans );
|
||||
|
||||
// Compute and output the world view vector (unnormalized):
|
||||
vec3 vViewWS = eyePosWorld - vPositionWS.xyz;
|
||||
|
||||
// Compute denormalized light vector in world space:
|
||||
vec3 vLightWS = -sunVec;
|
||||
|
||||
// Normalize the light and view vectors and transform it to the tangent space:
|
||||
mat3 mWorldToTangent = mat3( vTangentWS, vBinormalWS, vNormalWS );
|
||||
|
||||
// Propagate the view and the light vectors (in tangent space):
|
||||
vLightTS = mWorldToTangent * vLightWS;
|
||||
vViewTS = vViewWS * mWorldToTangent;
|
||||
|
||||
worldDist = clamp( pow( pos.z, 2.0 ), 0.0, 1.0 );
|
||||
}
|
||||
34
Templates/Empty/game/shaders/common/gl/debugInteriorsP.glsl
Normal file
34
Templates/Empty/game/shaders/common/gl/debugInteriorsP.glsl
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform sampler2D diffuseMap;
|
||||
uniform vec4 shadeColor;
|
||||
|
||||
varying vec2 TEX0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 diffuseColor = texture2D( diffuseMap, TEX0 );
|
||||
|
||||
gl_FragColor = diffuseColor;
|
||||
gl_FragColor *= shadeColor;
|
||||
}
|
||||
33
Templates/Empty/game/shaders/common/gl/debugInteriorsV.glsl
Normal file
33
Templates/Empty/game/shaders/common/gl/debugInteriorsV.glsl
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform mat4 modelview;
|
||||
|
||||
varying vec2 TEX0;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
TEX0 = gl_MultiTexCoord0.st;
|
||||
}
|
||||
|
||||
|
||||
196
Templates/Empty/game/shaders/common/gl/foliage.glsl
Normal file
196
Templates/Empty/game/shaders/common/gl/foliage.glsl
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// CornerId corresponds to this arrangement
|
||||
// from the perspective of the camera.
|
||||
//
|
||||
// 3 ---- 2
|
||||
// | |
|
||||
// 0 ---- 1
|
||||
//
|
||||
|
||||
#define MAX_COVERTYPES 8
|
||||
|
||||
uniform vec3 gc_camRight;
|
||||
uniform vec3 gc_camUp;
|
||||
uniform vec4 gc_typeRects[MAX_COVERTYPES];
|
||||
uniform vec2 gc_fadeParams;
|
||||
uniform vec2 gc_windDir;
|
||||
|
||||
// .x = gust length
|
||||
// .y = premultiplied simulation time and gust frequency
|
||||
// .z = gust strength
|
||||
uniform vec3 gc_gustInfo;
|
||||
|
||||
// .x = premultiplied simulation time and turbulance frequency
|
||||
// .y = turbulance strength
|
||||
uniform vec2 gc_turbInfo;
|
||||
|
||||
|
||||
//static float sMovableCorner[4] = { 0.0, 0.0, 1.0, 1.0 };
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// The following wind effect was derived from the GPU Gems 3 chapter...
|
||||
//
|
||||
// "Vegetation Procedural Animation and Shading in Crysis"
|
||||
// by Tiago Sousa, Crytek
|
||||
//
|
||||
|
||||
vec2 smoothCurve( vec2 x )
|
||||
{
|
||||
return x * x * ( 3.0 - 2.0 * x );
|
||||
}
|
||||
|
||||
vec2 triangleWave( vec2 x )
|
||||
{
|
||||
return abs( fract( x + 0.5 ) * 2.0 - 1.0 );
|
||||
}
|
||||
|
||||
vec2 smoothTriangleWave( vec2 x )
|
||||
{
|
||||
return smoothCurve( triangleWave( x ) );
|
||||
}
|
||||
|
||||
float windTurbulence( float bbPhase, float frequency, float strength )
|
||||
{
|
||||
// We create the input value for wave generation from the frequency and phase.
|
||||
vec2 waveIn = vec2( bbPhase + frequency );
|
||||
|
||||
// We use two square waves to generate the effect which
|
||||
// is then scaled by the overall strength.
|
||||
vec2 waves = ( fract( waveIn.xy * vec2( 1.975, 0.793 ) ) * 2.0 - 1.0 );
|
||||
waves = smoothTriangleWave( waves );
|
||||
|
||||
// Sum up the two waves into a single wave.
|
||||
return ( waves.x + waves.y ) * strength;
|
||||
}
|
||||
|
||||
vec2 windEffect( float bbPhase,
|
||||
vec2 windDirection,
|
||||
float gustLength,
|
||||
float gustFrequency,
|
||||
float gustStrength,
|
||||
float turbFrequency,
|
||||
float turbStrength )
|
||||
{
|
||||
// Calculate the ambient wind turbulence.
|
||||
float turbulence = windTurbulence( bbPhase, turbFrequency, turbStrength );
|
||||
|
||||
// We simulate the overall gust via a sine wave.
|
||||
float gustPhase = clamp( sin( ( bbPhase - gustFrequency ) / gustLength ) , 0.0, 1.0 );
|
||||
float gustOffset = ( gustPhase * gustStrength ) + ( ( 0.2 + gustPhase ) * turbulence );
|
||||
|
||||
// Return the final directional wind effect.
|
||||
return vec2(gustOffset) * windDirection.xy;
|
||||
}
|
||||
|
||||
void foliageProcessVert( inout vec3 position,
|
||||
inout vec4 diffuse,
|
||||
in vec4 texCoord,
|
||||
out vec2 outTexCoord,
|
||||
inout vec3 normal,
|
||||
inout vec3 T,
|
||||
in vec3 eyePos )
|
||||
{
|
||||
|
||||
float sCornerRight[4];
|
||||
sCornerRight[0] = -0.5;
|
||||
sCornerRight[1] = 0.5;
|
||||
sCornerRight[2] = 0.5;
|
||||
sCornerRight[3] = -0.5;
|
||||
|
||||
float sCornerUp[4];
|
||||
sCornerUp[0] = 0.0;
|
||||
sCornerUp[1] = 0.0;
|
||||
sCornerUp[2] = 1.0;
|
||||
sCornerUp[3] = 1.0;
|
||||
|
||||
vec2 sUVCornerExtent[4];
|
||||
sUVCornerExtent[0] = vec2( 0.0, 1.0 );
|
||||
sUVCornerExtent[1] = vec2( 1.0, 1.0 );
|
||||
sUVCornerExtent[2] = vec2( 1.0, 0.0 );
|
||||
sUVCornerExtent[3] = vec2( 0.0, 0.0 );
|
||||
|
||||
|
||||
// Assign the normal and tagent values.
|
||||
//normal = cross( gc_camUp, gc_camRight );
|
||||
T = gc_camRight;
|
||||
|
||||
// Pull out local vars we need for work.
|
||||
int corner = int( ( diffuse.a * 255.0 ) + 0.5 );
|
||||
vec2 size = texCoord.xy;
|
||||
int type = int( texCoord.z );
|
||||
|
||||
// The billboarding is based on the camera direction.
|
||||
vec3 rightVec = gc_camRight * sCornerRight[corner];
|
||||
vec3 upVec = gc_camUp * sCornerUp[corner];
|
||||
|
||||
// Figure out the corner position.
|
||||
vec3 outPos = ( upVec * size.y ) + ( rightVec * size.x );
|
||||
float len = length( outPos.xyz );
|
||||
|
||||
// We derive the billboard phase used for wind calculations from its position.
|
||||
float bbPhase = dot( position.xyz, vec3( 1.0 ) );
|
||||
|
||||
// Get the overall wind gust and turbulence effects.
|
||||
vec3 wind;
|
||||
wind.xy = windEffect( bbPhase,
|
||||
gc_windDir,
|
||||
gc_gustInfo.x, gc_gustInfo.y, gc_gustInfo.z,
|
||||
gc_turbInfo.x, gc_turbInfo.y );
|
||||
wind.z = 0.0;
|
||||
|
||||
// Add the summed wind effect into the point.
|
||||
outPos.xyz += wind.xyz * texCoord.w;
|
||||
|
||||
// Do a simple spherical clamp to keep the foliage
|
||||
// from stretching too much by wind effect.
|
||||
outPos.xyz = normalize( outPos.xyz ) * len;
|
||||
|
||||
// Move the point into world space.
|
||||
position += outPos;
|
||||
|
||||
// Grab the uv set and setup the texture coord.
|
||||
vec4 uvSet = gc_typeRects[type];
|
||||
outTexCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
|
||||
outTexCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
|
||||
|
||||
// Animate the normal to get lighting changes
|
||||
// across the the wind swept foliage.
|
||||
//
|
||||
// TODO: Expose the 10x as a factor to control
|
||||
// how much the wind effects the lighting on the grass.
|
||||
//
|
||||
normal.xy += wind.xy * ( 10.0 * texCoord.w );
|
||||
normal = normalize( normal );
|
||||
|
||||
|
||||
// Get the alpha fade value.
|
||||
|
||||
float fadeStart = gc_fadeParams.x;
|
||||
float fadeEnd = gc_fadeParams.y;
|
||||
float fadeRange = fadeEnd - fadeStart;
|
||||
|
||||
float dist = distance( eyePos, position.xyz ) - fadeStart;
|
||||
diffuse.a = 1.0 - clamp( dist / fadeRange, 0.0, 1.0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform sampler2D diffuseMap, alphaMap;
|
||||
uniform vec4 groundAlpha;
|
||||
|
||||
varying vec4 color, groundAlphaCoeff;
|
||||
varying vec2 outTexCoord, alphaLookup;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
vec4 alpha = texture2D(alphaMap, alphaLookup);
|
||||
gl_FragColor = color * texture2D(diffuseMap, outTexCoord);
|
||||
gl_FragColor.a = gl_FragColor.a * min(alpha, groundAlpha + groundAlphaCoeff.x).x;
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform mat4 projection, world;
|
||||
uniform vec3 CameraPos;
|
||||
uniform float GlobalSwayPhase, SwayMagnitudeSide, SwayMagnitudeFront,
|
||||
GlobalLightPhase, LuminanceMagnitude, LuminanceMidpoint, DistanceRange;
|
||||
|
||||
varying vec4 color, groundAlphaCoeff;
|
||||
varying vec2 outTexCoord, alphaLookup;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
// Init a transform matrix to be used in the following steps
|
||||
mat4 trans = mat4(0.0);
|
||||
trans[0][0] = 1.0;
|
||||
trans[1][1] = 1.0;
|
||||
trans[2][2] = 1.0;
|
||||
trans[3][3] = 1.0;
|
||||
trans[3][0] = gl_Vertex.x;
|
||||
trans[3][1] = gl_Vertex.y;
|
||||
trans[3][2] = gl_Vertex.z;
|
||||
|
||||
// Billboard transform * world matrix
|
||||
mat4 o = world;
|
||||
o = o * trans;
|
||||
|
||||
// Keep only the up axis result and position transform.
|
||||
// This gives us "cheating" cylindrical billboarding.
|
||||
o[0][0] = 1.0;
|
||||
o[0][1] = 0.0;
|
||||
o[0][2] = 0.0;
|
||||
o[0][3] = 0.0;
|
||||
o[1][0] = 0.0;
|
||||
o[1][1] = 1.0;
|
||||
o[1][2] = 0.0;
|
||||
o[1][3] = 0.0;
|
||||
|
||||
// Handle sway. Sway is stored in a texture coord. The x coordinate is the sway phase multiplier,
|
||||
// the y coordinate determines if this vertex actually sways or not.
|
||||
float xSway, ySway;
|
||||
float wavePhase = GlobalSwayPhase * gl_MultiTexCoord1.x;
|
||||
ySway = sin(wavePhase);
|
||||
xSway = cos(wavePhase);
|
||||
xSway = xSway * gl_MultiTexCoord1.y * SwayMagnitudeSide;
|
||||
ySway = ySway * gl_MultiTexCoord1.y * SwayMagnitudeFront;
|
||||
vec4 p;
|
||||
p = o * vec4(gl_Normal.x + xSway, ySway, gl_Normal.z, 1.0);
|
||||
|
||||
// Project the point
|
||||
gl_Position = projection * p;
|
||||
|
||||
// Lighting
|
||||
float Luminance = LuminanceMidpoint + LuminanceMagnitude * cos(GlobalLightPhase + gl_Normal.y);
|
||||
|
||||
// Alpha
|
||||
vec3 worldPos = vec3(gl_Vertex.x, gl_Vertex.y, gl_Vertex.z);
|
||||
float alpha = abs(distance(worldPos, CameraPos)) / DistanceRange;
|
||||
alpha = clamp(alpha, 0.0, 1.0); //pass it through
|
||||
|
||||
alphaLookup = vec2(alpha, 0.0);
|
||||
bool alphaCoeff = bool(gl_Normal.z);
|
||||
groundAlphaCoeff = vec4(float(alphaCoeff));
|
||||
outTexCoord = gl_MultiTexCoord0.st;
|
||||
color = vec4(Luminance, Luminance, Luminance, 1.0);
|
||||
}
|
||||
35
Templates/Empty/game/shaders/common/gl/guiMaterialV.glsl
Normal file
35
Templates/Empty/game/shaders/common/gl/guiMaterialV.glsl
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform mat4x4 modelview;
|
||||
|
||||
varying vec4 hpos;
|
||||
varying vec2 uv0;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
hpos = vec4( modelview * gl_Vertex );
|
||||
gl_Position = hpos;
|
||||
|
||||
uv0 = gl_MultiTexCoord0.st;
|
||||
}
|
||||
43
Templates/Empty/game/shaders/common/gl/hlslCompat.glsl
Normal file
43
Templates/Empty/game/shaders/common/gl/hlslCompat.glsl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// These are some simple wrappers for simple
|
||||
// HLSL compatibility.
|
||||
|
||||
#define float4 vec4
|
||||
#define float3 vec3
|
||||
#define float2 vec2
|
||||
|
||||
#define texCUBE textureCube
|
||||
#define tex2D texture2D
|
||||
|
||||
#define lerp mix
|
||||
|
||||
float saturate( float val ) { return clamp( val, 0.0, 1.0 ); }
|
||||
vec2 saturate( vec2 val ) { return clamp( val, 0.0, 1.0 ); }
|
||||
vec3 saturate( vec3 val ) { return clamp( val, 0.0, 1.0 ); }
|
||||
vec4 saturate( vec4 val ) { return clamp( val, 0.0, 1.0 ); }
|
||||
|
||||
float round( float n ) { return sign( n ) * floor( abs( n ) + 0.5 ); }
|
||||
vec2 round( vec2 n ) { return sign( n ) * floor( abs( n ) + 0.5 ); }
|
||||
vec3 round( vec3 n ) { return sign( n ) * floor( abs( n ) + 0.5 ); }
|
||||
vec4 round( vec4 n ) { return sign( n ) * floor( abs( n ) + 0.5 ); }
|
||||
161
Templates/Empty/game/shaders/common/gl/imposter.glsl
Normal file
161
Templates/Empty/game/shaders/common/gl/imposter.glsl
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "torque.glsl"
|
||||
|
||||
|
||||
#define IMPOSTER_MAX_UVS 64
|
||||
|
||||
|
||||
void imposter_v(
|
||||
// These parameters usually come from the vertex.
|
||||
vec3 center,
|
||||
int corner,
|
||||
float halfSize,
|
||||
vec3 imposterUp,
|
||||
vec3 imposterRight,
|
||||
|
||||
// These are from the imposter shader constant.
|
||||
int numEquatorSteps,
|
||||
int numPolarSteps,
|
||||
float polarAngle,
|
||||
bool includePoles,
|
||||
|
||||
// Other shader constants.
|
||||
vec3 camPos,
|
||||
vec4 uvs[IMPOSTER_MAX_UVS],
|
||||
|
||||
// The outputs of this function.
|
||||
out vec3 outWsPosition,
|
||||
out vec2 outTexCoord,
|
||||
out mat3 outWorldToTangent
|
||||
)
|
||||
{
|
||||
|
||||
float M_HALFPI_F = 1.57079632679489661923;
|
||||
float M_PI_F = 3.14159265358979323846;
|
||||
float M_2PI_F = 6.28318530717958647692;
|
||||
|
||||
|
||||
float sCornerRight[4];// = float[]( -1.0, 1.0, 1.0, -1.0 );
|
||||
sCornerRight[0] = -1.0;
|
||||
sCornerRight[1] = 1.0;
|
||||
sCornerRight[2] = 1.0;
|
||||
sCornerRight[3] = -1.0;
|
||||
float sCornerUp[4];// = float[]( -1.0, -1.0, 1.0, 1.0 );
|
||||
sCornerUp[0] = -1.0;
|
||||
sCornerUp[1] = -1.0;
|
||||
sCornerUp[2] = 1.0;
|
||||
sCornerUp[3] = 1.0;
|
||||
vec2 sUVCornerExtent[4];// = vec2[](vec2( 0.0, 1.0 ), vec2( 1.0, 1.0 ), vec2( 1.0, 0.0 ), vec2( 0.0, 0.0 ));
|
||||
sUVCornerExtent[0] = vec2( 0.0, 1.0 );
|
||||
sUVCornerExtent[1] = vec2( 1.0, 1.0 );
|
||||
sUVCornerExtent[2] = vec2( 1.0, 0.0 );
|
||||
sUVCornerExtent[3] = vec2( 0.0, 0.0 );
|
||||
|
||||
// TODO: This could all be calculated on the CPU.
|
||||
float equatorStepSize = M_2PI_F / float( numEquatorSteps );
|
||||
float equatorHalfStep = ( equatorStepSize / 2.0 ) - 0.0001;
|
||||
float polarStepSize = M_PI_F / float( numPolarSteps );
|
||||
float polarHalfStep = ( polarStepSize / 2.0 ) - 0.0001;
|
||||
|
||||
// The vector between the camera and the billboard.
|
||||
vec3 lookVec = normalize( camPos - center );
|
||||
|
||||
// Generate the camera up and right vectors from
|
||||
// the object transform and camera forward.
|
||||
vec3 camUp = imposterUp;
|
||||
vec3 camRight = cross( -lookVec, camUp );
|
||||
|
||||
// The billboarding is based on the camera directions.
|
||||
vec3 rightVec = camRight * sCornerRight[corner];
|
||||
vec3 upVec = camUp * sCornerUp[corner];
|
||||
|
||||
float lookPitch = acos( dot( imposterUp, lookVec ) );
|
||||
|
||||
// First check to see if we need to render the top billboard.
|
||||
int index;
|
||||
/*
|
||||
if ( includePoles && ( lookPitch < polarAngle || lookPitch > sPi - polarAngle ) )
|
||||
{
|
||||
index = numEquatorSteps * 3;
|
||||
|
||||
// When we render the top/bottom billboard we always use
|
||||
// a fixed vector that matches the rotation of the object.
|
||||
rightVec = vec3( 1, 0, 0 ) * sCornerRight[corner];
|
||||
upVec = vec3( 0, 1, 0 ) * sCornerUp[corner];
|
||||
|
||||
if ( lookPitch > sPi - polarAngle )
|
||||
{
|
||||
upVec = -upVec;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
else
|
||||
*/
|
||||
{
|
||||
// Calculate the rotation around the z axis then add the
|
||||
// equator half step. This gets the images to switch a
|
||||
// half step before the captured angle is met.
|
||||
float lookAzimuth = atan( lookVec.y, lookVec.x );
|
||||
float azimuth = atan( imposterRight.y, imposterRight.x );
|
||||
float rotZ = ( lookAzimuth - azimuth ) + equatorHalfStep;
|
||||
|
||||
// The y rotation is calculated from the look vector and
|
||||
// the object up vector.
|
||||
float rotY = lookPitch - polarHalfStep;
|
||||
|
||||
// TODO: How can we do this without conditionals?
|
||||
// Normalize the result to 0 to 2PI.
|
||||
if ( rotZ < 0.0 )
|
||||
rotZ += M_2PI_F;
|
||||
if ( rotZ > M_2PI_F )
|
||||
rotZ -= M_2PI_F;
|
||||
if ( rotY < 0.0 )
|
||||
rotY += M_2PI_F;
|
||||
if ( rotY > M_PI_F ) // Not M_2PI_F?
|
||||
rotY -= M_2PI_F;
|
||||
|
||||
float polarIdx = round( abs( rotY ) / polarStepSize );
|
||||
|
||||
// Get the index to the start of the right polar
|
||||
// images for this viewing angle.
|
||||
int numPolarOffset = int( float( numEquatorSteps ) * polarIdx );
|
||||
|
||||
// Calculate the final image index for lookup
|
||||
// of the texture coords.
|
||||
index = int( rotZ / equatorStepSize ) + numPolarOffset;
|
||||
}
|
||||
|
||||
// Generate the final world space position.
|
||||
outWsPosition = center + ( upVec * halfSize ) + ( rightVec * halfSize );
|
||||
|
||||
// Grab the uv set and setup the texture coord.
|
||||
vec4 uvSet = uvs[index];
|
||||
outTexCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
|
||||
outTexCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
|
||||
|
||||
// Needed for normal mapping and lighting.
|
||||
outWorldToTangent[0] = vec3( 1, 0, 0 );
|
||||
outWorldToTangent[1] = vec3( 0, 1, 0 );
|
||||
outWorldToTangent[2] = vec3( 0, 0, -1 );
|
||||
}
|
||||
115
Templates/Empty/game/shaders/common/gl/lighting.glsl
Normal file
115
Templates/Empty/game/shaders/common/gl/lighting.glsl
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// These are the uniforms used by most lighting shaders.
|
||||
|
||||
uniform vec3 inLightPos[4];
|
||||
uniform vec4 inLightInvRadiusSq;
|
||||
uniform vec4 inLightColor[4];
|
||||
uniform vec4 ambient;
|
||||
uniform float specularPower;
|
||||
uniform vec4 specularColor;
|
||||
|
||||
|
||||
// This is used to limit the maximum processed
|
||||
// lights in the compute4Lights down for really
|
||||
// low end GPUs.
|
||||
//
|
||||
// NOTE: If you want to support 10.5.x, this needs to be changed to 2.
|
||||
#define C4L_MAX_LIGHTS 4
|
||||
|
||||
|
||||
void compute4Lights( vec3 wsView,
|
||||
vec3 wsPosition,
|
||||
vec3 wsNormal,
|
||||
out vec4 outDiffuse,
|
||||
out vec4 outSpecular )
|
||||
{
|
||||
#ifdef PHONG_SPECULAR
|
||||
// (R.V)^c
|
||||
float reflected = reflect( wsView, wsNormal );
|
||||
#endif
|
||||
|
||||
vec4 nDotL = vec4( 0.0 );
|
||||
vec4 rDotL = vec4( 0.0 );
|
||||
vec4 sqDists = vec4( 0.0 );
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < C4L_MAX_LIGHTS; ++i )
|
||||
{
|
||||
vec3 lightVector = inLightPos[i] - wsPosition;
|
||||
vec3 lightDirection = normalize( lightVector );
|
||||
|
||||
nDotL[i] = max( dot( lightDirection, wsNormal ), 0.0 );
|
||||
|
||||
#ifdef PHONG_SPECULAR
|
||||
rDotL[i] = saturate( dot( lightDirection, reflected ) );
|
||||
#else
|
||||
// (N.H)^c [Blinn-Phong, TGEA style, default]
|
||||
rDotL[i] = dot( wsNormal, normalize( lightDirection + wsView ) );
|
||||
#endif
|
||||
|
||||
sqDists[i] = dot( lightVector, lightVector );
|
||||
}
|
||||
|
||||
// Attenuation
|
||||
vec4 atten = vec4( 1.0 ) - ( sqDists * inLightInvRadiusSq );
|
||||
|
||||
// Combine the light colors for output.
|
||||
vec4 diffuse = clamp( nDotL * atten, vec4( 0.0 ), vec4( 1.0 ) );
|
||||
outDiffuse = vec4( 0.0 );
|
||||
for ( i = 0; i < C4L_MAX_LIGHTS; ++i )
|
||||
outDiffuse += vec4( diffuse[i] ) * inLightColor[i];
|
||||
|
||||
// Output the specular power.
|
||||
rDotL = max( rDotL, vec4( 0.00001 ) );
|
||||
outSpecular = pow( rDotL, vec4( specularPower ) );
|
||||
}
|
||||
|
||||
|
||||
/// The standard specular calculation.
|
||||
///
|
||||
/// @param toLight Normalized vector representing direction from the pixel
|
||||
/// being lit, to the light source, in world space.
|
||||
///
|
||||
/// @param normal Normalized surface normal.
|
||||
///
|
||||
/// @param toEye The normalized vector representing direction from the pixel
|
||||
/// being lit to the camera.
|
||||
///
|
||||
/// @param specPwr The specular exponent.
|
||||
///
|
||||
/// @param specScale A scalar on the specular output used in RGB accumulation.
|
||||
///
|
||||
float calcSpecular( vec3 toLight, vec3 normal, vec3 toEye, float specPwr )
|
||||
{
|
||||
#ifdef PHONG_SPECULAR
|
||||
// (R.V)^c
|
||||
float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye );
|
||||
#else
|
||||
// (N.H)^c [Blinn-Phong, TGEA style, default]
|
||||
float specVal = dot( normal, normalize( toLight + toEye ) );
|
||||
#endif
|
||||
|
||||
// Return the specular factor.
|
||||
return pow( max( specVal, 0.00001f ), specPwr );
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "torque.glsl"
|
||||
|
||||
uniform sampler2D colorSource;
|
||||
uniform vec4 offscreenTargetParams;
|
||||
|
||||
#ifdef TORQUE_LINEAR_DEPTH
|
||||
#define REJECT_EDGES
|
||||
uniform sampler2D edgeSource;
|
||||
uniform vec4 edgeTargetParams;
|
||||
#endif
|
||||
|
||||
varying vec4 backbufferPos;
|
||||
varying vec4 offscreenPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Off-screen particle source screenspace position in XY
|
||||
// Back-buffer screenspace position in ZW
|
||||
vec4 ssPos = vec4(offscreenPos.xy / offscreenPos.w, backbufferPos.xy / backbufferPos.w);
|
||||
|
||||
vec4 uvScene = ( ssPos + 1.0 ) / 2.0;
|
||||
uvScene.yw = 1.0 - uvScene.yw;
|
||||
uvScene.xy = viewportCoordToRenderTarget(uvScene.xy, offscreenTargetParams);
|
||||
|
||||
#ifdef REJECT_EDGES
|
||||
// Cut out particles along the edges, this will create the stencil mask
|
||||
uvScene.zw = viewportCoordToRenderTarget(uvScene.zw, edgeTargetParams);
|
||||
float edge = texture2D( edgeSource, uvScene.zw ).r;
|
||||
if (-edge < 0.0)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
// Sample offscreen target and return
|
||||
gl_FragColor = texture2D( colorSource, uvScene.xy );
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform mat4 modelViewProj;
|
||||
uniform mat4 targetModelViewProj;
|
||||
|
||||
varying vec4 offscreenPos;
|
||||
varying vec4 backbufferPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelViewProj * gl_Vertex;
|
||||
backbufferPos = gl_Position;
|
||||
offscreenPos = targetModelViewProj * gl_Vertex;
|
||||
}
|
||||
|
||||
82
Templates/Empty/game/shaders/common/gl/particlesP.glsl
Normal file
82
Templates/Empty/game/shaders/common/gl/particlesP.glsl
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hlslCompat.glsl"
|
||||
#include "torque.glsl"
|
||||
|
||||
// With advanced lighting we get soft particles.
|
||||
#ifdef TORQUE_LINEAR_DEPTH
|
||||
#define SOFTPARTICLES
|
||||
#endif
|
||||
|
||||
#define CLIP_Z // TODO: Make this a proper macro
|
||||
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
#ifdef SOFTPARTICLES
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
uniform float oneOverSoftness;
|
||||
uniform float oneOverFar;
|
||||
uniform sampler2D prepassTex;
|
||||
//uniform vec3 vEye;
|
||||
uniform vec4 prePassTargetParams;
|
||||
#endif
|
||||
|
||||
uniform float alphaFactor;
|
||||
uniform float alphaScale;
|
||||
|
||||
varying vec4 color;
|
||||
varying vec2 uv0;
|
||||
varying vec4 pos;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
float softBlend = 1.0;
|
||||
|
||||
#ifdef SOFTPARTICLES
|
||||
float2 tc = pos.xy * vec2(1.0, -1.0 ) / pos.w;
|
||||
tc = viewportCoordToRenderTarget(saturate( ( tc + 1.0 ) * 0.5 ), prePassTargetParams);
|
||||
|
||||
float sceneDepth = prepassUncondition( prepassTex, tc ).w;
|
||||
float depth = pos.w * oneOverFar;
|
||||
float diff = sceneDepth - depth;
|
||||
#ifdef CLIP_Z
|
||||
// If drawing offscreen, this acts as the depth test, since we don't line up with the z-buffer
|
||||
// When drawing high-res, though, we want to be able to take advantage of hi-z
|
||||
// so this is #ifdef'd out
|
||||
if (diff < 0.0)
|
||||
discard;
|
||||
#endif
|
||||
softBlend = saturate( diff * oneOverSoftness );
|
||||
#endif
|
||||
|
||||
vec4 diffuse = texture2D( diffuseMap, uv0 );
|
||||
|
||||
// Scale output color by the alpha factor (turn LerpAlpha into pre-multiplied alpha)
|
||||
vec3 colorScale = ( alphaFactor < 0.0 ? color.rgb * diffuse.rgb : ( alphaFactor > 0.0 ? vec3(color.a * alphaFactor * diffuse.a * softBlend) : vec3(softBlend) ) );
|
||||
|
||||
gl_FragColor = hdrEncode( vec4(color.rgb * diffuse.rgb * colorScale, softBlend * color.a * diffuse.a * alphaScale) );
|
||||
}
|
||||
|
||||
37
Templates/Empty/game/shaders/common/gl/particlesV.glsl
Normal file
37
Templates/Empty/game/shaders/common/gl/particlesV.glsl
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
varying vec4 color;
|
||||
varying vec2 uv0;
|
||||
varying vec4 pos;
|
||||
|
||||
uniform mat4 modelViewProj;
|
||||
uniform mat4 fsModelViewProj;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelViewProj * gl_Vertex;
|
||||
pos = fsModelViewProj * gl_Vertex;
|
||||
color = gl_Color;
|
||||
uv0 = gl_MultiTexCoord0.st;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform sampler2D diffuseMap, refractMap, bumpMap;
|
||||
uniform vec4 shadeColor;
|
||||
|
||||
varying vec2 TEX0;
|
||||
varying vec4 TEX1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Fade edges of axis for texcoord passed in
|
||||
//-----------------------------------------------------------------------------
|
||||
float fadeAxis( float val )
|
||||
{
|
||||
// Fades from 1.0 to 0.0 when less than 0.1
|
||||
float fadeLow = clamp( val * 10.0, 0.0, 1.0 );
|
||||
|
||||
// Fades from 1.0 to 0.0 when greater than 0.9
|
||||
float fadeHigh = 1.0 - clamp( (val - 0.9) * 10.0, 0.0, 1.0 );
|
||||
|
||||
return fadeLow * fadeHigh;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
vec3 bumpNorm = texture2D( bumpMap, TEX0 ).rgb * 2.0 - 1.0;
|
||||
vec2 offset = vec2( bumpNorm.x, bumpNorm.y );
|
||||
vec4 texIndex = TEX1;
|
||||
|
||||
// The fadeVal is used to "fade" the distortion at the edges of the screen.
|
||||
// This is done so it won't sample the reflection texture out-of-bounds and create artifacts
|
||||
// Note - this can be done more efficiently with a texture lookup
|
||||
float fadeVal = fadeAxis( texIndex.x / texIndex.w ) * fadeAxis( texIndex.y / texIndex.w );
|
||||
|
||||
const float distortion = 0.2;
|
||||
texIndex.xy += offset * distortion * fadeVal;
|
||||
|
||||
vec4 diffuseColor = texture2D( diffuseMap, TEX0 );
|
||||
vec4 reflectColor = texture2DProj( refractMap, texIndex );
|
||||
|
||||
gl_FragColor = diffuseColor + reflectColor * diffuseColor.a;
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform mat4 modelview;
|
||||
|
||||
varying vec2 TEX0;
|
||||
varying vec4 TEX1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
mat4 texGenTest = mat4(0.5, 0.0, 0.0, 0.0,
|
||||
0.0, -0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.5, 0.5, 0.0, 1.0);
|
||||
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
|
||||
TEX0 = gl_MultiTexCoord0.st;
|
||||
|
||||
TEX1 = texGenTest * gl_Position;
|
||||
TEX1.y = -TEX1.y;
|
||||
|
||||
}
|
||||
41
Templates/Empty/game/shaders/common/gl/planarReflectP.glsl
Normal file
41
Templates/Empty/game/shaders/common/gl/planarReflectP.glsl
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform sampler2D diffuseMap, refractMap;
|
||||
uniform vec4 shadeColor;
|
||||
|
||||
varying vec2 TEX0;
|
||||
varying vec4 TEX1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
vec4 diffuseColor = texture2D( diffuseMap, TEX0 );
|
||||
vec4 reflectColor = texture2DProj( refractMap, TEX1 );
|
||||
|
||||
gl_FragColor = diffuseColor + reflectColor * diffuseColor.a;
|
||||
}
|
||||
48
Templates/Empty/game/shaders/common/gl/planarReflectV.glsl
Normal file
48
Templates/Empty/game/shaders/common/gl/planarReflectV.glsl
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform mat4 modelview;
|
||||
|
||||
varying vec2 TEX0;
|
||||
varying vec4 TEX1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
mat4 texGenTest = mat4(0.5, 0.0, 0.0, 0.0,
|
||||
0.0, -0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.5, 0.5, 0.0, 1.0);
|
||||
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
|
||||
TEX0 = gl_MultiTexCoord0.st;
|
||||
|
||||
TEX1 = texGenTest * gl_Position;
|
||||
TEX1.y = -TEX1.y;
|
||||
|
||||
}
|
||||
37
Templates/Empty/game/shaders/common/gl/precipP.glsl
Normal file
37
Templates/Empty/game/shaders/common/gl/precipP.glsl
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
varying vec4 color;
|
||||
varying vec2 texCoord;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(diffuseMap, texCoord) * color;
|
||||
}
|
||||
50
Templates/Empty/game/shaders/common/gl/precipV.glsl
Normal file
50
Templates/Empty/game/shaders/common/gl/precipV.glsl
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform mat4 modelview;
|
||||
uniform vec3 cameraPos, ambient;
|
||||
uniform vec2 fadeStartEnd;
|
||||
|
||||
varying vec4 color;
|
||||
varying vec2 texCoord;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
texCoord = gl_MultiTexCoord0.st;
|
||||
color = vec4( ambient.r, ambient.g, ambient.b, 1.0 );
|
||||
|
||||
// Do we need to do a distance fade?
|
||||
if ( fadeStartEnd.x < fadeStartEnd.y )
|
||||
{
|
||||
|
||||
float distance = length( cameraPos - gl_Vertex.xyz );
|
||||
color.a = abs( clamp( ( distance - fadeStartEnd.x ) / ( fadeStartEnd.y - fadeStartEnd.x ), 0.0, 1.0 ) - 1.0 );
|
||||
}
|
||||
}
|
||||
|
||||
46
Templates/Empty/game/shaders/common/gl/projectedShadowP.glsl
Normal file
46
Templates/Empty/game/shaders/common/gl/projectedShadowP.glsl
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec4 color;
|
||||
varying float fade;
|
||||
|
||||
uniform sampler2D inputTex;
|
||||
uniform vec4 ambient;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 LUMINANCE_VECTOR = vec3(0.2125f, 0.4154f, 0.1721f);
|
||||
float esmFactor = 200.0;
|
||||
|
||||
float lum = dot( ambient.rgb, LUMINANCE_VECTOR );
|
||||
|
||||
gl_FragColor.rgb = ambient.rgb * lum;
|
||||
gl_FragColor.a = 0.0;
|
||||
float depth = texture2D(inputTex, texCoord).a;
|
||||
|
||||
depth = depth * exp(depth - 10.0);
|
||||
depth = exp(esmFactor * depth) - 1.0;
|
||||
|
||||
gl_FragColor.a = clamp(depth * 300.0, 0.0, 1.0) * (1.0 - lum) * fade * color.a;
|
||||
}
|
||||
44
Templates/Empty/game/shaders/common/gl/projectedShadowV.glsl
Normal file
44
Templates/Empty/game/shaders/common/gl/projectedShadowV.glsl
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//*****************************************************************************
|
||||
// Precipitation vertex shader
|
||||
//*****************************************************************************
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec4 color;
|
||||
varying float fade;
|
||||
|
||||
uniform mat4 modelview;
|
||||
uniform float shadowLength;
|
||||
uniform vec3 shadowCasterPosition;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * vec4(gl_Vertex.xyz, 1.0);
|
||||
|
||||
color = gl_Color;
|
||||
texCoord = gl_MultiTexCoord1.st;
|
||||
|
||||
float fromCasterDist = length(gl_Vertex.xyz - shadowCasterPosition) - shadowLength;
|
||||
fade = 1.0 - clamp(fromCasterDist/shadowLength, 0.0, 1.0);
|
||||
}
|
||||
79
Templates/Empty/game/shaders/common/gl/scatterSkyP.glsl
Normal file
79
Templates/Empty/game/shaders/common/gl/scatterSkyP.glsl
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "torque.glsl"
|
||||
|
||||
// Calculates the Mie phase function
|
||||
float getMiePhase(float fCos, float fCos2, float g, float g2)
|
||||
{
|
||||
return 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos2) / pow(abs(1.0 + g2 - 2.0*g*fCos), 1.5);
|
||||
}
|
||||
|
||||
// Calculates the Rayleigh phase function
|
||||
float getRayleighPhase(float fCos2)
|
||||
{
|
||||
//return 1.0;
|
||||
return 0.75 + 0.75*fCos2;
|
||||
}
|
||||
|
||||
varying vec4 rayleighColor;
|
||||
varying vec4 mieColor;
|
||||
varying vec3 v3Direction;
|
||||
varying float zPosition;
|
||||
varying vec3 pos;
|
||||
|
||||
uniform samplerCube nightSky;
|
||||
uniform vec4 nightColor;
|
||||
uniform vec2 nightInterpAndExposure;
|
||||
uniform float useCubemap;
|
||||
uniform vec3 lightDir;
|
||||
uniform vec3 sunDir;
|
||||
|
||||
void main()
|
||||
{
|
||||
float fCos = dot( lightDir, v3Direction ) / length(v3Direction);
|
||||
float fCos2 = fCos*fCos;
|
||||
|
||||
float g = -0.991;
|
||||
float g2 = -0.991 * -0.991;
|
||||
|
||||
float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos2) / pow(abs(1.0 + g2 - 2.0*g*fCos), 1.5);
|
||||
|
||||
vec4 color = rayleighColor + fMiePhase * mieColor;
|
||||
color.a = color.b;
|
||||
|
||||
vec4 nightSkyColor = textureCube(nightSky, -v3Direction);
|
||||
nightSkyColor = mix(nightColor, nightSkyColor, useCubemap);
|
||||
|
||||
float fac = dot( normalize( pos ), sunDir );
|
||||
fac = max( nightInterpAndExposure.y, pow( clamp( fac, 0.0, 1.0 ), 2 ) );
|
||||
gl_FragColor = mix( color, nightSkyColor, nightInterpAndExposure.y );
|
||||
|
||||
// Clip based on the camera-relative
|
||||
// z position of the vertex, passed through
|
||||
// from the vertex position.
|
||||
if(zPosition < 0.0)
|
||||
discard;
|
||||
|
||||
gl_FragColor.a = 1;
|
||||
gl_FragColor = hdrEncode( gl_FragColor );
|
||||
}
|
||||
165
Templates/Empty/game/shaders/common/gl/scatterSkyV.glsl
Normal file
165
Templates/Empty/game/shaders/common/gl/scatterSkyV.glsl
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const int nSamples = 4;
|
||||
const float fSamples = 4.0;
|
||||
|
||||
// The scale depth (the altitude at which the average atmospheric density is found)
|
||||
const float fScaleDepth = 0.25;
|
||||
const float fInvScaleDepth = 1.0 / 0.25;
|
||||
|
||||
// The scale equation calculated by Vernier's Graphical Analysis
|
||||
float vernierScale(float fCos)
|
||||
{
|
||||
float x = 1.0 - fCos;
|
||||
float x5 = x * 5.25;
|
||||
float x5p6 = (-6.80 + x5);
|
||||
float xnew = (3.83 + x * x5p6);
|
||||
float xfinal = (0.459 + x * xnew);
|
||||
float xfinal2 = -0.00287 + x * xfinal;
|
||||
float outx = exp( xfinal2 );
|
||||
return 0.25 * outx;
|
||||
}
|
||||
|
||||
// This is the shader output data.
|
||||
varying vec4 rayleighColor;
|
||||
varying vec4 mieColor;
|
||||
varying vec3 v3Direction;
|
||||
varying float zPosition;
|
||||
varying vec3 pos;
|
||||
|
||||
uniform mat4 modelView;
|
||||
uniform vec4 misc;
|
||||
uniform vec4 sphereRadii;
|
||||
uniform vec4 scatteringCoeffs;
|
||||
uniform vec3 camPos;
|
||||
uniform vec3 lightDir;
|
||||
uniform vec4 invWaveLength;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = gl_Vertex.xyzw;
|
||||
vec3 normal = gl_Normal.xyz;
|
||||
vec4 color = gl_MultiTexCoord0.xyzw;
|
||||
|
||||
// Pull some variables out:
|
||||
float camHeight = misc.x;
|
||||
float camHeightSqr = misc.y;
|
||||
|
||||
float scale = misc.z;
|
||||
float scaleOverScaleDepth = misc.w;
|
||||
|
||||
float outerRadius = sphereRadii.x;
|
||||
float outerRadiusSqr = sphereRadii.y;
|
||||
|
||||
float innerRadius = sphereRadii.z;
|
||||
float innerRadiusSqr = sphereRadii.w;
|
||||
|
||||
float rayleighBrightness = scatteringCoeffs.x; // Kr * ESun
|
||||
float rayleigh4PI = scatteringCoeffs.y; // Kr * 4 * PI
|
||||
|
||||
float mieBrightness = scatteringCoeffs.z; // Km * ESun
|
||||
float mie4PI = scatteringCoeffs.w; // Km * 4 * PI
|
||||
|
||||
// Get the ray from the camera to the vertex,
|
||||
// and its length (which is the far point of the ray
|
||||
// passing through the atmosphere).
|
||||
vec3 v3Pos = position.xyz / 6378000.0;// / outerRadius;
|
||||
vec3 newCamPos = vec3( 0, 0, camHeight );
|
||||
v3Pos.z += innerRadius;
|
||||
vec3 v3Ray = v3Pos.xyz - newCamPos;
|
||||
float fFar = length(v3Ray);
|
||||
v3Ray /= fFar;
|
||||
|
||||
// Calculate the ray's starting position,
|
||||
// then calculate its scattering offset.
|
||||
vec3 v3Start = newCamPos;
|
||||
float fHeight = length(v3Start);
|
||||
float fDepth = exp(scaleOverScaleDepth * (innerRadius - camHeight));
|
||||
float fStartAngle = dot(v3Ray, v3Start) / fHeight;
|
||||
|
||||
float x = 1.0 - fStartAngle;
|
||||
float x5 = x * 5.25;
|
||||
float x5p6 = (-6.80 + x5);
|
||||
float xnew = (3.83 + x * x5p6);
|
||||
float xfinal = (0.459 + x * xnew);
|
||||
float xfinal2 = -0.00287 + x * xfinal;
|
||||
float othx = exp( xfinal2 );
|
||||
float vscale1 = 0.25 * othx;
|
||||
|
||||
float fStartOffset = fDepth * vscale1;//vernierScale(fStartAngle);
|
||||
|
||||
// Initialize the scattering loop variables.
|
||||
float fSampleLength = fFar / 2.0;
|
||||
float fScaledLength = fSampleLength * scale;
|
||||
vec3 v3SampleRay = v3Ray * fSampleLength;
|
||||
vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
|
||||
|
||||
// Now loop through the sample rays
|
||||
vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);
|
||||
for(int i=0; i<2; i++)
|
||||
{
|
||||
float fHeight = length(v3SamplePoint);
|
||||
float fDepth = exp(scaleOverScaleDepth * (innerRadius - fHeight));
|
||||
float fLightAngle = dot(lightDir, v3SamplePoint) / fHeight;
|
||||
float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;
|
||||
|
||||
x = 1.0 - fCameraAngle;
|
||||
x5 = x * 5.25;
|
||||
x5p6 = (-6.80 + x5);
|
||||
xnew = (3.83 + x * x5p6);
|
||||
xfinal = (0.459 + x * xnew);
|
||||
xfinal2 = -0.00287 + x * xfinal;
|
||||
othx = exp( xfinal2 );
|
||||
float vscale3 = 0.25 * othx;
|
||||
|
||||
|
||||
x = 1.0 - fLightAngle;
|
||||
x5 = x * 5.25;
|
||||
x5p6 = (-6.80 + x5);
|
||||
xnew = (3.83 + x * x5p6);
|
||||
xfinal = (0.459 + x * xnew);
|
||||
xfinal2 = -0.00287 + x * xfinal;
|
||||
othx = exp( xfinal2 );
|
||||
float vscale2 = 0.25 * othx;
|
||||
|
||||
float fScatter = (fStartOffset + fDepth*(vscale2 - vscale3));
|
||||
vec3 v3Attenuate = exp(-fScatter * (invWaveLength.xyz * rayleigh4PI + mie4PI));
|
||||
v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
|
||||
v3SamplePoint += v3SampleRay;
|
||||
}
|
||||
|
||||
// Finally, scale the Mie and Rayleigh colors
|
||||
// and set up the varying variables for the pixel shader.
|
||||
gl_Position = modelView * position;
|
||||
mieColor.rgb = v3FrontColor * mieBrightness;
|
||||
mieColor.a = 1.0;
|
||||
rayleighColor.rgb = v3FrontColor * (invWaveLength.xyz * rayleighBrightness);
|
||||
rayleighColor.a = 1.0;
|
||||
v3Direction = newCamPos - v3Pos.xyz;
|
||||
|
||||
// This offset is to get rid of the black line between the atmosky and the waterPlane
|
||||
// along the horizon.
|
||||
zPosition = position.z + 4000.0;
|
||||
pos = position.xyz;
|
||||
}
|
||||
|
||||
246
Templates/Empty/game/shaders/common/gl/torque.glsl
Normal file
246
Templates/Empty/game/shaders/common/gl/torque.glsl
Normal file
|
|
@ -0,0 +1,246 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TORQUE_GLSL_
|
||||
#define _TORQUE_GLSL_
|
||||
|
||||
|
||||
float M_HALFPI_F = 1.57079632679489661923;
|
||||
float M_PI_F = 3.14159265358979323846;
|
||||
float M_2PI_F = 6.28318530717958647692;
|
||||
|
||||
/// Calculate fog based on a start and end positions in worldSpace.
|
||||
float computeSceneFog( vec3 startPos,
|
||||
vec3 endPos,
|
||||
float fogDensity,
|
||||
float fogDensityOffset,
|
||||
float fogHeightFalloff )
|
||||
{
|
||||
float f = length( startPos - endPos ) - fogDensityOffset;
|
||||
float h = 1.0 - ( endPos.z * fogHeightFalloff );
|
||||
return exp( -fogDensity * f * h );
|
||||
}
|
||||
|
||||
|
||||
/// Calculate fog based on a start and end position and a height.
|
||||
/// Positions do not need to be in worldSpace but height does.
|
||||
float computeSceneFog( vec3 startPos,
|
||||
vec3 endPos,
|
||||
float height,
|
||||
float fogDensity,
|
||||
float fogDensityOffset,
|
||||
float fogHeightFalloff )
|
||||
{
|
||||
float f = length( startPos - endPos ) - fogDensityOffset;
|
||||
float h = 1.0 - ( height * fogHeightFalloff );
|
||||
return exp( -fogDensity * f * h );
|
||||
}
|
||||
|
||||
|
||||
/// Calculate fog based on a distance, height is not used.
|
||||
float computeSceneFog( float dist, float fogDensity, float fogDensityOffset )
|
||||
{
|
||||
float f = dist - fogDensityOffset;
|
||||
return exp( -fogDensity * f );
|
||||
}
|
||||
|
||||
|
||||
/// Convert a vec4 uv in viewport space to render target space.
|
||||
vec2 viewportCoordToRenderTarget( vec4 inCoord, vec4 rtParams )
|
||||
{
|
||||
vec2 outCoord = inCoord.xy / inCoord.w;
|
||||
outCoord = ( outCoord * rtParams.zw ) + rtParams.xy;
|
||||
return outCoord;
|
||||
}
|
||||
|
||||
|
||||
/// Convert a vec2 uv in viewport space to render target space.
|
||||
vec2 viewportCoordToRenderTarget( vec2 inCoord, vec4 rtParams )
|
||||
{
|
||||
vec2 outCoord = ( inCoord * rtParams.zw ) + rtParams.xy;
|
||||
return outCoord;
|
||||
}
|
||||
|
||||
|
||||
/// Convert a vec4 quaternion into a 3x3 matrix.
|
||||
mat3x3 quatToMat( vec4 quat )
|
||||
{
|
||||
float xs = quat.x * 2.0;
|
||||
float ys = quat.y * 2.0;
|
||||
float zs = quat.z * 2.0;
|
||||
|
||||
float wx = quat.w * xs;
|
||||
float wy = quat.w * ys;
|
||||
float wz = quat.w * zs;
|
||||
|
||||
float xx = quat.x * xs;
|
||||
float xy = quat.x * ys;
|
||||
float xz = quat.x * zs;
|
||||
|
||||
float yy = quat.y * ys;
|
||||
float yz = quat.y * zs;
|
||||
float zz = quat.z * zs;
|
||||
|
||||
mat3x3 mat;
|
||||
|
||||
mat[0][0] = 1.0 - (yy + zz);
|
||||
mat[1][0] = xy - wz;
|
||||
mat[2][0] = xz + wy;
|
||||
|
||||
mat[0][1] = xy + wz;
|
||||
mat[1][1] = 1.0 - (xx + zz);
|
||||
mat[2][1] = yz - wx;
|
||||
|
||||
mat[0][2] = xz - wy;
|
||||
mat[1][2] = yz + wx;
|
||||
mat[2][2] = 1.0 - (xx + yy);
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
/// The number of additional substeps we take when refining
|
||||
/// the results of the offset parallax mapping function below.
|
||||
///
|
||||
/// You should turn down the number of steps if your needing
|
||||
/// more performance out of your parallax surfaces. Increasing
|
||||
/// the number doesn't yeild much better results and is rarely
|
||||
/// worth the additional cost.
|
||||
///
|
||||
#define PARALLAX_REFINE_STEPS 3
|
||||
|
||||
/// Performs fast parallax offset mapping using
|
||||
/// multiple refinement steps.
|
||||
////// @param texMap The texture map whos alpha channel we sample the parallax depth.
|
||||
/// @param texCoord The incoming texture coordinate for sampling the parallax depth.
|
||||
/// @param negViewTS The negative view vector in tangent space.
|
||||
/// @param depthScale The parallax factor used to scale the depth result.
|
||||
///
|
||||
vec2 parallaxOffset( sampler2D texMap, vec2 texCoord, vec3 negViewTS, float depthScale )
|
||||
{
|
||||
float depth = texture2D( texMap, texCoord ).a;
|
||||
vec2 offset = negViewTS.xy * ( depth * depthScale );
|
||||
|
||||
for ( int i=0; i < PARALLAX_REFINE_STEPS; i++ )
|
||||
{
|
||||
depth = ( depth + texture2D( texMap, texCoord + offset ).a ) * 0.5;
|
||||
offset = negViewTS.xy * ( depth * depthScale );
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
/// The maximum value for 16bit per component integer HDR encoding.
|
||||
const float HDR_RGB16_MAX = 100.0;
|
||||
/// The maximum value for 10bit per component integer HDR encoding.const float HDR_RGB10_MAX = 4.0;
|
||||
|
||||
/// Encodes an HDR color for storage into a target.
|
||||
vec3 hdrEncode( vec3 sample ){
|
||||
#if defined( TORQUE_HDR_RGB16 )
|
||||
|
||||
return sample / HDR_RGB16_MAX;
|
||||
|
||||
#elif defined( TORQUE_HDR_RGB10 )
|
||||
|
||||
return sample / HDR_RGB10_MAX;
|
||||
|
||||
#else
|
||||
|
||||
// No encoding.
|
||||
return sample;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Encodes an HDR color for storage into a target.
|
||||
vec4 hdrEncode( vec4 sample )
|
||||
{
|
||||
return vec4( hdrEncode( sample.rgb ), sample.a );
|
||||
}
|
||||
|
||||
/// Decodes an HDR color from a target.
|
||||
vec3 hdrDecode( vec3 sample )
|
||||
{
|
||||
#if defined( TORQUE_HDR_RGB16 )
|
||||
|
||||
return sample * HDR_RGB16_MAX;
|
||||
|
||||
#elif defined( TORQUE_HDR_RGB10 )
|
||||
|
||||
return sample * HDR_RGB10_MAX;
|
||||
|
||||
#else
|
||||
|
||||
// No encoding.
|
||||
return sample;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Decodes an HDR color from a target.
|
||||
vec4 hdrDecode( vec4 sample )
|
||||
{
|
||||
return vec4( hdrDecode( sample.rgb ), sample.a );
|
||||
}
|
||||
|
||||
/// Returns the luminance for an HDR pixel.
|
||||
float hdrLuminance( vec3 sample )
|
||||
{
|
||||
// There are quite a few different ways to
|
||||
// calculate luminance from an rgb value.
|
||||
//
|
||||
// If you want to use a different technique
|
||||
// then plug it in here.
|
||||
//
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Max component luminance.
|
||||
//
|
||||
//float lum = max( sample.r, max( sample.g, sample.b ) );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// The perceptual relative luminance.
|
||||
//
|
||||
// See http://en.wikipedia.org/wiki/Luminance_(relative)
|
||||
//
|
||||
const vec3 RELATIVE_LUMINANCE = vec3( 0.2126, 0.7152, 0.0722 );
|
||||
float lum = dot( sample, RELATIVE_LUMINANCE );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// The average component luminance.
|
||||
//
|
||||
//const vec3 AVERAGE_LUMINANCE = vec3( 0.3333, 0.3333, 0.3333 );
|
||||
//float lum = dot( sample, AVERAGE_LUMINANCE );
|
||||
|
||||
return lum;
|
||||
}
|
||||
|
||||
|
||||
/// Basic assert macro. If the condition fails, then the shader will output color.
|
||||
/// @param condition This should be a bvec[2-4]. If any items is false, condition is considered to fail.
|
||||
/// @param color The color that should be outputted if the condition fails.
|
||||
/// @note This macro will only work in the void main() method of a pixel shader.
|
||||
#define assert(condition, color) { if(!any(condition)) { gl_FragColor = color; return; } }
|
||||
|
||||
#endif // _TORQUE_GLSL_
|
||||
55
Templates/Empty/game/shaders/common/gl/wavesP.glsl
Normal file
55
Templates/Empty/game/shaders/common/gl/wavesP.glsl
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform sampler2D diffMap;
|
||||
uniform sampler2D bumpMap;
|
||||
uniform samplerCube cubeMap;
|
||||
uniform vec4 specularColor;
|
||||
uniform float specularPower;
|
||||
uniform vec4 ambient;
|
||||
uniform float accumTime;
|
||||
|
||||
varying vec2 TEX0;
|
||||
varying vec4 outLightVec;
|
||||
varying vec3 outPos;
|
||||
varying vec3 outEyePos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texOffset;
|
||||
float sinOffset1 = sin( accumTime * 1.5 + TEX0.y * 6.28319 * 3.0 ) * 0.03;
|
||||
float sinOffset2 = sin( accumTime * 3.0 + TEX0.y * 6.28319 ) * 0.04;
|
||||
|
||||
texOffset.x = TEX0.x + sinOffset1 + sinOffset2;
|
||||
texOffset.y = TEX0.y + cos( accumTime * 3.0 + TEX0.x * 6.28319 * 2.0 ) * 0.05;
|
||||
|
||||
vec4 bumpNorm = texture2D(bumpMap, texOffset) * 2.0 - 1.0;
|
||||
vec4 diffuse = texture2D(diffMap, texOffset);
|
||||
|
||||
gl_FragColor = diffuse * (clamp(dot(outLightVec.xyz, bumpNorm.xyz), 0.0, 1.0) + ambient);
|
||||
|
||||
vec3 eyeVec = normalize(outEyePos - outPos);
|
||||
vec3 halfAng = normalize(eyeVec + outLightVec.xyz);
|
||||
float specular = clamp(dot(bumpNorm.xyz, halfAng), 0.0, 1.0) * outLightVec.w;
|
||||
specular = pow(specular, specularPower);
|
||||
gl_FragColor += specularColor * specular;
|
||||
}
|
||||
101
Templates/Empty/game/shaders/common/gl/wind.glsl
Normal file
101
Templates/Empty/game/shaders/common/gl/wind.glsl
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// A tip of the hat....
|
||||
//
|
||||
// The following wind effects were derived from the GPU Gems
|
||||
// 3 chapter "Vegetation Procedural Animation and Shading in Crysis"
|
||||
// by Tiago Sousa of Crytek.
|
||||
//
|
||||
|
||||
vec4 smoothCurve( vec4 x )
|
||||
{
|
||||
return x * x * ( 3.0 - 2.0 * x );
|
||||
}
|
||||
|
||||
vec4 triangleWave( vec4 x )
|
||||
{
|
||||
return abs( fract( x + 0.5 ) * 2.0 - 1.0 );
|
||||
}
|
||||
|
||||
vec4 smoothTriangleWave( vec4 x )
|
||||
{
|
||||
return smoothCurve( triangleWave( x ) );
|
||||
}
|
||||
|
||||
vec3 windTrunkBending( vec3 vPos, vec2 vWind, float fBendFactor )
|
||||
{
|
||||
// Smooth the bending factor and increase
|
||||
// the near by height limit.
|
||||
fBendFactor += 1.0;
|
||||
fBendFactor *= fBendFactor;
|
||||
fBendFactor = fBendFactor * fBendFactor - fBendFactor;
|
||||
|
||||
// Displace the vert.
|
||||
vec3 vNewPos = vPos;
|
||||
vNewPos.xy += vWind * fBendFactor;
|
||||
|
||||
// Limit the length which makes the bend more
|
||||
// spherical and prevents stretching.
|
||||
float fLength = length( vPos );
|
||||
vPos = normalize( vNewPos ) * fLength;
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
vec3 windBranchBending( vec3 vPos,
|
||||
vec3 vNormal,
|
||||
|
||||
float fTime,
|
||||
float fWindSpeed,
|
||||
|
||||
float fBranchPhase,
|
||||
float fBranchAmp,
|
||||
float fBranchAtten,
|
||||
|
||||
float fDetailPhase,
|
||||
float fDetailAmp,
|
||||
float fDetailFreq,
|
||||
|
||||
float fEdgeAtten )
|
||||
{
|
||||
float fVertPhase = dot( vPos, vec3( fDetailPhase + fBranchPhase ) );
|
||||
|
||||
vec2 vWavesIn = fTime + vec2( fVertPhase, fBranchPhase );
|
||||
|
||||
vec4 vWaves = ( fract( vWavesIn.xxyy *
|
||||
vec4( 1.975, 0.793, 0.375, 0.193 ) ) *
|
||||
2.0 - 1.0 ) * fWindSpeed * fDetailFreq;
|
||||
|
||||
vWaves = smoothTriangleWave( vWaves );
|
||||
|
||||
vec2 vWavesSum = vWaves.xz + vWaves.yw;
|
||||
|
||||
// We want the branches to bend both up and down.
|
||||
vWavesSum.y = 1.0 - ( vWavesSum.y * 2.0 );
|
||||
|
||||
vPos += vWavesSum.xxy * vec3( fEdgeAtten * fDetailAmp * vNormal.xy,
|
||||
fBranchAtten * fBranchAmp );
|
||||
|
||||
return vPos;
|
||||
}
|
||||
43
Templates/Empty/game/shaders/common/guiMaterialV.hlsl
Normal file
43
Templates/Empty/game/shaders/common/guiMaterialV.hlsl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hlslStructs.h"
|
||||
|
||||
struct MaterialDecoratorConnectV
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
MaterialDecoratorConnectV main( VertexIn_PCT IN,
|
||||
uniform float4x4 modelview : register(C0) )
|
||||
{
|
||||
MaterialDecoratorConnectV OUT;
|
||||
|
||||
OUT.hpos = mul(modelview, IN.pos);
|
||||
OUT.uv0 = IN.uv0;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
108
Templates/Empty/game/shaders/common/hlslStructs.h
Normal file
108
Templates/Empty/game/shaders/common/hlslStructs.h
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// The purpose of this file is to get all of our HLSL structures into one place.
|
||||
// Please use the structures here instead of redefining input and output structures
|
||||
// in each shader file. If structures are added, please adhere to the naming convention.
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Vertex Input Structures
|
||||
//
|
||||
// These structures map to FVFs/Vertex Declarations in Torque. See gfxStructs.h
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Notes
|
||||
//
|
||||
// Position should be specified as a float4. Right now our vertex structures in
|
||||
// the engine output float3s for position. This does NOT mean that the POSITION
|
||||
// binding should be float3, because it will assign 0 to the w coordinate, which
|
||||
// results in the vertex not getting translated when it is transformed.
|
||||
|
||||
struct VertexIn_P
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
};
|
||||
|
||||
struct VertexIn_PT
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VertexIn_PTTT
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
float2 uv1 : TEXCOORD1;
|
||||
float2 uv2 : TEXCOORD2;
|
||||
};
|
||||
|
||||
struct VertexIn_PC
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float4 color : DIFFUSE;
|
||||
};
|
||||
|
||||
struct VertexIn_PNC
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float4 color : DIFFUSE;
|
||||
};
|
||||
|
||||
struct VertexIn_PCT
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float4 color : DIFFUSE;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VertexIn_PN
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
};
|
||||
|
||||
struct VertexIn_PNT
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VertexIn_PNCT
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float4 color : DIFFUSE;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VertexIn_PNTTTB
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
float2 uv1 : TEXCOORD1;
|
||||
float3 T : TEXCOORD2;
|
||||
float3 B : TEXCOORD3;
|
||||
};
|
||||
149
Templates/Empty/game/shaders/common/imposter.hlsl
Normal file
149
Templates/Empty/game/shaders/common/imposter.hlsl
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "torque.hlsl"
|
||||
|
||||
|
||||
static float sCornerRight[4] = { -1, 1, 1, -1 };
|
||||
static float sCornerUp[4] = { -1, -1, 1, 1 };
|
||||
static float2 sUVCornerExtent[4] =
|
||||
{
|
||||
float2( 0, 1 ),
|
||||
float2( 1, 1 ),
|
||||
float2( 1, 0 ),
|
||||
float2( 0, 0 )
|
||||
};
|
||||
|
||||
#define IMPOSTER_MAX_UVS 64
|
||||
|
||||
|
||||
void imposter_v(
|
||||
// These parameters usually come from the vertex.
|
||||
float3 center,
|
||||
int corner,
|
||||
float halfSize,
|
||||
float3 imposterUp,
|
||||
float3 imposterRight,
|
||||
|
||||
// These are from the imposter shader constant.
|
||||
int numEquatorSteps,
|
||||
int numPolarSteps,
|
||||
float polarAngle,
|
||||
bool includePoles,
|
||||
|
||||
// Other shader constants.
|
||||
float3 camPos,
|
||||
float4 uvs[IMPOSTER_MAX_UVS],
|
||||
|
||||
// The outputs of this function.
|
||||
out float3 outWsPosition,
|
||||
out float2 outTexCoord,
|
||||
out float3x3 outWorldToTangent
|
||||
)
|
||||
{
|
||||
// TODO: This could all be calculated on the CPU.
|
||||
float equatorStepSize = M_2PI_F / numEquatorSteps;
|
||||
float equatorHalfStep = ( equatorStepSize / 2.0 ) - 0.0001;
|
||||
float polarStepSize = M_PI_F / numPolarSteps;
|
||||
float polarHalfStep = ( polarStepSize / 2.0 ) - 0.0001;
|
||||
|
||||
// The vector between the camera and the billboard.
|
||||
float3 lookVec = normalize( camPos - center );
|
||||
|
||||
// Generate the camera up and right vectors from
|
||||
// the object transform and camera forward.
|
||||
float3 camUp = imposterUp;
|
||||
float3 camRight = normalize( cross( -lookVec, camUp ) );
|
||||
|
||||
// The billboarding is based on the camera directions.
|
||||
float3 rightVec = camRight * sCornerRight[corner];
|
||||
float3 upVec = camUp * sCornerUp[corner];
|
||||
|
||||
float lookPitch = acos( dot( imposterUp, lookVec ) );
|
||||
|
||||
// First check to see if we need to render the top billboard.
|
||||
int index;
|
||||
/*
|
||||
if ( includePoles && ( lookPitch < polarAngle || lookPitch > sPi - polarAngle ) )
|
||||
{
|
||||
index = numEquatorSteps * 3;
|
||||
|
||||
// When we render the top/bottom billboard we always use
|
||||
// a fixed vector that matches the rotation of the object.
|
||||
rightVec = float3( 1, 0, 0 ) * sCornerRight[corner];
|
||||
upVec = float3( 0, 1, 0 ) * sCornerUp[corner];
|
||||
|
||||
if ( lookPitch > sPi - polarAngle )
|
||||
{
|
||||
upVec = -upVec;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
else
|
||||
*/
|
||||
{
|
||||
// Calculate the rotation around the z axis then add the
|
||||
// equator half step. This gets the images to switch a
|
||||
// half step before the captured angle is met.
|
||||
float lookAzimuth = atan2( lookVec.y, lookVec.x );
|
||||
float azimuth = atan2( imposterRight.y, imposterRight.x );
|
||||
float rotZ = ( lookAzimuth - azimuth ) + equatorHalfStep;
|
||||
|
||||
// The y rotation is calculated from the look vector and
|
||||
// the object up vector.
|
||||
float rotY = lookPitch - polarHalfStep;
|
||||
|
||||
// TODO: How can we do this without conditionals?
|
||||
// Normalize the result to 0 to 2PI.
|
||||
if ( rotZ < 0 )
|
||||
rotZ += M_2PI_F;
|
||||
if ( rotZ > M_2PI_F )
|
||||
rotZ -= M_2PI_F;
|
||||
if ( rotY < 0 )
|
||||
rotY += M_2PI_F;
|
||||
if ( rotY > M_PI_F ) // Not M_2PI_F?
|
||||
rotY -= M_2PI_F;
|
||||
|
||||
float polarIdx = round( abs( rotY ) / polarStepSize );
|
||||
|
||||
// Get the index to the start of the right polar
|
||||
// images for this viewing angle.
|
||||
int numPolarOffset = numEquatorSteps * polarIdx;
|
||||
|
||||
// Calculate the final image index for lookup
|
||||
// of the texture coords.
|
||||
index = ( rotZ / equatorStepSize ) + numPolarOffset;
|
||||
}
|
||||
|
||||
// Generate the final world space position.
|
||||
outWsPosition = center + ( upVec * halfSize ) + ( rightVec * halfSize );
|
||||
|
||||
// Grab the uv set and setup the texture coord.
|
||||
float4 uvSet = uvs[index];
|
||||
outTexCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
|
||||
outTexCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
|
||||
|
||||
// Needed for normal mapping and lighting.
|
||||
outWorldToTangent[0] = float3( 1, 0, 0 );
|
||||
outWorldToTangent[1] = float3( 0, 1, 0 );
|
||||
outWorldToTangent[2] = float3( 0, 0, -1 );
|
||||
}
|
||||
219
Templates/Empty/game/shaders/common/lighting.hlsl
Normal file
219
Templates/Empty/game/shaders/common/lighting.hlsl
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#ifndef TORQUE_SHADERGEN
|
||||
|
||||
// These are the uniforms used by most lighting shaders.
|
||||
|
||||
uniform float4 inLightPos[3];
|
||||
uniform float4 inLightInvRadiusSq;
|
||||
uniform float4 inLightColor[4];
|
||||
|
||||
#ifndef TORQUE_BL_NOSPOTLIGHT
|
||||
uniform float4 inLightSpotDir[3];
|
||||
uniform float4 inLightSpotAngle;
|
||||
uniform float4 inLightSpotFalloff;
|
||||
#endif
|
||||
|
||||
uniform float4 ambient;
|
||||
uniform float specularPower;
|
||||
uniform float4 specularColor;
|
||||
|
||||
#endif // !TORQUE_SHADERGEN
|
||||
|
||||
|
||||
void compute4Lights( float3 wsView,
|
||||
float3 wsPosition,
|
||||
float3 wsNormal,
|
||||
float4 shadowMask,
|
||||
|
||||
#ifdef TORQUE_SHADERGEN
|
||||
|
||||
float4 inLightPos[3],
|
||||
float4 inLightInvRadiusSq,
|
||||
float4 inLightColor[4],
|
||||
float4 inLightSpotDir[3],
|
||||
float4 inLightSpotAngle,
|
||||
float4 inLightSpotFalloff,
|
||||
float specularPower,
|
||||
float4 specularColor,
|
||||
|
||||
#endif // TORQUE_SHADERGEN
|
||||
|
||||
out float4 outDiffuse,
|
||||
out float4 outSpecular )
|
||||
{
|
||||
// NOTE: The light positions and spotlight directions
|
||||
// are stored in SoA order, so inLightPos[0] is the
|
||||
// x coord for all 4 lights... inLightPos[1] is y... etc.
|
||||
//
|
||||
// This is the key to fully utilizing the vector units and
|
||||
// saving a huge amount of instructions.
|
||||
//
|
||||
// For example this change saved more than 10 instructions
|
||||
// over a simple for loop for each light.
|
||||
|
||||
int i;
|
||||
|
||||
float4 lightVectors[3];
|
||||
for ( i = 0; i < 3; i++ )
|
||||
lightVectors[i] = wsPosition[i] - inLightPos[i];
|
||||
|
||||
float4 squareDists = 0;
|
||||
for ( i = 0; i < 3; i++ )
|
||||
squareDists += lightVectors[i] * lightVectors[i];
|
||||
|
||||
// Accumulate the dot product between the light
|
||||
// vector and the normal.
|
||||
//
|
||||
// The normal is negated because it faces away from
|
||||
// the surface and the light faces towards the
|
||||
// surface... this keeps us from needing to flip
|
||||
// the light vector direction which complicates
|
||||
// the spot light calculations.
|
||||
//
|
||||
// We normalize the result a little later.
|
||||
//
|
||||
float4 nDotL = 0;
|
||||
for ( i = 0; i < 3; i++ )
|
||||
nDotL += lightVectors[i] * -wsNormal[i];
|
||||
|
||||
float4 rDotL = 0;
|
||||
#ifndef TORQUE_BL_NOSPECULAR
|
||||
|
||||
// We're using the Phong specular reflection model
|
||||
// here where traditionally Torque has used Blinn-Phong
|
||||
// which has proven to be more accurate to real materials.
|
||||
//
|
||||
// We do so because its cheaper as do not need to
|
||||
// calculate the half angle for all 4 lights.
|
||||
//
|
||||
// Advanced Lighting still uses Blinn-Phong, but the
|
||||
// specular reconstruction it does looks fairly similar
|
||||
// to this.
|
||||
//
|
||||
float3 R = reflect( wsView, -wsNormal );
|
||||
|
||||
for ( i = 0; i < 3; i++ )
|
||||
rDotL += lightVectors[i] * R[i];
|
||||
|
||||
#endif
|
||||
|
||||
// Normalize the dots.
|
||||
//
|
||||
// Notice we're using the half type here to get a
|
||||
// much faster sqrt via the rsq_pp instruction at
|
||||
// the loss of some precision.
|
||||
//
|
||||
// Unless we have some extremely large point lights
|
||||
// i don't believe the precision loss will matter.
|
||||
//
|
||||
half4 correction = (half4)rsqrt( squareDists );
|
||||
nDotL = saturate( nDotL * correction );
|
||||
rDotL = clamp( rDotL * correction, 0.00001, 1.0 );
|
||||
|
||||
// First calculate a simple point light linear
|
||||
// attenuation factor.
|
||||
//
|
||||
// If this is a directional light the inverse
|
||||
// radius should be greater than the distance
|
||||
// causing the attenuation to have no affect.
|
||||
//
|
||||
float4 atten = saturate( 1.0 - ( squareDists * inLightInvRadiusSq ) );
|
||||
|
||||
#ifndef TORQUE_BL_NOSPOTLIGHT
|
||||
|
||||
// The spotlight attenuation factor. This is really
|
||||
// fast for what it does... 6 instructions for 4 spots.
|
||||
|
||||
float4 spotAtten = 0;
|
||||
for ( i = 0; i < 3; i++ )
|
||||
spotAtten += lightVectors[i] * inLightSpotDir[i];
|
||||
|
||||
float4 cosAngle = ( spotAtten * correction ) - inLightSpotAngle;
|
||||
atten *= saturate( cosAngle * inLightSpotFalloff );
|
||||
|
||||
#endif
|
||||
|
||||
// Finally apply the shadow masking on the attenuation.
|
||||
atten *= shadowMask;
|
||||
|
||||
// Get the final light intensity.
|
||||
float4 intensity = nDotL * atten;
|
||||
|
||||
// Combine the light colors for output.
|
||||
outDiffuse = 0;
|
||||
for ( i = 0; i < 4; i++ )
|
||||
outDiffuse += intensity[i] * inLightColor[i];
|
||||
|
||||
// Output the specular power.
|
||||
float4 specularIntensity = pow( rDotL, specularPower.xxxx ) * atten;
|
||||
|
||||
// Apply the per-light specular attenuation.
|
||||
float4 specular = float4(0,0,0,1);
|
||||
for ( i = 0; i < 4; i++ )
|
||||
specular += float4( inLightColor[i].rgb * inLightColor[i].a * specularIntensity[i], 1 );
|
||||
|
||||
// Add the final specular intensity values together
|
||||
// using a single dot product operation then get the
|
||||
// final specular lighting color.
|
||||
outSpecular = specularColor * specular;
|
||||
}
|
||||
|
||||
|
||||
// This value is used in AL as a constant power to raise specular values
|
||||
// to, before storing them into the light info buffer. The per-material
|
||||
// specular value is then computer by using the integer identity of
|
||||
// exponentiation:
|
||||
//
|
||||
// (a^m)^n = a^(m*n)
|
||||
//
|
||||
// or
|
||||
//
|
||||
// (specular^constSpecular)^(matSpecular/constSpecular) = specular^(matSpecular*constSpecular)
|
||||
//
|
||||
#define AL_ConstantSpecularPower 12.0f
|
||||
|
||||
/// The specular calculation used in Advanced Lighting.
|
||||
///
|
||||
/// @param toLight Normalized vector representing direction from the pixel
|
||||
/// being lit, to the light source, in world space.
|
||||
///
|
||||
/// @param normal Normalized surface normal.
|
||||
///
|
||||
/// @param toEye The normalized vector representing direction from the pixel
|
||||
/// being lit to the camera.
|
||||
///
|
||||
float AL_CalcSpecular( float3 toLight, float3 normal, float3 toEye )
|
||||
{
|
||||
#ifdef PHONG_SPECULAR
|
||||
// (R.V)^c
|
||||
float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye );
|
||||
#else
|
||||
// (N.H)^c [Blinn-Phong, TGEA style, default]
|
||||
float specVal = dot( normal, normalize( toLight + toEye ) );
|
||||
#endif
|
||||
|
||||
// Return the specular factor.
|
||||
return pow( max( specVal, 0.00001f ), AL_ConstantSpecularPower );
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../hlslStructs.h"
|
||||
|
||||
struct ConvexConnectV
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float4 wsEyeDir : TEXCOORD0;
|
||||
float4 ssPos : TEXCOORD1;
|
||||
float4 vsEyeDir : TEXCOORD2;
|
||||
};
|
||||
|
||||
ConvexConnectV main( VertexIn_P IN,
|
||||
uniform float4x4 modelview,
|
||||
uniform float4x4 objTrans,
|
||||
uniform float4x4 worldViewOnly,
|
||||
uniform float3 eyePosWorld )
|
||||
{
|
||||
ConvexConnectV OUT;
|
||||
|
||||
OUT.hpos = mul( modelview, IN.pos );
|
||||
OUT.wsEyeDir = mul( objTrans, IN.pos ) - float4( eyePosWorld, 0.0 );
|
||||
OUT.vsEyeDir = mul( worldViewOnly, IN.pos );
|
||||
OUT.ssPos = OUT.hpos;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
#include "../../postfx/postFx.hlsl"
|
||||
|
||||
|
||||
float4 main( PFXVertToPix IN,
|
||||
uniform sampler2D prepassTex : register(S0),
|
||||
uniform sampler1D depthViz : register(S1) ) : COLOR0
|
||||
{
|
||||
float depth = prepassUncondition( prepassTex, IN.uv0 ).w;
|
||||
return float4( tex1D( depthViz, depth ).rgb, 1.0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
#include "../../postfx/postFx.hlsl"
|
||||
|
||||
|
||||
float4 main( PFXVertToPix IN,
|
||||
uniform sampler2D lightPrePassTex : register(S0) ) : COLOR0
|
||||
{
|
||||
float3 lightcolor;
|
||||
float nl_Att, specular;
|
||||
lightinfoUncondition( tex2D( lightPrePassTex, IN.uv0 ), lightcolor, nl_Att, specular );
|
||||
return float4( lightcolor, 1.0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
#include "../../postfx/postFx.hlsl"
|
||||
|
||||
|
||||
float4 main( PFXVertToPix IN,
|
||||
uniform sampler2D lightPrePassTex : register(S0) ) : COLOR0
|
||||
{
|
||||
float3 lightcolor;
|
||||
float nl_Att, specular;
|
||||
lightinfoUncondition( tex2D( lightPrePassTex, IN.uv0 ), lightcolor, nl_Att, specular );
|
||||
return float4( specular, specular, specular, 1.0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
#include "../../postfx/postFx.hlsl"
|
||||
|
||||
|
||||
float4 main( PFXVertToPix IN,
|
||||
uniform sampler2D prepassTex : register(S0) ) : COLOR0
|
||||
{
|
||||
float3 normal = prepassUncondition( prepassTex, IN.uv0 ).xyz;
|
||||
return float4( ( normal + 1.0 ) * 0.5, 1.0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct MaterialDecoratorConnectV
|
||||
{
|
||||
float2 uv0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
float4 main( MaterialDecoratorConnectV IN,
|
||||
uniform sampler2D shadowMap : register(S0),
|
||||
uniform sampler1D depthViz : register(S1) ) : COLOR0
|
||||
{
|
||||
float depth = saturate( tex2D( shadowMap, IN.uv0 ).r );
|
||||
return float4( tex1D( depthViz, depth ).rgb, 1 );
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct FarFrustumQuadConnectV
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
float3 wsEyeRay : TEXCOORD1;
|
||||
float3 vsEyeRay : TEXCOORD2;
|
||||
};
|
||||
|
||||
struct FarFrustumQuadConnectP
|
||||
{
|
||||
float2 uv0 : TEXCOORD0;
|
||||
float3 wsEyeRay : TEXCOORD1;
|
||||
float3 vsEyeRay : TEXCOORD2;
|
||||
};
|
||||
|
||||
|
||||
float2 getUVFromSSPos( float3 ssPos, float4 rtParams )
|
||||
{
|
||||
float2 outPos = ( ssPos.xy + 1.0 ) / 2.0;
|
||||
outPos.y = 1.0 - outPos.y;
|
||||
outPos = ( outPos * rtParams.zw ) + rtParams.xy;
|
||||
return outPos;
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../hlslStructs.h"
|
||||
#include "farFrustumQuad.hlsl"
|
||||
|
||||
|
||||
FarFrustumQuadConnectV main( VertexIn_PNT IN,
|
||||
uniform float4 rtParams0 )
|
||||
{
|
||||
FarFrustumQuadConnectV OUT;
|
||||
|
||||
OUT.hpos = float4( IN.uv0, 0, 1 );
|
||||
|
||||
// Get a RT-corrected UV from the SS coord
|
||||
OUT.uv0 = getUVFromSSPos( OUT.hpos.xyz, rtParams0 );
|
||||
|
||||
// Interpolators will generate eye rays the
|
||||
// from far-frustum corners.
|
||||
OUT.wsEyeRay = IN.pos.xyz;
|
||||
OUT.vsEyeRay = IN.normal.xyz;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
varying vec4 wsEyeDir;
|
||||
varying vec4 ssPos;
|
||||
|
||||
uniform mat4 modelview;
|
||||
uniform mat4 objTrans;
|
||||
uniform vec3 eyePosWorld;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
wsEyeDir = objTrans * gl_Vertex - vec4( eyePosWorld, 0.0 );
|
||||
ssPos = gl_Position;
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
varying vec2 uv0;
|
||||
uniform sampler2D prepassBuffer;
|
||||
uniform sampler1D depthViz;
|
||||
|
||||
void main()
|
||||
{
|
||||
float depth = prepassUncondition( prepassBuffer, uv0 ).w;
|
||||
gl_FragColor = vec4( texture1D( depthViz, depth ).rgb, 1 );
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
varying vec2 uv0;
|
||||
uniform sampler2D lightInfoBuffer;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightcolor;
|
||||
float nl_Att, specular;
|
||||
lightinfoUncondition( texture2DLod( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
|
||||
gl_FragColor = vec4( lightcolor, 1.0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
varying vec2 uv0;
|
||||
uniform sampler2D lightInfoBuffer;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 lightcolor;
|
||||
float nl_Att, specular;
|
||||
lightinfoUncondition( texture2DLod( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
|
||||
gl_FragColor = vec4( specular, specular, specular, 1.0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
|
||||
varying vec2 uv0;
|
||||
uniform sampler2D prepassTex;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 normal = prepassUncondition( prepassTex, uv0 ).xyz;
|
||||
gl_FragColor = vec4( ( normal + 1.0 ) * 0.5, 1.0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
varying vec2 uv0;
|
||||
uniform sampler2D shadowMap;
|
||||
uniform sampler1D depthViz;
|
||||
|
||||
void main()
|
||||
{
|
||||
float depth = clamp( texture2DLod( shadowMap, uv0, 0 ).r, 0.0, 1.0 );
|
||||
gl_FragColor = vec4( texture1D( depthViz, depth ).rgb, 1.0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
vec2 getUVFromSSPos( vec3 ssPos, vec4 rtParams )
|
||||
{
|
||||
vec2 outPos = ( ssPos.xy + 1.0 ) / 2.0;
|
||||
outPos = ( outPos * rtParams.zw ) + rtParams.xy;
|
||||
//outPos.y = 1.0 - outPos.y;
|
||||
return outPos;
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "farFrustumQuad.glsl"
|
||||
|
||||
uniform vec4 renderTargetParams;
|
||||
|
||||
varying vec4 hpos;
|
||||
varying vec2 uv0;
|
||||
varying vec3 wsEyeRay;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
// Expand the SS coordinate (stored in uv0)
|
||||
hpos = vec4( gl_MultiTexCoord0.st * 2.0 - 1.0, 1.0, 1.0 );
|
||||
gl_Position = hpos;
|
||||
|
||||
// Get a RT-corrected UV from the SS coord
|
||||
uv0 = getUVFromSSPos( hpos.xyz, renderTargetParams );
|
||||
|
||||
// Interpolators will generate eye ray from far-frustum corners
|
||||
wsEyeRay = gl_Vertex.xyz;
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
float attenuate( vec4 lightColor, vec2 attParams, float dist )
|
||||
{
|
||||
// We're summing the results of a scaled constant,
|
||||
// linear, and quadratic attenuation.
|
||||
|
||||
#ifdef ACCUMULATE_LUV
|
||||
return lightColor.w * ( 1.0 - dot( attParams, vec2( dist, dist * dist ) ) );
|
||||
#else
|
||||
return 1.0 - dot( attParams, vec2( dist, dist * dist ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
// Calculate the specular coefficent
|
||||
//
|
||||
// pxlToLight - Normalized vector representing direction from the pixel being lit, to the light source, in world space
|
||||
// normal - Normalized surface normal
|
||||
// pxlToEye - Normalized vector representing direction from pixel being lit, to the camera, in world space
|
||||
// specPwr - Specular exponent
|
||||
// specularScale - A scalar on the specular output used in RGB accumulation.
|
||||
//
|
||||
float calcSpecular( vec3 pxlToLight, vec3 normal, vec3 pxlToEye, float specPwr, float specularScale )
|
||||
{
|
||||
#ifdef PHONG_SPECULAR
|
||||
// (R.V)^c
|
||||
float specVal = dot( normalize( -reflect( pxlToLight, normal ) ), pxlToEye );
|
||||
#else
|
||||
// (N.H)^c [Blinn-Phong, TGEA style, default]
|
||||
float specVal = dot( normal, normalize( pxlToLight + pxlToEye ) );
|
||||
#endif
|
||||
|
||||
#ifdef ACCUMULATE_LUV
|
||||
return pow( max( specVal, 0.00001f ), specPwr );
|
||||
#else
|
||||
// If this is RGB accumulation, than there is no facility for the luminance
|
||||
// of the light to play in to the specular intensity. In LUV, the luminance
|
||||
// of the light color gets rolled into N.L * Attenuation
|
||||
return specularScale * pow( max( specVal, 0.00001f ), specPwr );
|
||||
#endif
|
||||
}
|
||||
|
||||
vec3 getDistanceVectorToPlane( vec3 origin, vec3 direction, vec4 plane )
|
||||
{
|
||||
float denum = dot( plane.xyz, direction.xyz );
|
||||
float num = dot( plane, vec4( origin, 1.0 ) );
|
||||
float t = -num / denum;
|
||||
|
||||
return direction.xyz * t;
|
||||
}
|
||||
|
||||
vec3 getDistanceVectorToPlane( float negFarPlaneDotEye, vec3 direction, vec4 plane )
|
||||
{
|
||||
float denum = dot( plane.xyz, direction.xyz );
|
||||
float t = negFarPlaneDotEye / denum;
|
||||
|
||||
return direction.xyz * t;
|
||||
}
|
||||
|
|
@ -0,0 +1,241 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
#include "farFrustumQuad.glsl"
|
||||
#include "lightingUtils.glsl"
|
||||
#include "../../shadowMap/shadowMapIO_GLSL.h"
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
|
||||
#if TORQUE_SM >= 30
|
||||
|
||||
// Enables high quality soft shadow
|
||||
// filtering for SM3.0 and above.
|
||||
#define SOFTSHADOW_SM3
|
||||
|
||||
#include "softShadow.glsl"
|
||||
|
||||
#else
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
// I am not sure if we should do this in a better way
|
||||
//#define SHADOW_CUBE
|
||||
//#define SHADOW_PARABOLOID
|
||||
#define SHADOW_DUALPARABOLOID
|
||||
#define SHADOW_DUALPARABOLOID_SINGLE_PASS
|
||||
|
||||
|
||||
#ifdef SHADOW_CUBE
|
||||
|
||||
vec3 decodeShadowCoord( vec3 shadowCoord )
|
||||
{
|
||||
return shadowCoord;
|
||||
}
|
||||
|
||||
vec4 shadowSample( samplerCUBE shadowMap, vec3 shadowCoord )
|
||||
{
|
||||
return textureCUBE( shadowMap, shadowCoord );
|
||||
}
|
||||
|
||||
#elif defined( SHADOW_DUALPARABOLOID )
|
||||
|
||||
vec3 decodeShadowCoord( vec3 paraVec )
|
||||
{
|
||||
// Swizzle z and y
|
||||
paraVec = paraVec.xzy;
|
||||
|
||||
#ifdef SHADOW_DUALPARABOLOID_SINGLE_PASS
|
||||
|
||||
bool calcBack = (paraVec.z < 0.0);
|
||||
if(calcBack)
|
||||
paraVec.z = paraVec.z * -1.0;
|
||||
|
||||
#endif
|
||||
|
||||
vec3 shadowCoord;
|
||||
shadowCoord.x = (paraVec.x / (2.0*(1.0 + paraVec.z))) + 0.5;
|
||||
shadowCoord.y = ((paraVec.y / (2.0*(1.0 + paraVec.z))) + 0.5);
|
||||
shadowCoord.z = 0;
|
||||
|
||||
// adjust the co-ordinate slightly if it is near the extent of the paraboloid
|
||||
// this value was found via experementation
|
||||
shadowCoord.xy *= 0.997;
|
||||
|
||||
#ifdef SHADOW_DUALPARABOLOID_SINGLE_PASS
|
||||
|
||||
// If this is the back, offset in the atlas
|
||||
if(calcBack)
|
||||
shadowCoord.x += 1.0;
|
||||
|
||||
// Atlasing front and back maps, so scale
|
||||
shadowCoord.x *= 0.5;
|
||||
|
||||
#endif
|
||||
|
||||
return shadowCoord;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#error Unknown shadow type!
|
||||
|
||||
#endif
|
||||
|
||||
varying vec4 wsEyeDir;
|
||||
varying vec4 ssPos;
|
||||
|
||||
|
||||
uniform sampler2D prePassBuffer;
|
||||
|
||||
#ifdef SHADOW_CUBE
|
||||
uniform samplerCube shadowMap;
|
||||
#else
|
||||
uniform sampler2D shadowMap;
|
||||
#endif
|
||||
#ifdef ACCUMULATE_LUV
|
||||
uniform sampler2D scratchTarget;
|
||||
#endif
|
||||
|
||||
uniform vec4 renderTargetParams;
|
||||
|
||||
uniform vec3 lightPosition;
|
||||
uniform vec4 lightColor;
|
||||
uniform float lightBrightness;
|
||||
uniform float lightRange;
|
||||
uniform vec2 lightAttenuation;
|
||||
uniform vec4 lightMapParams;
|
||||
|
||||
uniform vec3 eyePosWorld;
|
||||
uniform vec4 farPlane;
|
||||
uniform float negFarPlaneDotEye;
|
||||
uniform mat3x3 worldToLightProj;
|
||||
|
||||
uniform vec4 lightParams;
|
||||
uniform float shadowSoftness;
|
||||
uniform float constantSpecularPower;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
// Compute scene UV
|
||||
vec3 ssPosP = ssPos.xyz / ssPos.w;
|
||||
vec2 uvScene = getUVFromSSPos( ssPosP, renderTargetParams );
|
||||
|
||||
// Sample/unpack the normal/z data
|
||||
vec4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
|
||||
vec3 normal = prepassSample.rgb;
|
||||
float depth = prepassSample.a;
|
||||
|
||||
// Eye ray - Eye -> Pixel
|
||||
vec3 eyeRay = getDistanceVectorToPlane( negFarPlaneDotEye, wsEyeDir.xyz / wsEyeDir.w , farPlane );
|
||||
|
||||
// Get world space pixel position
|
||||
vec3 worldPos = eyePosWorld + eyeRay * depth;
|
||||
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
vec3 lightVec = lightPosition - worldPos;
|
||||
float lenLightV = length( lightVec );
|
||||
if ( lightRange - lenLightV < 0.0 )
|
||||
discard;
|
||||
|
||||
// Get the attenuated falloff.
|
||||
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
|
||||
if ( atten - 1e-6 < 0.0 )
|
||||
discard;
|
||||
|
||||
// Normalize lightVec
|
||||
lightVec /= lenLightV;
|
||||
|
||||
// If we can do dynamic branching then avoid wasting
|
||||
// fillrate on pixels that are backfacing to the light.
|
||||
float nDotL = dot( lightVec, normal );
|
||||
//DB_CLIP( nDotL < 0 );
|
||||
|
||||
#ifdef NO_SHADOW
|
||||
|
||||
float shadowed = 1.0;
|
||||
|
||||
#else
|
||||
|
||||
// Convert the light vector into a shadow map
|
||||
// here once instead of in the filtering loop.
|
||||
vec4 shadowCoord = vec4(0.0);
|
||||
#ifdef SHADOW_CUBE
|
||||
shadowCoord.xy = decodeShadowCoord( -lightVec );
|
||||
#else
|
||||
shadowCoord.xy = decodeShadowCoord( worldToLightProj * -lightVec ).xy;
|
||||
#endif
|
||||
|
||||
// Get a linear depth from the light source.
|
||||
float distToLight = lenLightV / lightRange;
|
||||
|
||||
#ifdef SOFTSHADOW_SM3
|
||||
|
||||
float shadowed = softShadow_filter( shadowMap,
|
||||
gTapRotationTex,
|
||||
ssPosP.xy,
|
||||
shadowCoord.xy,
|
||||
shadowSoftness,
|
||||
distToLight,
|
||||
nDotL,
|
||||
lightParams.y );
|
||||
|
||||
#else // !SOFTSHADOW_SM3
|
||||
|
||||
// TODO: Implement the SM2 lower quality
|
||||
// shadow filtering method.
|
||||
|
||||
#endif
|
||||
|
||||
#endif // !NO_SHADOW
|
||||
|
||||
// NOTE: Do not clip on fully shadowed pixels as it would
|
||||
// cause the hardware occlusion query to disable the shadow.
|
||||
|
||||
// Specular term
|
||||
float specular = calcSpecular( lightVec,
|
||||
normal,
|
||||
normalize( -eyeRay ),
|
||||
constantSpecularPower,
|
||||
lightColor.a * lightBrightness );
|
||||
|
||||
// N.L * Attenuation
|
||||
float Sat_NL_Att = clamp( nDotL * atten * shadowed, 0.0, 1.0 );
|
||||
|
||||
// In LUV color mode we need to blend in the
|
||||
// output from the previous target.
|
||||
vec4 previousPix = vec4(0.0);
|
||||
#ifdef ACCUMULATE_LUV
|
||||
previousPix = texture2DLod( scratchTarget, uvScene, 0 );
|
||||
#endif
|
||||
|
||||
// Output
|
||||
gl_FragColor = lightinfoCondition( lightColor.rgb * lightBrightness,
|
||||
Sat_NL_Att,
|
||||
specular,
|
||||
previousPix ) * lightMapParams;
|
||||
}
|
||||
|
|
@ -0,0 +1,131 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#define NUM_TAPS 12
|
||||
|
||||
#define NUM_PRE_TAPS 4
|
||||
|
||||
/// The non-uniform poisson disk used in the
|
||||
/// high quality shadow filtering.
|
||||
vec2 sNonUniformTaps[NUM_TAPS];
|
||||
|
||||
void initNonUniformTaps()
|
||||
{
|
||||
// These first 4 taps are located around the edges
|
||||
// of the disk and are used to predict fully shadowed
|
||||
// or unshadowed areas.
|
||||
sNonUniformTaps[0] = vec2( 0.992833, 0.979309 );
|
||||
sNonUniformTaps[1] = vec2( -0.998585, 0.985853 );
|
||||
sNonUniformTaps[2] = vec2( 0.949299, -0.882562 );
|
||||
sNonUniformTaps[3] = vec2( -0.941358, -0.893924 );
|
||||
|
||||
// The rest of the samples.
|
||||
sNonUniformTaps[4] = vec2( 0.545055, -0.589072 );
|
||||
sNonUniformTaps[5] = vec2( 0.346526, 0.385821 );
|
||||
sNonUniformTaps[6] = vec2( -0.260183, 0.334412 );
|
||||
sNonUniformTaps[7] = vec2( 0.248676, -0.679605 );
|
||||
sNonUniformTaps[8] = vec2( -0.569502, -0.390637 );
|
||||
sNonUniformTaps[9] = vec2( -0.014096, 0.012577 );
|
||||
sNonUniformTaps[10] = vec2( -0.259178, 0.876272 );
|
||||
sNonUniformTaps[11] = vec2( 0.649526, 0.664333 );
|
||||
}
|
||||
|
||||
/// The texture used to do per-pixel pseudorandom
|
||||
/// rotations of the filter taps.
|
||||
uniform sampler2D gTapRotationTex;
|
||||
|
||||
|
||||
float softShadow_sampleTaps( sampler2D shadowMap,
|
||||
vec2 sinCos,
|
||||
vec2 shadowPos,
|
||||
float filterRadius,
|
||||
float distToLight,
|
||||
float esmFactor,
|
||||
int startTap,
|
||||
int endTap )
|
||||
{
|
||||
initNonUniformTaps();
|
||||
float shadow = 0.0;
|
||||
|
||||
vec2 tap = vec2(0.0);
|
||||
for ( int t = startTap; t < endTap; t++ )
|
||||
{
|
||||
tap.x = ( sNonUniformTaps[t].x * sinCos.y - sNonUniformTaps[t].y * sinCos.x ) * filterRadius;
|
||||
tap.y = ( sNonUniformTaps[t].y * sinCos.y + sNonUniformTaps[t].x * sinCos.x ) * filterRadius;
|
||||
float occluder = texture2DLod( shadowMap, shadowPos + tap, 0.0 ).r;
|
||||
|
||||
float esm = clamp( exp( esmFactor * ( occluder - distToLight ) ), 0.0, 1.0 );
|
||||
shadow += esm / float( endTap - startTap );
|
||||
}
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
|
||||
// HACK! HACK! HACK!
|
||||
// We take the noise texture directly as the second parameter to ensure that it
|
||||
// is the "last used" sampler, and thus doesn't collide with the prepass buffer
|
||||
// or shadow map. If we use gTapRotationTex directly here, then it is the first
|
||||
// used sampler and will collide with the prepass buffer.
|
||||
float softShadow_filter( sampler2D shadowMap,
|
||||
sampler2D noiseTexture,
|
||||
vec2 vpos,
|
||||
vec2 shadowPos,
|
||||
float filterRadius,
|
||||
float distToLight,
|
||||
float dotNL,
|
||||
float esmFactor )
|
||||
{
|
||||
// Lookup the random rotation for this screen pixel.
|
||||
vec2 sinCos = ( texture2DLod( noiseTexture, vpos * 16.0, 0.0 ).rg - 0.5 ) * 2.0;
|
||||
|
||||
// Do the prediction taps first.
|
||||
float shadow = softShadow_sampleTaps( shadowMap,
|
||||
sinCos,
|
||||
shadowPos,
|
||||
filterRadius,
|
||||
distToLight,
|
||||
esmFactor,
|
||||
0,
|
||||
NUM_PRE_TAPS );
|
||||
|
||||
// Only do the expensive filtering if we're really
|
||||
// in a partially shadowed area.
|
||||
if ( shadow * ( 1.0 - shadow ) * max( dotNL, 0.0 ) > 0.06 )
|
||||
{
|
||||
shadow += softShadow_sampleTaps( shadowMap,
|
||||
sinCos,
|
||||
shadowPos,
|
||||
filterRadius,
|
||||
distToLight,
|
||||
esmFactor,
|
||||
NUM_PRE_TAPS,
|
||||
NUM_TAPS );
|
||||
|
||||
// This averages the taps above with the results
|
||||
// of the prediction samples.
|
||||
shadow *= 0.5;
|
||||
}
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
|
@ -0,0 +1,168 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
#include "farFrustumQuad.glsl"
|
||||
#include "lightingUtils.glsl"
|
||||
#include "../../shadowMap/shadowMapIO_GLSL.h"
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
|
||||
#if TORQUE_SM >= 30
|
||||
|
||||
// Enables high quality soft shadow
|
||||
// filtering for SM3.0 and above.
|
||||
#define SOFTSHADOW_SM3
|
||||
|
||||
#include "softShadow.glsl"
|
||||
|
||||
#else
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
varying vec4 ssPos;
|
||||
varying vec4 wsEyeDir;
|
||||
|
||||
|
||||
uniform sampler2D prePassBuffer;
|
||||
uniform sampler2D shadowMap;
|
||||
#ifdef ACCUMULATE_LUV
|
||||
uniform sampler2D scratchTarget;
|
||||
#endif
|
||||
|
||||
uniform vec4 renderTargetParams;
|
||||
|
||||
uniform vec3 lightPosition;
|
||||
uniform vec4 lightColor;
|
||||
uniform float lightBrightness;
|
||||
uniform float lightRange;
|
||||
uniform vec2 lightAttenuation;
|
||||
uniform vec3 lightDirection;
|
||||
uniform vec4 lightSpotParams;
|
||||
uniform vec4 lightMapParams;
|
||||
|
||||
uniform vec3 eyePosWorld;
|
||||
uniform vec4 farPlane;
|
||||
uniform float negFarPlaneDotEye;
|
||||
uniform mat4x4 worldToLightProj;
|
||||
|
||||
uniform vec4 lightParams;
|
||||
uniform float shadowSoftness;
|
||||
uniform float constantSpecularPower;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
// Compute scene UV
|
||||
vec3 ssPosP = ssPos.xyz / ssPos.w;
|
||||
vec2 uvScene = getUVFromSSPos( ssPosP, renderTargetParams );
|
||||
|
||||
// Sample/unpack the normal/z data
|
||||
vec4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
|
||||
vec3 normal = prepassSample.rgb;
|
||||
float depth = prepassSample.a;
|
||||
|
||||
// Eye ray - Eye -> Pixel
|
||||
vec3 eyeRay = getDistanceVectorToPlane( negFarPlaneDotEye, wsEyeDir.xyz / wsEyeDir.w , farPlane );
|
||||
|
||||
// Get world space pixel position
|
||||
vec3 worldPos = eyePosWorld + eyeRay * depth;
|
||||
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
vec3 lightToPxlVec = worldPos - lightPosition;
|
||||
float lenLightV = length( lightToPxlVec );
|
||||
lightToPxlVec /= lenLightV;
|
||||
|
||||
//lightDirection = float3( -lightDirection.xy, lightDirection.z ); //float3( 0, 0, -1 );
|
||||
float cosAlpha = dot( lightDirection, lightToPxlVec );
|
||||
if ( cosAlpha - lightSpotParams.x < 0.0 ) discard;
|
||||
if ( lightRange - lenLightV < 0.0 ) discard;
|
||||
|
||||
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
|
||||
atten *= ( cosAlpha - lightSpotParams.x ) / lightSpotParams.y;
|
||||
if ( atten - 1e-6 < 0.0 ) discard;
|
||||
|
||||
float nDotL = dot( normal, -lightToPxlVec );
|
||||
|
||||
#ifdef NO_SHADOW
|
||||
|
||||
float shadowed = 1.0;
|
||||
|
||||
#else
|
||||
|
||||
// Find Shadow coordinate
|
||||
vec4 pxlPosLightProj = vec4( worldToLightProj * vec4( worldPos, 1.0 ) );
|
||||
vec2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + vec2( 0.5, 0.5 );
|
||||
|
||||
// Get a linear depth from the light source.
|
||||
float distToLight = pxlPosLightProj.z / lightRange;
|
||||
|
||||
#ifdef SOFTSHADOW_SM3
|
||||
|
||||
float shadowed = softShadow_filter( shadowMap,
|
||||
gTapRotationTex,
|
||||
ssPosP.xy,
|
||||
shadowCoord,
|
||||
shadowSoftness,
|
||||
distToLight,
|
||||
nDotL,
|
||||
lightParams.y );
|
||||
|
||||
#else // !SOFTSHADOW_SM3
|
||||
|
||||
// Simple exponential shadow map.
|
||||
float occluder = decodeShadowMap( texture2DLod( shadowMap, shadowCoord, 0.0 ) );
|
||||
float esmFactor = lightParams.y;
|
||||
float shadowed = clamp( exp( esmFactor * ( occluder - distToLight ) ), 0.0, 1.0 );
|
||||
|
||||
#endif
|
||||
|
||||
#endif // !NO_SHADOW
|
||||
|
||||
// NOTE: Do not clip on fully shadowed pixels as it would
|
||||
// cause the hardware occlusion query to disable the shadow.
|
||||
|
||||
// Specular term
|
||||
float specular = calcSpecular( -lightToPxlVec,
|
||||
normal,
|
||||
normalize( -eyeRay ),
|
||||
constantSpecularPower,
|
||||
lightColor.a * lightBrightness );
|
||||
|
||||
// N.L * Attenuation
|
||||
float Sat_NL_Att = clamp( nDotL * atten * shadowed, 0.0, 1.0 );
|
||||
|
||||
// In LUV color mode we need to blend in the
|
||||
// output from the previous target.
|
||||
vec4 previousPix = vec4(0.0);
|
||||
#ifdef ACCUMULATE_LUV
|
||||
previousPix = texture2DLod( scratchTarget, uvScene, 0.0 );
|
||||
#endif
|
||||
|
||||
// Output
|
||||
gl_FragColor = lightinfoCondition( lightColor.rgb * lightBrightness,
|
||||
Sat_NL_Att,
|
||||
specular,
|
||||
previousPix ) * lightMapParams;
|
||||
}
|
||||
|
|
@ -0,0 +1,230 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../gl/hlslCompat.glsl"
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
#include "lightingUtils.glsl"
|
||||
#include "../../shadowMap/shadowMapIO_GLSL.h"
|
||||
|
||||
varying vec2 uv0;
|
||||
varying vec3 wsEyeRay;
|
||||
|
||||
uniform sampler2D prePassBuffer;
|
||||
uniform sampler2D ShadowMap;
|
||||
|
||||
#if TORQUE_SM >= 30
|
||||
|
||||
// Enables high quality soft shadow
|
||||
// filtering for SM3.0 and above.
|
||||
#define SOFTSHADOW_SM3
|
||||
|
||||
#include "softShadow.glsl"
|
||||
|
||||
#else
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
uniform vec3 lightDirection;
|
||||
uniform vec4 lightColor;
|
||||
uniform float lightBrightness;
|
||||
uniform vec4 lightAmbient;
|
||||
uniform vec4 lightTrilight;
|
||||
|
||||
uniform vec3 eyePosWorld;
|
||||
|
||||
uniform mat4 worldToLightProj;
|
||||
uniform vec4 splitDistStart;
|
||||
uniform vec4 splitDistEnd;
|
||||
uniform vec4 scaleX;
|
||||
uniform vec4 scaleY;
|
||||
uniform vec4 offsetX;
|
||||
uniform vec4 offsetY;
|
||||
uniform vec4 atlasXOffset;
|
||||
uniform vec4 atlasYOffset;
|
||||
uniform vec2 atlasScale;
|
||||
uniform vec4 zNearFarInvNearFar;
|
||||
uniform vec4 lightMapParams;
|
||||
|
||||
uniform float constantSpecularPower;
|
||||
uniform vec2 fadeStartLength;
|
||||
uniform vec4 farPlaneScalePSSM;
|
||||
uniform vec4 splitFade;
|
||||
uniform vec4 overDarkPSSM;
|
||||
uniform float shadowSoftness;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
// Sample/unpack the normal/z data
|
||||
vec4 prepassSample = prepassUncondition( prePassBuffer, uv0 );
|
||||
vec3 normal = prepassSample.rgb;
|
||||
float depth = prepassSample.a;
|
||||
|
||||
// Use eye ray to get ws pos
|
||||
vec4 worldPos = vec4(eyePosWorld + wsEyeRay * depth, 1.0f);
|
||||
|
||||
// Get the light attenuation.
|
||||
float dotNL = dot(-lightDirection, normal);
|
||||
|
||||
#ifdef NO_SHADOW
|
||||
|
||||
// Fully unshadowed.
|
||||
float shadowed = 1.0;
|
||||
|
||||
#else
|
||||
|
||||
// Compute shadow map coordinate
|
||||
vec4 pxlPosLightProj = worldToLightProj * worldPos;
|
||||
vec2 baseShadowCoord = pxlPosLightProj.xy / pxlPosLightProj.w;
|
||||
|
||||
float distOffset = 0.0;
|
||||
float shadowed = 0.0;
|
||||
float fadeAmt = 0.0;
|
||||
vec4 zDist = vec4(zNearFarInvNearFar.x + zNearFarInvNearFar.y * depth);
|
||||
|
||||
// Calculate things dependant on the shadowmap split
|
||||
for ( int i = 0; i < 2; i++ )
|
||||
{
|
||||
float zDistSplit = zDist.x + distOffset;
|
||||
vec4 mask0;
|
||||
mask0.x = float(zDistSplit >= splitDistStart.x);
|
||||
mask0.y = float(zDistSplit >= splitDistStart.y);
|
||||
mask0.z = float(zDistSplit >= splitDistStart.z);
|
||||
mask0.w = float(zDistSplit >= splitDistStart.w);
|
||||
|
||||
vec4 mask1;
|
||||
mask1.x = float(zDistSplit < splitDistEnd.x);
|
||||
mask1.y = float(zDistSplit < splitDistEnd.y);
|
||||
mask1.z = float(zDistSplit < splitDistEnd.z);
|
||||
mask1.w = float(zDistSplit < splitDistEnd.w);
|
||||
|
||||
vec4 finalMask = mask0 * mask1;
|
||||
|
||||
float splitFadeDist = dot( finalMask, splitFade );
|
||||
|
||||
vec2 finalScale;
|
||||
finalScale.x = dot(finalMask, scaleX);
|
||||
finalScale.y = dot(finalMask, scaleY);
|
||||
|
||||
vec2 finalOffset;
|
||||
finalOffset.x = dot(finalMask, offsetX);
|
||||
finalOffset.y = dot(finalMask, offsetY);
|
||||
|
||||
vec2 shadowCoord;
|
||||
shadowCoord = baseShadowCoord * finalScale;
|
||||
shadowCoord += finalOffset;
|
||||
|
||||
// Convert to texcoord space
|
||||
shadowCoord = 0.5 * shadowCoord + vec2(0.5, 0.5);
|
||||
//shadowCoord.y = 1.0f - shadowCoord.y;
|
||||
|
||||
// Move around inside of atlas
|
||||
vec2 aOffset;
|
||||
aOffset.x = dot(finalMask, atlasXOffset);
|
||||
aOffset.y = dot(finalMask, atlasYOffset);
|
||||
|
||||
shadowCoord *= atlasScale;
|
||||
shadowCoord += aOffset;
|
||||
|
||||
// Distance to light, in shadowmap space
|
||||
float distToLight = pxlPosLightProj.z / pxlPosLightProj.w;
|
||||
|
||||
// Each split has a different far plane, take this into account.
|
||||
float farPlaneScale = dot( farPlaneScalePSSM, finalMask );
|
||||
distToLight *= farPlaneScale;
|
||||
|
||||
#ifdef SOFTSHADOW_SM3
|
||||
|
||||
float esmShadow = softShadow_filter( ShadowMap,
|
||||
gTapRotationTex,
|
||||
uv0.xy,
|
||||
shadowCoord,
|
||||
farPlaneScale * shadowSoftness,
|
||||
distToLight,
|
||||
dotNL,
|
||||
dot( finalMask, overDarkPSSM ) );
|
||||
|
||||
#else // !SOFTSHADOW_SM3
|
||||
|
||||
float occluder = decodeShadowMap( texture2DLod( ShadowMap, shadowCoord, 0.0 ) );
|
||||
float overDark = dot( finalMask, overDarkPSSM );
|
||||
float esmShadow = saturate( exp( esmFactor * ( occluder - distToLight ) ) );
|
||||
|
||||
#endif
|
||||
|
||||
if ( i == 0 )
|
||||
{
|
||||
float endDist = dot(splitDistEnd, finalMask);
|
||||
fadeAmt = smoothstep(endDist - splitFadeDist, endDist, zDist).x;
|
||||
shadowed = esmShadow * ( 1.0 - fadeAmt );
|
||||
}
|
||||
else
|
||||
shadowed += esmShadow * fadeAmt;
|
||||
|
||||
distOffset += splitFadeDist;
|
||||
}
|
||||
|
||||
// Fade out the shadow at the end of the range.
|
||||
float fadeOutAmt = ( zDist.x - fadeStartLength.x ) * fadeStartLength.y;
|
||||
shadowed = mix( shadowed, 1.0, clamp( fadeOutAmt, 0.0, 1.0 ) );
|
||||
|
||||
#endif // !NO_SHADOW
|
||||
|
||||
// Calc lighting coefficents
|
||||
float specular = calcSpecular( -lightDirection,
|
||||
normal,
|
||||
normalize(-wsEyeRay),
|
||||
constantSpecularPower,
|
||||
lightColor.a * lightBrightness );
|
||||
|
||||
float Sat_NL_Att = clamp(dotNL, 0.0, 1.0) * shadowed;
|
||||
|
||||
// Trilight, described by Tom Forsyth
|
||||
// http://home.comcast.net/~tom_forsyth/papers/trilight/trilight.html
|
||||
#ifdef ACCUMULATE_LUV
|
||||
|
||||
// In LUV multiply in the brightness of the light color (normaly done in the attenuate function)
|
||||
Sat_NL_Att *= lightColor.a;
|
||||
|
||||
vec4 ambientBlend = lightAmbient;
|
||||
ambientBlend.b *= clamp(-dotNL, 0.0, 1.0);
|
||||
|
||||
vec3 trilight = lightTrilight.rgb;
|
||||
trilight.b *= clamp(1.0 - abs(dotNL), 0.0, 1.0);
|
||||
|
||||
ambientBlend.rg = mix(ambientBlend.rg, trilight.rg, clamp(0.5 * trilight.b / lightAmbient.b, 0.0, 1.0));
|
||||
ambientBlend.b += trilight.b;
|
||||
|
||||
#else
|
||||
|
||||
// RGB
|
||||
// TODO: Trilight seems broken... it does lighting in shadows!
|
||||
//vec4 ambientBlend = vec4(lightTrilight.rgb * clamp(1.0 - abs(dotNL), 0.0, 1.0) + lightAmbient.rgb * clamp(-dotNL, 0.0, 1.0), 0.0);
|
||||
vec4 ambientBlend = vec4(lightAmbient.rgb, 0.0);
|
||||
|
||||
#endif
|
||||
|
||||
// Output
|
||||
gl_FragColor = lightinfoCondition( lightColor.rgb * lightBrightness, Sat_NL_Att, specular, ambientBlend) * lightMapParams;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
float attenuate( float4 lightColor, float2 attParams, float dist )
|
||||
{
|
||||
// We're summing the results of a scaled constant,
|
||||
// linear, and quadratic attenuation.
|
||||
|
||||
#ifdef ACCUMULATE_LUV
|
||||
return lightColor.w * ( 1.0 - dot( attParams, float2( dist, dist * dist ) ) );
|
||||
#else
|
||||
return 1.0 - dot( attParams, float2( dist, dist * dist ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
float3 getDistanceVectorToPlane( float3 origin, float3 direction, float4 plane )
|
||||
{
|
||||
float denum = dot( plane.xyz, direction.xyz );
|
||||
float num = dot( plane, float4( origin, 1.0 ) );
|
||||
float t = -num / denum;
|
||||
|
||||
return direction.xyz * t;
|
||||
}
|
||||
|
||||
float3 getDistanceVectorToPlane( float negFarPlaneDotEye, float3 direction, float4 plane )
|
||||
{
|
||||
float denum = dot( plane.xyz, direction.xyz );
|
||||
float t = negFarPlaneDotEye / denum;
|
||||
|
||||
return direction.xyz * t;
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
#include "farFrustumQuad.hlsl"
|
||||
#include "lightingUtils.hlsl"
|
||||
#include "../../lighting.hlsl"
|
||||
|
||||
|
||||
struct ConvexConnectP
|
||||
{
|
||||
float4 ssPos : TEXCOORD0;
|
||||
float3 vsEyeDir : TEXCOORD1;
|
||||
};
|
||||
|
||||
float4 main( ConvexConnectP IN,
|
||||
uniform sampler2D prePassBuffer : register(S0),
|
||||
|
||||
uniform float4 lightPosition,
|
||||
uniform float4 lightColor,
|
||||
uniform float lightRange,
|
||||
|
||||
uniform float4 vsFarPlane,
|
||||
uniform float4 rtParams0 ) : COLOR0
|
||||
{
|
||||
// Compute scene UV
|
||||
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
|
||||
float2 uvScene = getUVFromSSPos(ssPos, rtParams0);
|
||||
|
||||
// Sample/unpack the normal/z data
|
||||
float4 prepassSample = prepassUncondition(prePassBuffer, uvScene);
|
||||
float3 normal = prepassSample.rgb;
|
||||
float depth = prepassSample.a;
|
||||
|
||||
// Eye ray - Eye -> Pixel
|
||||
float3 eyeRay = getDistanceVectorToPlane(-vsFarPlane.w, IN.vsEyeDir, vsFarPlane);
|
||||
float3 viewSpacePos = eyeRay * depth;
|
||||
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
float3 lightVec = lightPosition.xyz - viewSpacePos;
|
||||
float lenLightV = length(lightVec);
|
||||
clip(lightRange - lenLightV);
|
||||
|
||||
// Do a very simple falloff instead of real attenuation
|
||||
float atten = 1.0 - saturate(lenLightV / lightRange);
|
||||
|
||||
// Normalize lightVec
|
||||
lightVec /= lenLightV;
|
||||
|
||||
// N.L * Attenuation
|
||||
float Sat_NL_Att = saturate(dot(lightVec, normal)) * atten;
|
||||
|
||||
// Output, no specular
|
||||
return lightinfoCondition(lightColor.rgb, Sat_NL_Att, 0.0, 0.0);
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../hlslStructs.h"
|
||||
|
||||
struct ConvexConnectV
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float4 ssPos : TEXCOORD0;
|
||||
float3 vsEyeDir : TEXCOORD1;
|
||||
};
|
||||
|
||||
ConvexConnectV main( VertexIn_P IN,
|
||||
uniform float4x4 viewProj,
|
||||
uniform float4x4 view,
|
||||
uniform float3 particlePosWorld,
|
||||
uniform float lightRange )
|
||||
{
|
||||
ConvexConnectV OUT;
|
||||
|
||||
float4 vPosWorld = IN.pos + float4(particlePosWorld, 0.0) + float4(IN.pos.xyz, 0.0) * lightRange;
|
||||
OUT.hpos = mul(viewProj, vPosWorld);
|
||||
OUT.vsEyeDir = mul(view, vPosWorld);
|
||||
OUT.ssPos = OUT.hpos;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
|
@ -0,0 +1,239 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
#include "farFrustumQuad.hlsl"
|
||||
#include "lightingUtils.hlsl"
|
||||
#include "../../lighting.hlsl"
|
||||
#include "../shadowMap/shadowMapIO_HLSL.h"
|
||||
#include "softShadow.hlsl"
|
||||
|
||||
|
||||
struct ConvexConnectP
|
||||
{
|
||||
float4 wsEyeDir : TEXCOORD0;
|
||||
float4 ssPos : TEXCOORD1;
|
||||
float4 vsEyeDir : TEXCOORD2;
|
||||
};
|
||||
|
||||
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
/// The texture for cookie rendering.
|
||||
uniform samplerCUBE cookieMap : register(S2);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SHADOW_CUBE
|
||||
|
||||
float3 decodeShadowCoord( float3 shadowCoord )
|
||||
{
|
||||
return shadowCoord;
|
||||
}
|
||||
|
||||
float4 shadowSample( samplerCUBE shadowMap, float3 shadowCoord )
|
||||
{
|
||||
return texCUBE( shadowMap, shadowCoord );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
float3 decodeShadowCoord( float3 paraVec )
|
||||
{
|
||||
// Flip y and z
|
||||
paraVec = paraVec.xzy;
|
||||
|
||||
#ifndef SHADOW_PARABOLOID
|
||||
|
||||
bool calcBack = (paraVec.z < 0.0);
|
||||
if ( calcBack )
|
||||
{
|
||||
paraVec.z = paraVec.z * -1.0;
|
||||
|
||||
#ifdef SHADOW_DUALPARABOLOID
|
||||
paraVec.x = -paraVec.x;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
float3 shadowCoord;
|
||||
shadowCoord.x = (paraVec.x / (2*(1 + paraVec.z))) + 0.5;
|
||||
shadowCoord.y = 1-((paraVec.y / (2*(1 + paraVec.z))) + 0.5);
|
||||
shadowCoord.z = 0;
|
||||
|
||||
// adjust the co-ordinate slightly if it is near the extent of the paraboloid
|
||||
// this value was found via experementation
|
||||
// NOTE: this is wrong, it only biases in one direction, not towards the uv
|
||||
// center ( 0.5 0.5 ).
|
||||
//shadowCoord.xy *= 0.997;
|
||||
|
||||
#ifndef SHADOW_PARABOLOID
|
||||
|
||||
// If this is the back, offset in the atlas
|
||||
if ( calcBack )
|
||||
shadowCoord.x += 1.0;
|
||||
|
||||
// Atlasing front and back maps, so scale
|
||||
shadowCoord.x *= 0.5;
|
||||
|
||||
#endif
|
||||
|
||||
return shadowCoord;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
float4 main( ConvexConnectP IN,
|
||||
|
||||
uniform sampler2D prePassBuffer : register(S0),
|
||||
|
||||
#ifdef SHADOW_CUBE
|
||||
uniform samplerCUBE shadowMap : register(S1),
|
||||
#else
|
||||
uniform sampler2D shadowMap : register(S1),
|
||||
#endif
|
||||
|
||||
uniform float4 rtParams0,
|
||||
|
||||
uniform float3 lightPosition,
|
||||
uniform float4 lightColor,
|
||||
uniform float lightBrightness,
|
||||
uniform float lightRange,
|
||||
uniform float2 lightAttenuation,
|
||||
uniform float4 lightMapParams,
|
||||
|
||||
uniform float4 vsFarPlane,
|
||||
uniform float3x3 viewToLightProj,
|
||||
|
||||
uniform float4 lightParams,
|
||||
uniform float shadowSoftness ) : COLOR0
|
||||
{
|
||||
// Compute scene UV
|
||||
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
|
||||
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
|
||||
|
||||
// Sample/unpack the normal/z data
|
||||
float4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
|
||||
float3 normal = prepassSample.rgb;
|
||||
float depth = prepassSample.a;
|
||||
|
||||
// Eye ray - Eye -> Pixel
|
||||
float3 eyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
|
||||
float3 viewSpacePos = eyeRay * depth;
|
||||
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
float3 lightVec = lightPosition - viewSpacePos;
|
||||
float lenLightV = length( lightVec );
|
||||
clip( lightRange - lenLightV );
|
||||
|
||||
// Get the attenuated falloff.
|
||||
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
|
||||
clip( atten - 1e-6 );
|
||||
|
||||
// Normalize lightVec
|
||||
lightVec /= lenLightV;
|
||||
|
||||
// If we can do dynamic branching then avoid wasting
|
||||
// fillrate on pixels that are backfacing to the light.
|
||||
float nDotL = dot( lightVec, normal );
|
||||
//DB_CLIP( nDotL < 0 );
|
||||
|
||||
#ifdef NO_SHADOW
|
||||
|
||||
float shadowed = 1.0;
|
||||
|
||||
#else
|
||||
|
||||
// Get a linear depth from the light source.
|
||||
float distToLight = lenLightV / lightRange;
|
||||
|
||||
#ifdef SHADOW_CUBE
|
||||
|
||||
// TODO: We need to fix shadow cube to handle soft shadows!
|
||||
float occ = texCUBE( shadowMap, mul( viewToLightProj, -lightVec ) ).r;
|
||||
float shadowed = saturate( exp( lightParams.y * ( occ - distToLight ) ) );
|
||||
|
||||
#else
|
||||
|
||||
float2 shadowCoord = decodeShadowCoord( mul( viewToLightProj, -lightVec ) ).xy;
|
||||
|
||||
float shadowed = softShadow_filter( shadowMap,
|
||||
ssPos.xy,
|
||||
shadowCoord,
|
||||
shadowSoftness,
|
||||
distToLight,
|
||||
nDotL,
|
||||
lightParams.y );
|
||||
|
||||
#endif
|
||||
|
||||
#endif // !NO_SHADOW
|
||||
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
// Lookup the cookie sample.
|
||||
float4 cookie = texCUBE( cookieMap, mul( viewToLightProj, -lightVec ) );
|
||||
|
||||
// Multiply the light with the cookie tex.
|
||||
lightColor.rgb *= cookie.rgb;
|
||||
|
||||
// Use a maximum channel luminance to attenuate
|
||||
// the lighting else we get specular in the dark
|
||||
// regions of the cookie texture.
|
||||
atten *= max( cookie.r, max( cookie.g, cookie.b ) );
|
||||
|
||||
#endif
|
||||
|
||||
// NOTE: Do not clip on fully shadowed pixels as it would
|
||||
// cause the hardware occlusion query to disable the shadow.
|
||||
|
||||
// Specular term
|
||||
float specular = AL_CalcSpecular( lightVec,
|
||||
normal,
|
||||
normalize( -eyeRay ) ) * lightColor.a;
|
||||
|
||||
float Sat_NL_Att = saturate( nDotL * atten * shadowed ) * lightBrightness;
|
||||
float3 lightColorOut = lightMapParams.rgb * lightColor.rgb;
|
||||
float4 addToResult = 0.0;
|
||||
|
||||
// TODO: This needs to be removed when lightmapping is disabled
|
||||
// as its extra work per-pixel on dynamic lit scenes.
|
||||
//
|
||||
// Special lightmapping pass.
|
||||
if ( lightMapParams.a < 0.0 )
|
||||
{
|
||||
// This disables shadows on the backsides of objects.
|
||||
shadowed = nDotL < 0.0f ? 1.0f : shadowed;
|
||||
|
||||
Sat_NL_Att = 1.0f;
|
||||
shadowed = lerp( 1.0f, shadowed, atten );
|
||||
lightColorOut = shadowed;
|
||||
specular *= lightBrightness;
|
||||
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
|
||||
}
|
||||
|
||||
return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
|
||||
}
|
||||
|
|
@ -0,0 +1,159 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#if defined( SOFTSHADOW ) && defined( SOFTSHADOW_HIGH_QUALITY )
|
||||
|
||||
#define NUM_PRE_TAPS 4
|
||||
#define NUM_TAPS 12
|
||||
|
||||
/// The non-uniform poisson disk used in the
|
||||
/// high quality shadow filtering.
|
||||
static float2 sNonUniformTaps[NUM_TAPS] =
|
||||
{
|
||||
// These first 4 taps are located around the edges
|
||||
// of the disk and are used to predict fully shadowed
|
||||
// or unshadowed areas.
|
||||
{ 0.992833, 0.979309 },
|
||||
{ -0.998585, 0.985853 },
|
||||
{ 0.949299, -0.882562 },
|
||||
{ -0.941358, -0.893924 },
|
||||
|
||||
// The rest of the samples.
|
||||
{ 0.545055, -0.589072 },
|
||||
{ 0.346526, 0.385821 },
|
||||
{ -0.260183, 0.334412 },
|
||||
{ 0.248676, -0.679605 },
|
||||
{ -0.569502, -0.390637 },
|
||||
{ -0.614096, 0.212577 },
|
||||
{ -0.259178, 0.876272 },
|
||||
{ 0.649526, 0.864333 },
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
#define NUM_PRE_TAPS 5
|
||||
|
||||
/// The non-uniform poisson disk used in the
|
||||
/// high quality shadow filtering.
|
||||
static float2 sNonUniformTaps[NUM_PRE_TAPS] =
|
||||
{
|
||||
{ 0.892833, 0.959309 },
|
||||
{ -0.941358, -0.873924 },
|
||||
{ -0.260183, 0.334412 },
|
||||
{ 0.348676, -0.679605 },
|
||||
{ -0.569502, -0.390637 },
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/// The texture used to do per-pixel pseudorandom
|
||||
/// rotations of the filter taps.
|
||||
uniform sampler2D gTapRotationTex : register(S3);
|
||||
|
||||
|
||||
float softShadow_sampleTaps( sampler2D shadowMap,
|
||||
float2 sinCos,
|
||||
float2 shadowPos,
|
||||
float filterRadius,
|
||||
float distToLight,
|
||||
float esmFactor,
|
||||
int startTap,
|
||||
int endTap )
|
||||
{
|
||||
float shadow = 0;
|
||||
|
||||
float2 tap = 0;
|
||||
for ( int t = startTap; t < endTap; t++ )
|
||||
{
|
||||
tap.x = ( sNonUniformTaps[t].x * sinCos.y - sNonUniformTaps[t].y * sinCos.x ) * filterRadius;
|
||||
tap.y = ( sNonUniformTaps[t].y * sinCos.y + sNonUniformTaps[t].x * sinCos.x ) * filterRadius;
|
||||
float occluder = tex2Dlod( shadowMap, float4( shadowPos + tap, 0, 0 ) ).r;
|
||||
|
||||
float esm = saturate( exp( esmFactor * ( occluder - distToLight ) ) );
|
||||
shadow += esm / float( endTap - startTap );
|
||||
}
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
||||
|
||||
float softShadow_filter( sampler2D shadowMap,
|
||||
float2 vpos,
|
||||
float2 shadowPos,
|
||||
float filterRadius,
|
||||
float distToLight,
|
||||
float dotNL,
|
||||
float esmFactor )
|
||||
{
|
||||
#ifndef SOFTSHADOW
|
||||
|
||||
// If softshadow is undefined then we skip any complex
|
||||
// filtering... just do a single sample ESM.
|
||||
|
||||
float occluder = tex2Dlod( shadowMap, float4( shadowPos, 0, 0 ) ).r;
|
||||
float shadow = saturate( exp( esmFactor * ( occluder - distToLight ) ) );
|
||||
|
||||
#else
|
||||
|
||||
// Lookup the random rotation for this screen pixel.
|
||||
float2 sinCos = ( tex2Dlod( gTapRotationTex, float4( vpos * 16, 0, 0 ) ).rg - 0.5 ) * 2;
|
||||
|
||||
// Do the prediction taps first.
|
||||
float shadow = softShadow_sampleTaps( shadowMap,
|
||||
sinCos,
|
||||
shadowPos,
|
||||
filterRadius,
|
||||
distToLight,
|
||||
esmFactor,
|
||||
0,
|
||||
NUM_PRE_TAPS );
|
||||
|
||||
// We live with only the pretap results if we don't
|
||||
// have high quality shadow filtering enabled.
|
||||
#ifdef SOFTSHADOW_HIGH_QUALITY
|
||||
|
||||
// Only do the expensive filtering if we're really
|
||||
// in a partially shadowed area.
|
||||
if ( shadow * ( 1.0 - shadow ) * max( dotNL, 0 ) > 0.06 )
|
||||
{
|
||||
shadow += softShadow_sampleTaps( shadowMap,
|
||||
sinCos,
|
||||
shadowPos,
|
||||
filterRadius,
|
||||
distToLight,
|
||||
esmFactor,
|
||||
NUM_PRE_TAPS,
|
||||
NUM_TAPS );
|
||||
|
||||
// This averages the taps above with the results
|
||||
// of the prediction samples.
|
||||
shadow *= 0.5;
|
||||
}
|
||||
|
||||
#endif // SOFTSHADOW_HIGH_QUALITY
|
||||
|
||||
#endif // SOFTSHADOW
|
||||
|
||||
return shadow;
|
||||
}
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
#include "farFrustumQuad.hlsl"
|
||||
#include "lightingUtils.hlsl"
|
||||
#include "../../lighting.hlsl"
|
||||
#include "../shadowMap/shadowMapIO_HLSL.h"
|
||||
#include "softShadow.hlsl"
|
||||
|
||||
|
||||
struct ConvexConnectP
|
||||
{
|
||||
float4 wsEyeDir : TEXCOORD0;
|
||||
float4 ssPos : TEXCOORD1;
|
||||
float4 vsEyeDir : TEXCOORD2;
|
||||
};
|
||||
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
/// The texture for cookie rendering.
|
||||
uniform sampler2D cookieMap : register(S2);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
float4 main( ConvexConnectP IN,
|
||||
|
||||
uniform sampler2D prePassBuffer : register(S0),
|
||||
uniform sampler2D shadowMap : register(S1),
|
||||
|
||||
uniform float4 rtParams0,
|
||||
|
||||
uniform float3 lightPosition,
|
||||
uniform float4 lightColor,
|
||||
uniform float lightBrightness,
|
||||
uniform float lightRange,
|
||||
uniform float2 lightAttenuation,
|
||||
uniform float3 lightDirection,
|
||||
uniform float4 lightSpotParams,
|
||||
uniform float4 lightMapParams,
|
||||
|
||||
uniform float4 vsFarPlane,
|
||||
uniform float4x4 viewToLightProj,
|
||||
|
||||
uniform float4 lightParams,
|
||||
uniform float shadowSoftness ) : COLOR0
|
||||
{
|
||||
// Compute scene UV
|
||||
float3 ssPos = IN.ssPos.xyz / IN.ssPos.w;
|
||||
float2 uvScene = getUVFromSSPos( ssPos, rtParams0 );
|
||||
|
||||
// Sample/unpack the normal/z data
|
||||
float4 prepassSample = prepassUncondition( prePassBuffer, uvScene );
|
||||
float3 normal = prepassSample.rgb;
|
||||
float depth = prepassSample.a;
|
||||
|
||||
// Eye ray - Eye -> Pixel
|
||||
float3 eyeRay = getDistanceVectorToPlane( -vsFarPlane.w, IN.vsEyeDir.xyz, vsFarPlane );
|
||||
float3 viewSpacePos = eyeRay * depth;
|
||||
|
||||
// Build light vec, get length, clip pixel if needed
|
||||
float3 lightToPxlVec = viewSpacePos - lightPosition;
|
||||
float lenLightV = length( lightToPxlVec );
|
||||
lightToPxlVec /= lenLightV;
|
||||
|
||||
//lightDirection = float3( -lightDirection.xy, lightDirection.z ); //float3( 0, 0, -1 );
|
||||
float cosAlpha = dot( lightDirection, lightToPxlVec );
|
||||
clip( cosAlpha - lightSpotParams.x );
|
||||
clip( lightRange - lenLightV );
|
||||
|
||||
float atten = attenuate( lightColor, lightAttenuation, lenLightV );
|
||||
atten *= ( cosAlpha - lightSpotParams.x ) / lightSpotParams.y;
|
||||
clip( atten - 1e-6 );
|
||||
atten = saturate( atten );
|
||||
|
||||
float nDotL = dot( normal, -lightToPxlVec );
|
||||
|
||||
// Get the shadow texture coordinate
|
||||
float4 pxlPosLightProj = mul( viewToLightProj, float4( viewSpacePos, 1 ) );
|
||||
float2 shadowCoord = ( ( pxlPosLightProj.xy / pxlPosLightProj.w ) * 0.5 ) + float2( 0.5, 0.5 );
|
||||
shadowCoord.y = 1.0f - shadowCoord.y;
|
||||
|
||||
#ifdef NO_SHADOW
|
||||
|
||||
float shadowed = 1.0;
|
||||
|
||||
#else
|
||||
|
||||
// Get a linear depth from the light source.
|
||||
float distToLight = pxlPosLightProj.z / lightRange;
|
||||
|
||||
float shadowed = softShadow_filter( shadowMap,
|
||||
ssPos.xy,
|
||||
shadowCoord,
|
||||
shadowSoftness,
|
||||
distToLight,
|
||||
nDotL,
|
||||
lightParams.y );
|
||||
|
||||
#endif // !NO_SHADOW
|
||||
|
||||
#ifdef USE_COOKIE_TEX
|
||||
|
||||
// Lookup the cookie sample.
|
||||
float4 cookie = tex2D( cookieMap, shadowCoord );
|
||||
|
||||
// Multiply the light with the cookie tex.
|
||||
lightColor.rgb *= cookie.rgb;
|
||||
|
||||
// Use a maximum channel luminance to attenuate
|
||||
// the lighting else we get specular in the dark
|
||||
// regions of the cookie texture.
|
||||
atten *= max( cookie.r, max( cookie.g, cookie.b ) );
|
||||
|
||||
#endif
|
||||
|
||||
// NOTE: Do not clip on fully shadowed pixels as it would
|
||||
// cause the hardware occlusion query to disable the shadow.
|
||||
|
||||
// Specular term
|
||||
float specular = AL_CalcSpecular( -lightToPxlVec,
|
||||
normal,
|
||||
normalize( -eyeRay ) ) * lightColor.a;
|
||||
|
||||
float Sat_NL_Att = saturate( nDotL * atten * shadowed ) * lightBrightness;
|
||||
float3 lightColorOut = lightMapParams.rgb * lightColor.rgb;
|
||||
float4 addToResult = 0.0;
|
||||
|
||||
// TODO: This needs to be removed when lightmapping is disabled
|
||||
// as its extra work per-pixel on dynamic lit scenes.
|
||||
//
|
||||
// Special lightmapping pass.
|
||||
if ( lightMapParams.a < 0.0 )
|
||||
{
|
||||
// This disables shadows on the backsides of objects.
|
||||
shadowed = nDotL < 0.0f ? 1.0f : shadowed;
|
||||
|
||||
Sat_NL_Att = 1.0f;
|
||||
shadowed = lerp( 1.0f, shadowed, atten );
|
||||
lightColorOut = shadowed;
|
||||
specular *= lightBrightness;
|
||||
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
|
||||
}
|
||||
|
||||
return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
|
||||
}
|
||||
|
|
@ -0,0 +1,233 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
#include "farFrustumQuad.hlsl"
|
||||
#include "../../torque.hlsl"
|
||||
#include "../../lighting.hlsl"
|
||||
#include "lightingUtils.hlsl"
|
||||
#include "../shadowMap/shadowMapIO_HLSL.h"
|
||||
#include "softShadow.hlsl"
|
||||
|
||||
|
||||
uniform sampler2D ShadowMap : register(S1);
|
||||
|
||||
#ifdef USE_SSAO_MASK
|
||||
uniform sampler2D ssaoMask : register(S2);
|
||||
uniform float4 rtParams2;
|
||||
#endif
|
||||
|
||||
|
||||
float4 main( FarFrustumQuadConnectP IN,
|
||||
|
||||
uniform sampler2D prePassBuffer : register(S0),
|
||||
|
||||
uniform float3 lightDirection,
|
||||
uniform float4 lightColor,
|
||||
uniform float lightBrightness,
|
||||
uniform float4 lightAmbient,
|
||||
|
||||
uniform float3 eyePosWorld,
|
||||
|
||||
uniform float4x4 worldToLightProj,
|
||||
|
||||
uniform float4 scaleX,
|
||||
uniform float4 scaleY,
|
||||
uniform float4 offsetX,
|
||||
uniform float4 offsetY,
|
||||
uniform float4 atlasXOffset,
|
||||
uniform float4 atlasYOffset,
|
||||
uniform float2 atlasScale,
|
||||
uniform float4 zNearFarInvNearFar,
|
||||
uniform float4 lightMapParams,
|
||||
|
||||
uniform float2 fadeStartLength,
|
||||
uniform float4 farPlaneScalePSSM,
|
||||
uniform float4 overDarkPSSM,
|
||||
uniform float shadowSoftness ) : COLOR0
|
||||
{
|
||||
// Sample/unpack the normal/z data
|
||||
float4 prepassSample = prepassUncondition( prePassBuffer, IN.uv0 );
|
||||
float3 normal = prepassSample.rgb;
|
||||
float depth = prepassSample.a;
|
||||
|
||||
// Use eye ray to get ws pos
|
||||
float4 worldPos = float4(eyePosWorld + IN.wsEyeRay * depth, 1.0f);
|
||||
|
||||
// Get the light attenuation.
|
||||
float dotNL = dot(-lightDirection, normal);
|
||||
|
||||
#ifdef PSSM_DEBUG_RENDER
|
||||
float3 debugColor = 0;
|
||||
#endif
|
||||
|
||||
#ifdef NO_SHADOW
|
||||
|
||||
// Fully unshadowed.
|
||||
float shadowed = 1.0;
|
||||
|
||||
#ifdef PSSM_DEBUG_RENDER
|
||||
debugColor = 1.0;
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
// Compute shadow map coordinate
|
||||
float4 pxlPosLightProj = mul(worldToLightProj, worldPos);
|
||||
float2 baseShadowCoord = pxlPosLightProj.xy / pxlPosLightProj.w;
|
||||
|
||||
// Distance to light, in shadowmap space
|
||||
float distToLight = pxlPosLightProj.z / pxlPosLightProj.w;
|
||||
|
||||
// Figure out which split to sample from. Basically, we compute the shadowmap sample coord
|
||||
// for all of the splits and then check if its valid.
|
||||
float4 shadowCoordX = baseShadowCoord.xxxx;
|
||||
float4 shadowCoordY = baseShadowCoord.yyyy;
|
||||
float4 farPlaneDists = distToLight.xxxx;
|
||||
shadowCoordX *= scaleX;
|
||||
shadowCoordY *= scaleY;
|
||||
shadowCoordX += offsetX;
|
||||
shadowCoordY += offsetY;
|
||||
farPlaneDists *= farPlaneScalePSSM;
|
||||
|
||||
// If the shadow sample is within -1..1 and the distance
|
||||
// to the light for this pixel is less than the far plane
|
||||
// of the split, use it.
|
||||
float4 finalMask;
|
||||
if ( shadowCoordX.x > -0.99 && shadowCoordX.x < 0.99 &&
|
||||
shadowCoordY.x > -0.99 && shadowCoordY.x < 0.99 &&
|
||||
farPlaneDists.x < 1.0 )
|
||||
finalMask = float4(1, 0, 0, 0);
|
||||
|
||||
else if ( shadowCoordX.y > -0.99 && shadowCoordX.y < 0.99 &&
|
||||
shadowCoordY.y > -0.99 && shadowCoordY.y < 0.99 &&
|
||||
farPlaneDists.y < 1.0 )
|
||||
finalMask = float4(0, 1, 0, 0);
|
||||
|
||||
else if ( shadowCoordX.z > -0.99 && shadowCoordX.z < 0.99 &&
|
||||
shadowCoordY.z > -0.99 && shadowCoordY.z < 0.99 &&
|
||||
farPlaneDists.z < 1.0 )
|
||||
finalMask = float4(0, 0, 1, 0);
|
||||
|
||||
else
|
||||
finalMask = float4(0, 0, 0, 1);
|
||||
|
||||
|
||||
#ifdef PSSM_DEBUG_RENDER
|
||||
if ( finalMask.x > 0 )
|
||||
debugColor += float3( 1, 0, 0 );
|
||||
else if ( finalMask.y > 0 )
|
||||
debugColor += float3( 0, 1, 0 );
|
||||
else if ( finalMask.z > 0 )
|
||||
debugColor += float3( 0, 0, 1 );
|
||||
else if ( finalMask.w > 0 )
|
||||
debugColor += float3( 1, 1, 0 );
|
||||
#endif
|
||||
|
||||
// Here we know what split we're sampling from, so recompute the texcoord location
|
||||
// Yes, we could just use the result from above, but doing it this way actually saves
|
||||
// shader instructions.
|
||||
float2 finalScale;
|
||||
finalScale.x = dot(finalMask, scaleX);
|
||||
finalScale.y = dot(finalMask, scaleY);
|
||||
|
||||
float2 finalOffset;
|
||||
finalOffset.x = dot(finalMask, offsetX);
|
||||
finalOffset.y = dot(finalMask, offsetY);
|
||||
|
||||
float2 shadowCoord;
|
||||
shadowCoord = baseShadowCoord * finalScale;
|
||||
shadowCoord += finalOffset;
|
||||
|
||||
// Convert to texcoord space
|
||||
shadowCoord = 0.5 * shadowCoord + float2(0.5, 0.5);
|
||||
shadowCoord.y = 1.0f - shadowCoord.y;
|
||||
|
||||
// Move around inside of atlas
|
||||
float2 aOffset;
|
||||
aOffset.x = dot(finalMask, atlasXOffset);
|
||||
aOffset.y = dot(finalMask, atlasYOffset);
|
||||
|
||||
shadowCoord *= atlasScale;
|
||||
shadowCoord += aOffset;
|
||||
|
||||
// Each split has a different far plane, take this into account.
|
||||
float farPlaneScale = dot( farPlaneScalePSSM, finalMask );
|
||||
distToLight *= farPlaneScale;
|
||||
|
||||
float shadowed = softShadow_filter( ShadowMap,
|
||||
IN.uv0.xy,
|
||||
shadowCoord,
|
||||
farPlaneScale * shadowSoftness,
|
||||
distToLight,
|
||||
dotNL,
|
||||
dot( finalMask, overDarkPSSM ) );
|
||||
|
||||
// Fade out the shadow at the end of the range.
|
||||
float4 zDist = (zNearFarInvNearFar.x + zNearFarInvNearFar.y * depth);
|
||||
float fadeOutAmt = ( zDist.x - fadeStartLength.x ) * fadeStartLength.y;
|
||||
shadowed = lerp( shadowed, 1.0, saturate( fadeOutAmt ) );
|
||||
|
||||
#ifdef PSSM_DEBUG_RENDER
|
||||
if ( fadeOutAmt > 1.0 )
|
||||
debugColor = 1.0;
|
||||
#endif
|
||||
|
||||
#endif // !NO_SHADOW
|
||||
|
||||
// Specular term
|
||||
float specular = AL_CalcSpecular( -lightDirection,
|
||||
normal,
|
||||
normalize(-IN.vsEyeRay) ) * lightColor.a;
|
||||
|
||||
float Sat_NL_Att = saturate( dotNL * shadowed ) * lightBrightness;
|
||||
float3 lightColorOut = lightMapParams.rgb * lightColor.rgb;
|
||||
float4 addToResult = lightAmbient;
|
||||
|
||||
// TODO: This needs to be removed when lightmapping is disabled
|
||||
// as its extra work per-pixel on dynamic lit scenes.
|
||||
//
|
||||
// Special lightmapping pass.
|
||||
if ( lightMapParams.a < 0.0 )
|
||||
{
|
||||
// This disables shadows on the backsides of objects.
|
||||
shadowed = dotNL < 0.0f ? 1.0f : shadowed;
|
||||
|
||||
Sat_NL_Att = 1.0f;
|
||||
lightColorOut = shadowed;
|
||||
specular *= lightBrightness;
|
||||
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
|
||||
}
|
||||
|
||||
// Sample the AO texture.
|
||||
#ifdef USE_SSAO_MASK
|
||||
float ao = 1.0 - tex2D( ssaoMask, viewportCoordToRenderTarget( IN.uv0.xy, rtParams2 ) ).r;
|
||||
addToResult *= ao;
|
||||
#endif
|
||||
|
||||
#ifdef PSSM_DEBUG_RENDER
|
||||
lightColorOut = debugColor;
|
||||
#endif
|
||||
|
||||
return lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
varying vec2 uv;
|
||||
|
||||
uniform vec2 oneOverTargetSize;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 sNonUniformTaps[8];
|
||||
|
||||
sNonUniformTaps[0] = vec2(0.992833, 0.979309);
|
||||
sNonUniformTaps[1] = vec2(-0.998585, 0.985853);
|
||||
sNonUniformTaps[2] = vec2(0.949299, -0.882562);
|
||||
sNonUniformTaps[3] = vec2(-0.941358, -0.893924);
|
||||
sNonUniformTaps[4] = vec2(0.545055, -0.589072);
|
||||
sNonUniformTaps[5] = vec2(0.346526, 0.385821);
|
||||
sNonUniformTaps[6] = vec2(-0.260183, 0.334412);
|
||||
sNonUniformTaps[7] = vec2(0.248676, -0.679605);
|
||||
|
||||
gl_FragColor = vec4(0.0);
|
||||
|
||||
vec2 texScale = vec2(1.0);
|
||||
|
||||
for ( int i=0; i < 4; i++ )
|
||||
{
|
||||
vec2 offset = (oneOverTargetSize * texScale) * sNonUniformTaps[i];
|
||||
gl_FragColor += texture2D( diffuseMap, uv + offset );
|
||||
}
|
||||
|
||||
gl_FragColor /= vec4(4.0);
|
||||
gl_FragColor.rgb = vec3(0.0);
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../../../../shaders/common/gl/torque.glsl"
|
||||
|
||||
uniform vec2 oneOverTargetSize;
|
||||
uniform vec4 rtParams0;
|
||||
|
||||
varying vec2 uv;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = gl_Vertex;
|
||||
uv = viewportCoordToRenderTarget( gl_MultiTexCoord0.st, rtParams0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "shaders/common/postFx/postFx.hlsl"
|
||||
|
||||
uniform sampler2D diffuseMap : register(S0);
|
||||
|
||||
struct VertToPix
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
static float offset[3] = { 0.0, 1.3846153846, 3.2307692308 };
|
||||
static float weight[3] = { 0.2270270270, 0.3162162162, 0.0702702703 };
|
||||
|
||||
uniform float2 oneOverTargetSize;
|
||||
|
||||
float4 main( VertToPix IN ) : COLOR
|
||||
{
|
||||
float4 OUT = tex2D( diffuseMap, IN.uv ) * weight[0];
|
||||
|
||||
for ( int i=1; i < 3; i++ )
|
||||
{
|
||||
float2 sample = (BLUR_DIR * offset[i]) * oneOverTargetSize;
|
||||
OUT += tex2D( diffuseMap, IN.uv + sample ) * weight[i];
|
||||
OUT += tex2D( diffuseMap, IN.uv - sample ) * weight[i];
|
||||
}
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "../../../../../../shaders/common/postFx/postFx.hlsl"
|
||||
#include "../../../../../../shaders/common/torque.hlsl"
|
||||
|
||||
float4 rtParams0;
|
||||
|
||||
struct VertToPix
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
VertToPix main( PFXVert IN )
|
||||
{
|
||||
VertToPix OUT;
|
||||
|
||||
OUT.hpos = IN.pos;
|
||||
OUT.uv = viewportCoordToRenderTarget( IN.uv, rtParams0 );
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//*****************************************************************************
|
||||
// Box Filter
|
||||
//*****************************************************************************
|
||||
|
||||
struct ConnectData
|
||||
{
|
||||
float2 tex0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
// If not defined from ShaderData then define
|
||||
// the default blur kernel size here.
|
||||
//#ifndef blurSamples
|
||||
// #define blurSamples 4
|
||||
//#endif
|
||||
|
||||
float log_conv ( float x0, float X, float y0, float Y )
|
||||
{
|
||||
return (X + log(x0 + (y0 * exp(Y - X))));
|
||||
}
|
||||
|
||||
float4 main( ConnectData IN,
|
||||
uniform sampler2D diffuseMap0 : register(S0),
|
||||
uniform float texSize : register(C0),
|
||||
uniform float2 blurDimension : register(C2),
|
||||
uniform float2 blurBoundaries : register(C3)
|
||||
) : COLOR0
|
||||
{
|
||||
// 5x5
|
||||
if (IN.tex0.x <= blurBoundaries.x)
|
||||
{
|
||||
float texelSize = 1.2f / texSize;
|
||||
float2 sampleOffset = texelSize * blurDimension;
|
||||
//float2 offset = 0.5 * float( blurSamples ) * sampleOffset;
|
||||
|
||||
float2 texCoord = IN.tex0;
|
||||
|
||||
float accum = log_conv(0.3125, tex2D(diffuseMap0, texCoord - sampleOffset), 0.375, tex2D(diffuseMap0, texCoord));
|
||||
accum = log_conv(1, accum, 0.3125, tex2D(diffuseMap0, texCoord + sampleOffset));
|
||||
|
||||
return accum;
|
||||
} else {
|
||||
// 3x3
|
||||
if (IN.tex0.x <= blurBoundaries.y)
|
||||
{
|
||||
float texelSize = 1.3f / texSize;
|
||||
float2 sampleOffset = texelSize * blurDimension;
|
||||
//float2 offset = 0.5 * float( blurSamples ) * sampleOffset;
|
||||
|
||||
float2 texCoord = IN.tex0;
|
||||
float accum = log_conv(0.5, tex2D(diffuseMap0, texCoord - sampleOffset), 0.5, tex2D(diffuseMap0, texCoord + sampleOffset));
|
||||
|
||||
return accum;
|
||||
} else {
|
||||
return tex2D(diffuseMap0, IN.tex0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//*****************************************************************************
|
||||
// Box Filter
|
||||
//*****************************************************************************
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures
|
||||
//-----------------------------------------------------------------------------
|
||||
struct VertData
|
||||
{
|
||||
float2 texCoord : TEXCOORD0;
|
||||
float4 position : POSITION;
|
||||
};
|
||||
|
||||
struct ConnectData
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float2 tex0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
ConnectData main( VertData IN,
|
||||
uniform float4x4 modelview : register(C0))
|
||||
{
|
||||
ConnectData OUT;
|
||||
|
||||
OUT.hpos = mul(modelview, IN.position);
|
||||
OUT.tex0 = IN.texCoord;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define blurSamples 4.0
|
||||
|
||||
uniform sampler2D diffuseMap0;
|
||||
uniform float texSize;
|
||||
uniform vec2 blurDimension;
|
||||
|
||||
varying vec2 tex0;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Preshader
|
||||
float TexelSize = 1.0 / texSize;
|
||||
vec2 SampleOffset = TexelSize * blurDimension;
|
||||
vec2 Offset = 0.5 * float(blurSamples - 1.0) * SampleOffset;
|
||||
|
||||
vec2 BaseTexCoord = tex0 - Offset;
|
||||
|
||||
vec4 accum = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
for(int i = 0; i < int(blurSamples); i++)
|
||||
{
|
||||
accum += texture2D(diffuseMap0, BaseTexCoord + float(i) * SampleOffset);
|
||||
}
|
||||
accum /= blurSamples;
|
||||
gl_FragColor = accum;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform mat4 modelview;
|
||||
|
||||
varying vec2 tex0;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
tex0 = gl_MultiTexCoord0.st;
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//#define SM_Fmt_R8G8B8A8
|
||||
|
||||
#define pkDepthBitShft 65536.0
|
||||
#define pkDepthChanMax 256.0
|
||||
#define bias -0.5/255.0
|
||||
#define coeff 0.9999991
|
||||
//#define coeff 1.0
|
||||
|
||||
vec4 encodeShadowMap( float depth )
|
||||
{
|
||||
#if defined(SM_Fmt_R8G8B8A8)
|
||||
return frac( vec4(1.0, 255.0, 65025.0, 160581375.0) * depth ) + vec4(bias);
|
||||
|
||||
//float4 packedValue = frac((depth / coeff) * float4(16777216.0, 65536.0, 256.0, 1.0));
|
||||
//return (packedValue - packedValue.xxyz * float4(0, 1.0 / 256, 1.0 / 256, 1.0 / 256));
|
||||
#else
|
||||
return vec4(depth);
|
||||
#endif
|
||||
}
|
||||
|
||||
float decodeShadowMap( vec4 smSample )
|
||||
{
|
||||
#if defined(SM_Fmt_R8G8B8A8)
|
||||
return dot( smSample, vec4(1.0, 1/255.0, 1/65025.0, 1/160581375.0) );
|
||||
#else
|
||||
return smSample.x;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//#define SM_Fmt_R8G8B8A8
|
||||
|
||||
#define pkDepthBitShft 65536.0
|
||||
#define pkDepthChanMax 256.0
|
||||
#define bias -0.5/255.0
|
||||
#define coeff 0.9999991
|
||||
//#define coeff 1.0
|
||||
|
||||
float4 encodeShadowMap( float depth )
|
||||
{
|
||||
#if defined(SM_Fmt_R8G8B8A8)
|
||||
return frac( float4(1.0, 255.0, 65025.0, 160581375.0) * depth ) + bias;
|
||||
|
||||
//float4 packedValue = frac((depth / coeff) * float4(16777216.0, 65536.0, 256.0, 1.0));
|
||||
//return (packedValue - packedValue.xxyz * float4(0, 1.0 / 256, 1.0 / 256, 1.0 / 256));
|
||||
#else
|
||||
return depth;
|
||||
#endif
|
||||
}
|
||||
|
||||
float decodeShadowMap( float4 smSample )
|
||||
{
|
||||
#if defined(SM_Fmt_R8G8B8A8)
|
||||
return dot( smSample, float4(1.0, 1/255.0, 1/65025.0, 1/160581375.0) );
|
||||
#else
|
||||
return smSample.x;
|
||||
#endif
|
||||
}
|
||||
53
Templates/Empty/game/shaders/common/particleCompositeP.hlsl
Normal file
53
Templates/Empty/game/shaders/common/particleCompositeP.hlsl
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "torque.hlsl"
|
||||
|
||||
uniform sampler2D colorSource : register(S0);
|
||||
uniform float4 offscreenTargetParams;
|
||||
|
||||
#ifdef TORQUE_LINEAR_DEPTH
|
||||
#define REJECT_EDGES
|
||||
uniform sampler2D edgeSource : register(S1);
|
||||
uniform float4 edgeTargetParams;
|
||||
#endif
|
||||
|
||||
|
||||
float4 main( float4 offscreenPos : TEXCOORD0, float4 backbufferPos : TEXCOORD1 ) : COLOR
|
||||
{
|
||||
// Off-screen particle source screenspace position in XY
|
||||
// Back-buffer screenspace position in ZW
|
||||
float4 ssPos = float4(offscreenPos.xy / offscreenPos.w, backbufferPos.xy / backbufferPos.w);
|
||||
|
||||
float4 uvScene = ( ssPos + 1.0 ) / 2.0;
|
||||
uvScene.yw = 1.0 - uvScene.yw;
|
||||
uvScene.xy = viewportCoordToRenderTarget(uvScene.xy, offscreenTargetParams);
|
||||
|
||||
#ifdef REJECT_EDGES
|
||||
// Cut out particles along the edges, this will create the stencil mask
|
||||
uvScene.zw = viewportCoordToRenderTarget(uvScene.zw, edgeTargetParams);
|
||||
float edge = tex2D( edgeSource, uvScene.zw ).r;
|
||||
clip( -edge );
|
||||
#endif
|
||||
|
||||
// Sample offscreen target and return
|
||||
return tex2D( colorSource, uvScene.xy );
|
||||
}
|
||||
47
Templates/Empty/game/shaders/common/particleCompositeV.hlsl
Normal file
47
Templates/Empty/game/shaders/common/particleCompositeV.hlsl
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hlslStructs.h"
|
||||
|
||||
struct VertOut
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float4 offscreenPos : TEXCOORD0;
|
||||
float4 backbufferPos : TEXCOORD1;
|
||||
};
|
||||
|
||||
uniform float4 screenRect; // point, extent
|
||||
|
||||
VertOut main( float4 uvCoord : COLOR )
|
||||
{
|
||||
VertOut OUT;
|
||||
|
||||
OUT.hpos = float4(uvCoord.xy, 1.0, 1.0);
|
||||
OUT.hpos.xy *= screenRect.zw;
|
||||
OUT.hpos.xy += screenRect.xy;
|
||||
|
||||
OUT.backbufferPos = OUT.hpos;
|
||||
OUT.offscreenPos = OUT.hpos;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
||||
109
Templates/Empty/game/shaders/common/particlesP.hlsl
Normal file
109
Templates/Empty/game/shaders/common/particlesP.hlsl
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "torque.hlsl"
|
||||
|
||||
// With advanced lighting we get soft particles.
|
||||
#ifdef TORQUE_LINEAR_DEPTH
|
||||
#define SOFTPARTICLES
|
||||
#endif
|
||||
|
||||
#ifdef SOFTPARTICLES
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
uniform float oneOverSoftness;
|
||||
uniform float oneOverFar;
|
||||
uniform sampler2D prepassTex : register(S1);
|
||||
//uniform float3 vEye;
|
||||
uniform float4 prePassTargetParams;
|
||||
#endif
|
||||
|
||||
#define CLIP_Z // TODO: Make this a proper macro
|
||||
|
||||
struct Conn
|
||||
{
|
||||
float4 color : TEXCOORD0;
|
||||
float2 uv0 : TEXCOORD1;
|
||||
float4 pos : TEXCOORD2;
|
||||
};
|
||||
|
||||
uniform sampler2D diffuseMap : register(S0);
|
||||
|
||||
uniform sampler2D paraboloidLightMap : register(S2);
|
||||
|
||||
float4 lmSample( float3 nrm )
|
||||
{
|
||||
bool calcBack = (nrm.z < 0.0);
|
||||
if ( calcBack )
|
||||
nrm.z = nrm.z * -1.0;
|
||||
|
||||
float2 lmCoord;
|
||||
lmCoord.x = (nrm.x / (2*(1 + nrm.z))) + 0.5;
|
||||
lmCoord.y = 1-((nrm.y / (2*(1 + nrm.z))) + 0.5);
|
||||
|
||||
|
||||
// If this is the back, offset in the atlas
|
||||
if ( calcBack )
|
||||
lmCoord.x += 1.0;
|
||||
|
||||
// Atlasing front and back maps, so scale
|
||||
lmCoord.x *= 0.5;
|
||||
|
||||
return tex2D(paraboloidLightMap, lmCoord);
|
||||
}
|
||||
|
||||
|
||||
uniform float alphaFactor;
|
||||
uniform float alphaScale;
|
||||
|
||||
float4 main( Conn IN ) : COLOR
|
||||
{
|
||||
float softBlend = 1;
|
||||
|
||||
#ifdef SOFTPARTICLES
|
||||
float2 tc = IN.pos.xy * float2(1.0, -1.0) / IN.pos.w;
|
||||
tc = viewportCoordToRenderTarget(saturate( ( tc + 1.0 ) * 0.5 ), prePassTargetParams);
|
||||
|
||||
float sceneDepth = prepassUncondition( prepassTex, tc ).w;
|
||||
float depth = IN.pos.w * oneOverFar;
|
||||
float diff = sceneDepth - depth;
|
||||
#ifdef CLIP_Z
|
||||
// If drawing offscreen, this acts as the depth test, since we don't line up with the z-buffer
|
||||
// When drawing high-res, though, we want to be able to take advantage of hi-z
|
||||
// so this is #ifdef'd out
|
||||
//clip(diff);
|
||||
#endif
|
||||
softBlend = saturate( diff * oneOverSoftness );
|
||||
#endif
|
||||
|
||||
float4 diffuse = tex2D( diffuseMap, IN.uv0 );
|
||||
|
||||
//return float4( lmSample(float3(0, 0, -1)).rgb, IN.color.a * diffuse.a * softBlend * alphaScale);
|
||||
|
||||
// Scale output color by the alpha factor (turn LerpAlpha into pre-multiplied alpha)
|
||||
float3 colorScale = ( alphaFactor < 0.0 ? IN.color.rgb * diffuse.rgb : ( alphaFactor > 0.0 ? IN.color.a * diffuse.a * alphaFactor * softBlend : softBlend ) );
|
||||
|
||||
return hdrEncode( float4( IN.color.rgb * diffuse.rgb * colorScale,
|
||||
IN.color.a * diffuse.a * softBlend * alphaScale ) );
|
||||
}
|
||||
|
||||
53
Templates/Empty/game/shaders/common/particlesV.hlsl
Normal file
53
Templates/Empty/game/shaders/common/particlesV.hlsl
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
float4 pos : POSITION;
|
||||
float4 color : COLOR0;
|
||||
float2 uv0 : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct Conn
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float4 color : TEXCOORD0;
|
||||
float2 uv0 : TEXCOORD1;
|
||||
float4 pos : TEXCOORD2;
|
||||
};
|
||||
|
||||
|
||||
uniform float4x4 modelViewProj;
|
||||
uniform float4x4 fsModelViewProj;
|
||||
|
||||
Conn main( Vertex In )
|
||||
{
|
||||
Conn Out;
|
||||
|
||||
Out.hpos = mul( modelViewProj, In.pos );
|
||||
Out.pos = mul( fsModelViewProj, In.pos );
|
||||
Out.color = In.color;
|
||||
Out.uv0 = In.uv0;
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
83
Templates/Empty/game/shaders/common/planarReflectBumpP.hlsl
Normal file
83
Templates/Empty/game/shaders/common/planarReflectBumpP.hlsl
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ConnectData
|
||||
{
|
||||
float4 texCoord : TEXCOORD0;
|
||||
float2 tex2 : TEXCOORD1;
|
||||
};
|
||||
|
||||
|
||||
struct Fragout
|
||||
{
|
||||
float4 col : COLOR0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Fade edges of axis for texcoord passed in
|
||||
//-----------------------------------------------------------------------------
|
||||
float fadeAxis( float val )
|
||||
{
|
||||
// Fades from 1.0 to 0.0 when less than 0.1
|
||||
float fadeLow = saturate( val * 10.0 );
|
||||
|
||||
// Fades from 1.0 to 0.0 when greater than 0.9
|
||||
float fadeHigh = 1.0 - saturate( (val - 0.9) * 10.0 );
|
||||
|
||||
return fadeLow * fadeHigh;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
Fragout main( ConnectData IN,
|
||||
uniform sampler2D refractMap : register(S1),
|
||||
uniform sampler2D texMap : register(S0),
|
||||
uniform sampler2D bumpMap : register(S2)
|
||||
)
|
||||
{
|
||||
Fragout OUT;
|
||||
|
||||
float3 bumpNorm = tex2D( bumpMap, IN.tex2 ) * 2.0 - 1.0;
|
||||
float2 offset = float2( bumpNorm.x, bumpNorm.y );
|
||||
float4 texIndex = IN.texCoord;
|
||||
|
||||
// The fadeVal is used to "fade" the distortion at the edges of the screen.
|
||||
// This is done so it won't sample the reflection texture out-of-bounds and create artifacts
|
||||
// Note - this can be done more efficiently with a texture lookup
|
||||
float fadeVal = fadeAxis( texIndex.x / texIndex.w ) * fadeAxis( texIndex.y / texIndex.w );
|
||||
|
||||
const float distortion = 0.2;
|
||||
texIndex.xy += offset * distortion * fadeVal;
|
||||
|
||||
float4 reflectColor = tex2Dproj( refractMap, texIndex );
|
||||
float4 diffuseColor = tex2D( texMap, IN.tex2 );
|
||||
|
||||
OUT.col = diffuseColor + reflectColor * diffuseColor.a;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
66
Templates/Empty/game/shaders/common/planarReflectBumpV.hlsl
Normal file
66
Templates/Empty/game/shaders/common/planarReflectBumpV.hlsl
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define IN_HLSL
|
||||
#include "shdrConsts.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures
|
||||
//-----------------------------------------------------------------------------
|
||||
struct VertData
|
||||
{
|
||||
float2 texCoord : TEXCOORD0;
|
||||
float2 lmCoord : TEXCOORD1;
|
||||
float3 T : TEXCOORD2;
|
||||
float3 B : TEXCOORD3;
|
||||
float3 normal : NORMAL;
|
||||
float4 position : POSITION;
|
||||
};
|
||||
|
||||
|
||||
struct ConnectData
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float4 texCoord : TEXCOORD0;
|
||||
float2 tex2 : TEXCOORD1;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
ConnectData main( VertData IN,
|
||||
uniform float4x4 modelview )
|
||||
{
|
||||
ConnectData OUT;
|
||||
OUT.hpos = mul(modelview, IN.position);
|
||||
|
||||
float4x4 texGenTest = { 0.5, 0.0, 0.0, 0.5,
|
||||
0.0, -0.5, 0.0, 0.5,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0 };
|
||||
|
||||
OUT.texCoord = mul( texGenTest, OUT.hpos );
|
||||
|
||||
OUT.tex2 = IN.texCoord;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
55
Templates/Empty/game/shaders/common/planarReflectP.hlsl
Normal file
55
Templates/Empty/game/shaders/common/planarReflectP.hlsl
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures
|
||||
//-----------------------------------------------------------------------------
|
||||
struct ConnectData
|
||||
{
|
||||
float2 texCoord : TEXCOORD0;
|
||||
float4 tex2 : TEXCOORD1;
|
||||
};
|
||||
|
||||
|
||||
struct Fragout
|
||||
{
|
||||
float4 col : COLOR0;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
Fragout main( ConnectData IN,
|
||||
uniform sampler2D texMap : register(S0),
|
||||
uniform sampler2D refractMap : register(S1)
|
||||
)
|
||||
{
|
||||
Fragout OUT;
|
||||
|
||||
float4 diffuseColor = tex2D( texMap, IN.texCoord );
|
||||
float4 reflectColor = tex2Dproj( refractMap, IN.tex2 );
|
||||
|
||||
OUT.col = diffuseColor + reflectColor * diffuseColor.a;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
56
Templates/Empty/game/shaders/common/planarReflectV.hlsl
Normal file
56
Templates/Empty/game/shaders/common/planarReflectV.hlsl
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define IN_HLSL
|
||||
#include "hlslStructs.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Structures
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct ConnectData
|
||||
{
|
||||
float4 hpos : POSITION;
|
||||
float2 texCoord : TEXCOORD0;
|
||||
float4 tex2 : TEXCOORD1;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
ConnectData main( VertexIn_PNTTTB IN,
|
||||
uniform float4x4 modelview : register(C0)
|
||||
)
|
||||
{
|
||||
ConnectData OUT;
|
||||
OUT.hpos = mul(modelview, IN.pos);
|
||||
|
||||
float4x4 texGenTest = { 0.5, 0.0, 0.0, 0.5,
|
||||
0.0, -0.5, 0.0, 0.5,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.0, 0.0, 0.0, 1.0 };
|
||||
|
||||
OUT.texCoord = IN.uv0;
|
||||
OUT.tex2 = mul( texGenTest, OUT.hpos );
|
||||
|
||||
return OUT;
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Based on 'Cubic Lens Distortion HLSL Shader' by François Tarlier
|
||||
// www.francois-tarlier.com/blog/index.php/2009/11/cubic-lens-distortion-shader
|
||||
|
||||
#include "./postFx.hlsl"
|
||||
#include "./../torque.hlsl"
|
||||
|
||||
|
||||
uniform sampler2D backBuffer : register( s0 );
|
||||
uniform float distCoeff;
|
||||
uniform float cubeDistort;
|
||||
uniform float3 colorDistort;
|
||||
|
||||
|
||||
float4 main( PFXVertToPix IN ) : COLOR0
|
||||
{
|
||||
float2 tex = IN.uv0;
|
||||
|
||||
float f = 0;
|
||||
float r2 = (tex.x - 0.5) * (tex.x - 0.5) + (tex.y - 0.5) * (tex.y - 0.5);
|
||||
|
||||
// Only compute the cubic distortion if necessary.
|
||||
if ( cubeDistort == 0.0 )
|
||||
f = 1 + r2 * distCoeff;
|
||||
else
|
||||
f = 1 + r2 * (distCoeff + cubeDistort * sqrt(r2));
|
||||
|
||||
// Distort each color channel seperately to get a chromatic distortion effect.
|
||||
float3 outColor;
|
||||
float3 distort = f.xxx + colorDistort;
|
||||
|
||||
for ( int i=0; i < 3; i++ )
|
||||
{
|
||||
float x = distort[i] * ( tex.x - 0.5 ) + 0.5;
|
||||
float y = distort[i] * ( tex.y - 0.5 ) + 0.5;
|
||||
outColor[i] = tex2Dlod( backBuffer, float4(x,y,0,0) )[i];
|
||||
}
|
||||
|
||||
return float4( outColor.rgb, 1 );
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "./../postFx.hlsl"
|
||||
|
||||
// These are set by the game engine.
|
||||
uniform sampler2D shrunkSampler : register(S0); // Output of DofDownsample()
|
||||
uniform sampler2D blurredSampler : register(S1); // Blurred version of the shrunk sampler
|
||||
|
||||
// This is the pixel shader function that calculates the actual
|
||||
// value used for the near circle of confusion.
|
||||
// "texCoords" are 0 at the bottom left pixel and 1 at the top right.
|
||||
float4 main( PFXVertToPix IN ) : COLOR
|
||||
{
|
||||
float3 color;
|
||||
float coc;
|
||||
half4 blurred;
|
||||
half4 shrunk;
|
||||
|
||||
shrunk = tex2D( shrunkSampler, IN.uv0 );
|
||||
blurred = tex2D( blurredSampler, IN.uv1 );
|
||||
color = shrunk.rgb;
|
||||
//coc = shrunk.a;
|
||||
//coc = blurred.a;
|
||||
//coc = max( blurred.a, shrunk.a );
|
||||
coc = 2 * max( blurred.a, shrunk.a ) - shrunk.a;
|
||||
|
||||
|
||||
//return float4( coc.rrr, 1.0 );
|
||||
//return float4( color, 1.0 );
|
||||
return float4( color, coc );
|
||||
//return float4( 1.0, 0.0, 1.0, 1.0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "./../postFx.hlsl"
|
||||
#include "./../../torque.hlsl"
|
||||
|
||||
uniform float4 rtParams0;
|
||||
uniform float4 rtParams1;
|
||||
uniform float4 rtParams2;
|
||||
uniform float4 rtParams3;
|
||||
|
||||
PFXVertToPix main( PFXVert IN )
|
||||
{
|
||||
PFXVertToPix OUT;
|
||||
|
||||
/*
|
||||
OUT.hpos = IN.pos;
|
||||
OUT.uv0 = IN.uv;
|
||||
OUT.uv1 = IN.uv;
|
||||
OUT.uv2 = IN.uv;
|
||||
OUT.uv3 = IN.uv;
|
||||
*/
|
||||
|
||||
/*
|
||||
OUT.hpos = IN.pos;
|
||||
OUT.uv0 = IN.uv + rtParams0.xy;
|
||||
OUT.uv1 = IN.uv + rtParams1.xy;
|
||||
OUT.uv2 = IN.uv + rtParams2.xy;
|
||||
OUT.uv3 = IN.uv + rtParams3.xy;
|
||||
*/
|
||||
|
||||
/*
|
||||
OUT.hpos = IN.pos;
|
||||
OUT.uv0 = IN.uv * rtParams0.zw;
|
||||
OUT.uv1 = IN.uv * rtParams1.zw;
|
||||
OUT.uv2 = IN.uv * rtParams2.zw;
|
||||
OUT.uv3 = IN.uv * rtParams3.zw;
|
||||
*/
|
||||
|
||||
|
||||
OUT.hpos = IN.pos;
|
||||
OUT.uv0 = viewportCoordToRenderTarget( IN.uv, rtParams0 );
|
||||
OUT.uv1 = viewportCoordToRenderTarget( IN.uv, rtParams1 );
|
||||
OUT.uv2 = viewportCoordToRenderTarget( IN.uv, rtParams2 );
|
||||
OUT.uv3 = viewportCoordToRenderTarget( IN.uv, rtParams3 );
|
||||
|
||||
|
||||
OUT.wsEyeRay = IN.wsEyeRay;
|
||||
|
||||
return OUT;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue