Initial implementation of the new Base Game Template and some starting modules.

This makes some tweaks to the engine to support this, specifically, it tweaks the hardcoded shaderpaths to defer to a pref variable, so none of the shader paths are hardcoded.

Also tweaks how post effects read in texture files, removing a bizzare filepath interpretation choice, where if the file path didn't start with "/" it forcefully appended the script's file path. This made it impossible to have images not in the same dir as the script file defining the post effect.

This was changed and the existing template's post effects tweaked for now to just add "./" to those few paths impacted, as well as the perf vars to support the non-hardcoded shader paths in the engine.
This commit is contained in:
Areloch 2017-02-24 02:40:56 -06:00
parent 5c8a82180b
commit 1ed8b05169
1572 changed files with 146699 additions and 85 deletions

View file

@ -0,0 +1,87 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Volumetric Fog final pixel shader V2.00
#include "../shaderModel.hlsl"
#include "../shaderModelAutoGen.hlsl"
#include "../torque.hlsl"
TORQUE_UNIFORM_SAMPLER2D(prepassTex, 0);
TORQUE_UNIFORM_SAMPLER2D(depthBuffer, 1);
TORQUE_UNIFORM_SAMPLER2D(frontBuffer, 2);
TORQUE_UNIFORM_SAMPLER2D(density, 3);
uniform float3 ambientColor;
uniform float accumTime;
uniform float4 fogColor;
uniform float4 modspeed;//xy speed layer 1, zw speed layer 2
uniform float2 viewpoint;
uniform float2 texscale;
uniform float fogDensity;
uniform float preBias;
uniform float textured;
uniform float modstrength;
uniform float numtiles;
uniform float fadesize;
uniform float2 PixelSize;
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 htpos : TEXCOORD0;
float2 uv0 : TEXCOORD1;
};
float4 main( ConnectData IN ) : TORQUE_TARGET0
{
float2 uvscreen=((IN.htpos.xy/IN.htpos.w) + 1.0 ) / 2.0;
uvscreen.y = 1.0 - uvscreen.y;
float obj_test = TORQUE_PREPASS_UNCONDITION(prepassTex, uvscreen).w * preBias;
float depth = TORQUE_TEX2D(depthBuffer, uvscreen).r;
float front = TORQUE_TEX2D(frontBuffer, uvscreen).r;
if (depth <= front)
return float4(0,0,0,0);
else if ( obj_test < depth )
depth = obj_test;
if ( front >= 0.0)
depth -= front;
float diff = 1.0;
float3 col = fogColor.rgb;
if (textured != 0.0)
{
float2 offset = viewpoint + ((-0.5 + (texscale * uvscreen)) * numtiles);
float2 mod1 = TORQUE_TEX2D(density, (offset + (modspeed.xy*accumTime))).rg;
float2 mod2 = TORQUE_TEX2D(density, (offset + (modspeed.zw*accumTime))).rg;
diff = (mod2.r + mod1.r) * modstrength;
col *= (2.0 - ((mod1.g + mod2.g) * fadesize))/2.0;
}
col *= ambientColor;
float4 resultColor = float4(col, 1.0 - saturate(exp(-fogDensity * depth * diff * fadesize)));
return hdrEncode(resultColor);
}

View file

@ -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.
//-----------------------------------------------------------------------------
// Volumetric Fog prepass pixel shader V1.00
#include "../shaderModel.hlsl"
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 pos : TEXCOORD0;
};
float4 main( ConnectData IN ) : TORQUE_TARGET0
{
float OUT;
clip( IN.pos.w );
OUT = IN.pos.w;
return float4(OUT,0,0,1);
}

View 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.
//-----------------------------------------------------------------------------
// Volumetric Fog prepass vertex shader V1.00
#include "../shaderModel.hlsl"
#include "../hlslStructs.hlsl"
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 pos : TEXCOORD0;
};
uniform float4x4 modelView;
ConnectData main( VertexIn_P IN)
{
ConnectData OUT;
OUT.hpos = mul(modelView, float4(IN.pos, 1.0));
OUT.pos = OUT.hpos;
return OUT;
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------
// Volumetric Fog Reflection pixel shader V1.00
#include "../shaderModel.hlsl"
uniform float4 fogColor;
uniform float fogDensity;
uniform float reflStrength;
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 pos : TEXCOORD0;
};
float4 main( ConnectData IN ) : TORQUE_TARGET0
{
return float4(fogColor.rgb,saturate(fogDensity*reflStrength));
}

View 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.
//-----------------------------------------------------------------------------
// Volumetric Fog final vertex shader V1.00
#include "../shaderModel.hlsl"
#include "../hlslStructs.hlsl"
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float4 htpos : TEXCOORD0;
float2 uv0 : TEXCOORD1;
};
uniform float4x4 modelView;
ConnectData main( VertexIn_PNTT IN)
{
ConnectData OUT;
OUT.hpos = mul(modelView, float4(IN.pos,1.0));
OUT.htpos = OUT.hpos;
OUT.uv0 = IN.uv0;
return OUT;
}

View file

@ -0,0 +1,87 @@
//-----------------------------------------------------------------------------
// 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 "../../gl/torque.glsl"
uniform sampler2D prepassTex;
uniform sampler2D depthBuffer;
uniform sampler2D frontBuffer;
uniform sampler2D density;
uniform float accumTime;
uniform vec4 fogColor;
uniform float fogDensity;
uniform float preBias;
uniform float textured;
uniform float modstrength;
uniform vec4 modspeed;//xy speed layer 1, zw speed layer 2
uniform vec2 viewpoint;
uniform vec2 texscale;
uniform vec3 ambientColor;
uniform float numtiles;
uniform float fadesize;
uniform vec2 PixelSize;
in vec4 _hpos;
#define IN_hpos _hpos
out vec4 OUT_col;
void main()
{
vec2 uvscreen=((IN_hpos.xy/IN_hpos.w) + 1.0 ) / 2.0;
uvscreen.y = 1.0 - uvscreen.y;
float obj_test = prepassUncondition( prepassTex, uvscreen).w * preBias;
float depth = tex2D(depthBuffer,uvscreen).r;
float front = tex2D(frontBuffer,uvscreen).r;
if (depth <= front)
{
OUT_col = vec4(0,0,0,0);
return;
}
else if ( obj_test < depth )
depth = obj_test;
if ( front >= 0.0)
depth -= front;
float diff = 1.0;
vec3 col = fogColor.rgb;
if (textured != 0.0)
{
vec2 offset = viewpoint + ((-0.5 + (texscale * uvscreen)) * numtiles);
vec2 mod1 = tex2D(density,(offset + (modspeed.xy*accumTime))).rg;
vec2 mod2= tex2D(density,(offset + (modspeed.zw*accumTime))).rg;
diff = (mod2.r + mod1.r) * modstrength;
col *= (2.0 - ((mod1.g + mod2.g) * fadesize))/2.0;
}
col *= ambientColor;
vec4 returnColor = vec4(col, 1.0 - saturate(exp(-fogDensity * depth * diff * fadesize)));
OUT_col = hdrEncode(returnColor);
}

View 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 "../../gl/hlslCompat.glsl"
in vec4 _hpos;
#define IN_hpos _hpos
out vec4 OUT_col;
void main()
{
float OUT;
clip( IN_hpos.w );
OUT = IN_hpos.w;
OUT_col = vec4(OUT,0,0,1);
}

View file

@ -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 "../../gl/hlslCompat.glsl"
in vec4 vPosition;
#define IN_position vPosition
out vec4 _hpos;
#define OUT_hpos _hpos
uniform mat4 modelView;
void main()
{
vec4 inPos = IN_position;
inPos.w = 1.0;
OUT_hpos = tMul( modelView, inPos );
gl_Position = OUT_hpos;
correctSSP(gl_Position);
}

View 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.
//-----------------------------------------------------------------------------
#include "../../gl/hlslCompat.glsl"
uniform vec4 fogColor;
uniform float fogDensity;
uniform float reflStrength;
out vec4 OUT_col;
void main()
{
OUT_col = vec4(fogColor.rgb,saturate(fogDensity*reflStrength));
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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"
in vec4 vPosition;
#define IN_position vPosition
out vec4 _hpos;
#define OUT_hpos _hpos
uniform mat4 modelView;
void main()
{
OUT_hpos = tMul(modelView, IN_position);
gl_Position = OUT_hpos;
correctSSP(gl_Position);
}

View 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 : TORQUE_POSITION;
float2 texCoord : TEXCOORD0;
};
TORQUE_UNIFORM_SAMPLER2D(diffuseMap, 0);
float4 main( ConnectData IN ) : TORQUE_TARGET0
{
float4 col = TORQUE_TEX2D(diffuseMap, IN.texCoord);
return hdrEncode( col );
}

View 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.
//-----------------------------------------------------------------------------
#include "shaderModel.hlsl"
struct CloudVert
{
float3 pos : POSITION;
float2 uv0 : TEXCOORD0;
};
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float2 texCoord : TEXCOORD0;
};
uniform float4x4 modelview;
uniform float2 texDirection;
uniform float2 texOffset;
uniform float accumTime;
uniform float texScale;
ConnectData main( CloudVert IN )
{
ConnectData OUT;
OUT.hpos = mul(modelview, float4(IN.pos,1.0));
float2 uv = IN.uv0;
uv += texOffset;
uv *= texScale;
uv += accumTime * texDirection;
OUT.texCoord = uv;
return OUT;
}

View file

@ -0,0 +1,146 @@
//-----------------------------------------------------------------------------
// 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 "shaderModel.hlsl"
#include "torque.hlsl"
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct ConnectData
{
float4 hpos : TORQUE_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
//-----------------------------------------------------------------------------
TORQUE_UNIFORM_SAMPLER2D(normalHeightMap, 0);
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 ) : TORQUE_TARGET0
{
// 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 = TORQUE_TEX2D( normalHeightMap, IN.texCoord12.zw );
noise1 = normalize( ( noise1 - 0.5 ) * 2.0 );
//return noise1;
float4 noise2 = TORQUE_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( TORQUE_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 = TORQUE_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 );
}

View 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
//-----------------------------------------------------------------------------
#include "shaderModel.hlsl"
struct CloudVert
{
float3 pos : POSITION;
float3 normal : NORMAL;
float3 binormal : BINORMAL;
float3 tangent : TANGENT;
float2 uv0 : TEXCOORD0;
};
struct ConnectData
{
float4 hpos : TORQUE_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, float4(IN.pos,1.0));
// 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 = float4(IN.pos, 1.0) + 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;
}

View 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 "../shaderModel.hlsl"
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
TORQUE_UNIFORM_SAMPLER2D(diffuseMap, 0);
float4 main( Conn IN ) : TORQUE_TARGET0
{
return float4(IN.color.rgb, IN.color.a * TORQUE_TEX2D(diffuseMap, IN.texCoord).a);
}

View 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.
//-----------------------------------------------------------------------------
#include "../shaderModel.hlsl"
struct Appdata
{
float3 position : POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
uniform float4x4 modelview;
Conn main( Appdata In )
{
Conn Out;
Out.HPOS = mul(modelview, float4(In.position,1.0));
Out.color = In.color;
Out.texCoord = In.texCoord;
return Out;
}

View 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.
//-----------------------------------------------------------------------------
#include "../shaderModel.hlsl"
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
};
float4 main(Conn IN) : TORQUE_TARGET0
{
return IN.color;
}

View file

@ -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.
//-----------------------------------------------------------------------------
#include "../shaderModel.hlsl"
struct Appdata
{
float3 position : POSITION;
float4 color : COLOR;
};
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
};
uniform float4x4 modelview;
Conn main( Appdata In )
{
Conn Out;
Out.HPOS = mul(modelview, float4(In.position,1.0));
Out.color = In.color;
return Out;
}

View file

@ -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.
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;
out vec4 OUT_col;
void main()
{
OUT_col = vec4(color.rgb, color.a * texture(diffuseMap, texCoord).a);
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec4 color;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
texCoord = vTexCoord0.st;
}

View file

@ -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.
//-----------------------------------------------------------------------------
in vec4 color;
out vec4 OUT_col;
void main()
{
OUT_col = color;
}

View 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.
//-----------------------------------------------------------------------------
#include "../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec4 vColor;
uniform mat4 modelview;
out vec4 color;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
}

View file

@ -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.
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;
out vec4 OUT_col;
void main()
{
OUT_col = texture(diffuseMap, texCoord) * color;
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec4 color;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
color = vColor;
texCoord = vTexCoord0.st;
}

View file

@ -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 ;
vec4 main( vec2 ScreenPos : VPOS ) : COLOR0
{
vec2 TexCoord = ScreenPos;
vec4 diffuse;
asm { tfetch2D diffuse, TexCoord, colorTarget0Texture, UnnormalizedTextureCoords = true };
return diffuse;
}

View file

@ -0,0 +1,22 @@
//-----------------------------------------------------------------------------
// 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.
//-----------------------------------------------------------------------------

View file

@ -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 diffuseMap;
in vec2 texCoord;
out vec4 OUT_col;
void main()
{
OUT_col = texture(diffuseMap, texCoord);
}

View 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.
//-----------------------------------------------------------------------------
#include "../../gl/hlslCompat.glsl"
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec2 texCoord;
void main()
{
gl_Position = tMul(modelview, vPosition);
correctSSP(gl_Position);
texCoord = vTexCoord0.st;
}

View 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 "../shaderModel.hlsl"
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
TORQUE_UNIFORM_SAMPLER2D(diffuseMap, 0);
float4 main( Conn IN ) : TORQUE_TARGET0
{
return TORQUE_TEX2D(diffuseMap, IN.texCoord) * IN.color;
}

View 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.
//-----------------------------------------------------------------------------
#include "../shaderModel.hlsl"
struct Appdata
{
float3 position : POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
struct Conn
{
float4 HPOS : TORQUE_POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
uniform float4x4 modelview;
Conn main( Appdata In )
{
Conn Out;
Out.HPOS = mul(modelview, float4(In.position,1.0));
Out.color = In.color;
Out.texCoord = In.texCoord;
return Out;
}

View file

@ -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;
}

View file

@ -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 );
}

View file

@ -0,0 +1,36 @@
//-----------------------------------------------------------------------------
// 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 "../shaderModel.hlsl"
TORQUE_UNIFORM_SAMPLER2D(diffuseMap, 0);
struct Conn
{
float4 hpos : TORQUE_POSITION;
float2 texCoord : TEXCOORD0;
};
float4 main(Conn IN) : TORQUE_TARGET0
{
return TORQUE_TEX2D(diffuseMap, IN.texCoord);
}

View 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.
//-----------------------------------------------------------------------------
#include "../shaderModel.hlsl"
struct Appdata
{
float3 position : POSITION;
float4 color : COLOR;
float2 texCoord : TEXCOORD0;
};
struct Conn
{
float4 hpos : TORQUE_POSITION;
float2 texCoord : TEXCOORD0;
};
uniform float4x4 modelview;
Conn main( Appdata In )
{
Conn Out;
Out.hpos = mul(modelview, float4(In.position, 1.0));
Out.texCoord = In.texCoord;
return Out;
}

View 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 float2 gc_fadeParams;
uniform float2 gc_windDir;
uniform float3 gc_camRight;
uniform float3 gc_camUp;
uniform float4 gc_typeRects[MAX_COVERTYPES];
// .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 );
}

View file

@ -0,0 +1,60 @@
//-----------------------------------------------------------------------------
// 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"
#include "shaderModel.hlsl"
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float2 outTexCoord : TEXCOORD0;
float4 color : COLOR0;
float4 groundAlphaCoeff : COLOR1;
float2 alphaLookup : TEXCOORD1;
};
struct Fragout
{
float4 col : TORQUE_TARGET0;
};
TORQUE_UNIFORM_SAMPLER2D(diffuseMap, 0);
TORQUE_UNIFORM_SAMPLER2D(alphaMap, 1);
uniform float4 groundAlpha;
uniform float4 ambient;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Fragout main( ConnectData IN )
{
Fragout OUT;
float4 alpha = TORQUE_TEX2D(alphaMap, IN.alphaLookup);
OUT.col = float4( ambient.rgb * IN.lum.rgb, 1.0 ) * TORQUE_TEX2D(diffuseMap, IN.texCoord);
OUT.col.a = OUT.col.a * min(alpha, groundAlpha + IN.groundAlphaCoeff.x).x;
return OUT;
}

View file

@ -0,0 +1,129 @@
//-----------------------------------------------------------------------------
// 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
//-----------------------------------------------------------------------------
#include "shaderModel.hlsl"
struct VertData
{
float3 position : POSITION;
float3 normal : NORMAL;
float2 texCoord : TEXCOORD0;
float2 waveScale : TEXCOORD1;
};
struct ConnectData
{
float4 hpos : TORQUE_POSITION;
float2 outTexCoord : TEXCOORD0;
float4 color : COLOR0;
float4 groundAlphaCoeff : COLOR1;
float2 alphaLookup : TEXCOORD1;
};
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);
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
ConnectData main( VertData IN )
{
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 = IN.position;
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;
}

View file

@ -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.
//-----------------------------------------------------------------------------
#include "torque.glsl"
#include "hlslCompat.glsl"
//ConnectData
in vec2 texCoord;
#define IN_texCoord texCoord
uniform sampler2D diffuseMap ;
out vec4 OUT_col;
void main()
{
vec4 col = texture( diffuseMap, IN_texCoord );
OUT_col = hdrEncode( col );
}

View 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 "hlslCompat.glsl"
//CloudVert
in vec4 vPosition;
in vec2 vTexCoord0;
#define IN_pos vPosition
#define IN_uv0 vTexCoord0
uniform mat4 modelview;
uniform float accumTime;
uniform float texScale;
uniform vec2 texDirection;
uniform vec2 texOffset;
out vec2 texCoord;
#define OUT_texCoord texCoord
void main()
{
gl_Position = tMul(modelview, IN_pos);
vec2 uv = IN_uv0;
uv += texOffset;
uv *= texScale;
uv += accumTime * texDirection;
OUT_texCoord = uv;
correctSSP(gl_Position);
}

View file

@ -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.
//-----------------------------------------------------------------------------
//*****************************************************************************
// Glow Shader
//*****************************************************************************
uniform vec4 kernel;
uniform sampler2D diffuseMap;
in vec2 texc0, texc1, texc2, texc3;
out vec4 OUT_col;
void main()
{
OUT_col = texture(diffuseMap, texc0) * kernel.x;
OUT_col += texture(diffuseMap, texc1) * kernel.y;
OUT_col += texture(diffuseMap, texc2) * kernel.z;
OUT_col += texture(diffuseMap, texc3) * kernel.w;
}

View 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.
//-----------------------------------------------------------------------------
//*****************************************************************************
// Glow shader
//*****************************************************************************
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
uniform mat4 modelview;
uniform vec2 offset0, offset1, offset2, offset3;
out vec2 texc0, texc1, texc2, texc3;
void main()
{
gl_Position = modelview * vPosition;
vec2 tc = vTexCoord0.st;
tc.y = 1.0 - tc.y;
texc0 = tc + offset0;
texc1 = tc + offset1;
texc2 = tc + offset2;
texc3 = tc + offset3;
gl_Position.y *= -1;
}

View file

@ -0,0 +1,147 @@
//-----------------------------------------------------------------------------
// 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"
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
//ConnectData
in vec4 texCoord12;
#define IN_texCoord12 texCoord12
in vec4 texCoord34;
#define IN_texCoord34 texCoord34
in vec3 vLightTS; // light vector in tangent space, denormalized
#define IN_vLightTS vLightTS
in vec3 vViewTS; // view vector in tangent space, denormalized
#define IN_vViewTS vViewTS
in float worldDist;
#define IN_worldDist worldDist
//-----------------------------------------------------------------------------
// Uniforms
//-----------------------------------------------------------------------------
uniform sampler2D normalHeightMap;
uniform vec3 ambientColor;
uniform vec3 sunColor;
uniform float cloudCoverage;
uniform vec3 cloudBaseColor;
uniform float cloudExposure;
out vec4 OUT_col;
//-----------------------------------------------------------------------------
// 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 );
vec4 cResultColor = vec4( 0, 0, 0, 1 );
vec2 texSample = IN_texCoord12.xy;
vec4 noise1 = texture( normalHeightMap, IN_texCoord12.zw );
noise1 = normalize( ( noise1 - 0.5 ) * 2.0 );
//return noise1;
vec4 noise2 = texture( normalHeightMap, IN_texCoord34.xy );
noise2 = normalize( ( noise2 - 0.5 ) * 2.0 );
//return noise2;
vec3 noiseNormal = normalize( noise1 + noise2 ).xyz;
//return vec4( noiseNormal, 1.0 );
float noiseHeight = noise1.a * noise2.a * ( cloudCoverage / 2.0 + 0.5 );
vec3 vNormalTS = normalize( texture( 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 = texture( normalHeightMap, texSample ).a + coverage + noiseHeight;
if ( cloudCoverage > -1.0 )
cResultColor.a /= 1.0 + coverage;
cResultColor.a = clamp( cResultColor.a * pow( saturate(cloudCoverage), 0.25 ), 0.0, 1.0 );
cResultColor.a = mix( cResultColor.a, 0.0, 1.0 - pow(IN_worldDist,2.0) );
OUT_col = hdrEncode(cResultColor);
}

View 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.
//-----------------------------------------------------------------------------
#include "hlslCompat.glsl"
in vec4 vPosition;
in vec3 vNormal;
in vec3 vBinormal;
in vec3 vTangent;
in vec2 vTexCoord0;
out vec4 texCoord12;
#define OUT_texCoord12 texCoord12
out vec4 texCoord34;
#define OUT_texCoord34 texCoord34
out vec3 vLightTS; // light vector in tangent space, denormalized
#define OUT_vLightTS vLightTS
out vec3 vViewTS; // view vector in tangent space, denormalized
#define OUT_vViewTS vViewTS
out float worldDist;
#define OUT_worldDist 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 IN_pos = vPosition;
vec3 IN_normal = vNormal;
vec3 IN_binormal = vBinormal;
vec3 IN_tangent = vTangent;
vec2 IN_uv0 = vTexCoord0.st;
gl_Position = modelview * IN_pos;
// Offset the uv so we don't have a seam directly over our head.
vec2 uv = IN_uv0 + vec2( 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:
vec3 vNormalWS = -IN_normal;
vec3 vTangentWS = -IN_tangent;
vec3 vBinormalWS = -IN_binormal;
// Compute position in world space:
vec4 vPositionWS = IN_pos + vec4( eyePosWorld, 1 ); //tMul( IN_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 IN_tangent space:
mat3 mWorldToTangent = mat3( vTangentWS, vBinormalWS, vNormalWS );
// Propagate the view and the light vectors (in tangent space):
OUT_vLightTS = vLightWS * mWorldToTangent;
OUT_vViewTS = mWorldToTangent * vViewWS;
OUT_worldDist = clamp( pow( max( IN_pos.z, 0 ), 2 ), 0.0, 1.0 );
correctSSP(gl_Position);
}

View 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 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;
const float sCornerRight[4] = float[]( -0.5, 0.5, 0.5, -0.5 );
const float sCornerUp[4] = float[]( 0, 0, 1, 1 );
const float sMovableCorner[4] = float[]( 0, 0, 1, 1 );
const vec2 sUVCornerExtent[4] = vec2[]
(
vec2( 0, 1 ),
vec2( 1, 1 ),
vec2( 1, 0 ),
vec2( 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
//
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,
inout vec4 texCoord,
inout vec3 normal,
inout vec3 T,
in vec3 eyePos )
{
// Assign the normal and tagent values.
//normal = vec3( 0, 0, 1 );//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];
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;
float fadeRange = fadeEnd - fadeStart;
float dist = distance( eyePos, position.xyz ) - fadeStart;
diffuse.a = 1.0 - clamp( dist / fadeRange, 0.0, 1.0 );
}

View file

@ -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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap, alphaMap;
uniform vec4 groundAlpha;
in vec4 color, groundAlphaCoeff;
in vec2 outTexCoord, alphaLookup;
out vec4 OUT_col;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
vec4 alpha = texture(alphaMap, alphaLookup);
OUT_col = color * texture(diffuseMap, outTexCoord);
OUT_col.a = OUT_col.a * min(alpha, groundAlpha + groundAlphaCoeff.x).x;
}

View file

@ -0,0 +1,99 @@
//-----------------------------------------------------------------------------
// 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
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec3 vNormal;
in vec4 vColor;
in vec2 vTexCoord0;
in vec2 vTexCoord1;
in vec2 vTexCoord2;
uniform mat4 projection, world;
uniform vec3 CameraPos;
uniform float GlobalSwayPhase, SwayMagnitudeSide, SwayMagnitudeFront,
GlobalLightPhase, LuminanceMagnitude, LuminanceMidpoint, DistanceRange;
out vec4 color, groundAlphaCoeff;
out 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] = vPosition.x;
trans[3][1] = vPosition.y;
trans[3][2] = vPosition.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 * vTexCoord1.x;
ySway = sin(wavePhase);
xSway = cos(wavePhase);
xSway = xSway * vTexCoord1.y * SwayMagnitudeSide;
ySway = ySway * vTexCoord1.y * SwayMagnitudeFront;
vec4 p;
p = o * vec4(vNormal.x + xSway, ySway, vNormal.z, 1.0);
// Project the point
gl_Position = projection * p;
// Lighting
float Luminance = LuminanceMidpoint + LuminanceMagnitude * cos(GlobalLightPhase + vNormal.y);
// Alpha
vec3 worldPos = vec3(vPosition.x, vPosition.y, vPosition.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(vNormal.z);
groundAlphaCoeff = vec4(float(alphaCoeff));
outTexCoord = vTexCoord0.st;
color = vec4(Luminance, Luminance, Luminance, 1.0);
gl_Position.y *= -1;
}

View file

@ -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.
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4x4 modelview;
out vec4 hpos;
out vec2 uv0;
void main()
{
hpos = vec4( modelview * vPosition );
gl_Position = hpos;
uv0 = vTexCoord0.st;
gl_Position.y *= -1;
}

View file

@ -0,0 +1,103 @@
//-----------------------------------------------------------------------------
// 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 half float
#define half2 vec2
#define half3 vec3
#define half4 vec4
#define float4x4 mat4
#define float3x3 mat3
#define float2x2 mat2
#define texCUBE texture
#define tex2D texture
#define tex1D texture
#define tex2Dproj textureProj
#define tex2Dlod( sampler, texCoord ) textureLod(sampler, texCoord.xy, texCoord.w)
#define samplerCUBE samplerCube
#define frac fract
#define lerp mix
void tSetMatrixRow(inout float3x3 m, int row, float3 value)
{
m[0][row] = value.x;
m[1][row] = value.y;
m[2][row] = value.z;
}
void tSetMatrixRow(inout float4x4 m, int row, float4 value)
{
m[0][row] = value.x;
m[1][row] = value.y;
m[2][row] = value.z;
m[3][row] = value.w;
}
#define tGetMatrix3Row(matrix, row) float3(matrix[0][row], matrix[1][row], matrix[2][row])
#define tGetMatrix4Row(matrix, row) float4(matrix[0][row], matrix[1][row], matrix[2][row], matrix[3][row])
float3x3 float4x4to3x3(float4x4 m)
{
return float3x3( vec3(m[0]).xyz, m[1].xyz, m[2].xyz);
}
float3x3 float4x4to3x3_(float4x4 m)
{
return float3x3( vec3(m[0]), m[1].xyz, m[2].xyz);
}
mat4 mat4FromRow( float r0c0, float r0c1, float r0c2, float r0c3,
float r1c0, float r1c1, float r1c2, float r1c3,
float r2c0, float r2c1, float r2c2, float r2c3,
float r3c0, float r3c1, float r3c2, float r3c3 )
{
return mat4( r0c0, r1c0, r2c0, r3c0,
r0c1, r1c1, r2c1, r3c1,
r0c2, r1c2, r2c2, r3c2,
r0c3, r1c3, r2c3, r3c3 );
}
#define saturate( val ) clamp( val, 0.0, 1.0 )
#define round( n ) (sign( n ) * floor( abs( n ) + 0.5 ))
#define tMul(a, b) (a*b)
#define inversesqrt( n ) inversesqrt( n )
#define correctSSP(vec) vec.y *= -1
#ifdef TORQUE_PIXEL_SHADER
void clip(float a) { if(a < 0) discard;}
#endif

View 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 );
}

View file

@ -0,0 +1,249 @@
//-----------------------------------------------------------------------------
// 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"
#ifndef TORQUE_SHADERGEN
// These are the uniforms used by most lighting shaders.
uniform vec4 inLightPos[3];
uniform vec4 inLightInvRadiusSq;
uniform vec4 inLightColor[4];
#ifndef TORQUE_BL_NOSPOTLIGHT
uniform vec4 inLightSpotDir[3];
uniform vec4 inLightSpotAngle;
uniform vec4 inLightSpotFalloff;
#endif
uniform vec4 ambient;
#define ambientCameraFactor 0.3
uniform float specularPower;
uniform vec4 specularColor;
#endif // !TORQUE_SHADERGEN
void compute4Lights( vec3 wsView,
vec3 wsPosition,
vec3 wsNormal,
vec4 shadowMask,
#ifdef TORQUE_SHADERGEN
vec4 inLightPos[3],
vec4 inLightInvRadiusSq,
vec4 inLightColor[4],
vec4 inLightSpotDir[3],
vec4 inLightSpotAngle,
vec4 inLightSpotFalloff,
float specularPower,
vec4 specularColor,
#endif // TORQUE_SHADERGEN
out vec4 outDiffuse,
out vec4 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;
vec4 lightVectors[3];
for ( i = 0; i < 3; i++ )
lightVectors[i] = wsPosition[i] - inLightPos[i];
vec4 squareDists = vec4(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.
//
vec4 nDotL = vec4(0);
for ( i = 0; i < 3; i++ )
nDotL += lightVectors[i] * -wsNormal[i];
vec4 rDotL = vec4(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.
//
vec3 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(inversesqrt( 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.
//
vec4 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.
vec4 spotAtten = vec4(0);
for ( i = 0; i < 3; i++ )
spotAtten += lightVectors[i] * inLightSpotDir[i];
vec4 cosAngle = ( spotAtten * correction ) - inLightSpotAngle;
atten *= saturate( cosAngle * inLightSpotFalloff );
#endif
// Finally apply the shadow masking on the attenuation.
atten *= shadowMask;
// Get the final light intensity.
vec4 intensity = nDotL * atten;
// Combine the light colors for output.
outDiffuse = vec4(0);
for ( i = 0; i < 4; i++ )
outDiffuse += intensity[i] * inLightColor[i];
// Output the specular power.
vec4 specularIntensity = pow( rDotL, vec4(specularPower) ) * atten;
// Apply the per-light specular attenuation.
vec4 specular = vec4(0,0,0,1);
for ( i = 0; i < 4; i++ )
specular += vec4( 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( vec3 toLight, vec3 normal, vec3 toEye )
{
// (R.V)^c
float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye );
// Return the specular factor.
return pow( max( specVal, 0.00001f ), AL_ConstantSpecularPower );
}
/// The output for Deferred 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.
///
vec4 AL_DeferredOutput(
vec3 lightColor,
vec3 diffuseColor,
vec4 matInfo,
vec4 ambient,
float specular,
float shadowAttenuation)
{
vec3 specularColor = vec3(specular);
bool metalness = getFlag(matInfo.r, 3);
if ( metalness )
{
specularColor = 0.04 * (1 - specular) + diffuseColor * specular;
}
//specular = color * map * spec^gloss
float specularOut = (specularColor * matInfo.b * min(pow(max(specular,1.0f), max((matInfo.a / AL_ConstantSpecularPower),1.0f)),matInfo.a)).r;
lightColor *= vec3(shadowAttenuation);
lightColor += ambient.rgb;
return vec4(lightColor.rgb, specularOut);
}

View file

@ -0,0 +1,62 @@
//-----------------------------------------------------------------------------
// 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"
#include "hlslCompat.glsl"
in vec4 offscreenPos;
in vec4 backbufferPos;
#define IN_offscreenPos offscreenPos
#define IN_backbufferPos backbufferPos
uniform sampler2D colorSource;
uniform vec4 offscreenTargetParams;
#ifdef TORQUE_LINEAR_DEPTH
#define REJECT_EDGES
uniform sampler2D edgeSource;
uniform vec4 edgeTargetParams;
#endif
out vec4 OUT_col;
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 = texture( edgeSource, uvScene.zw ).r;
clip( -edge );
#endif
// Sample offscreen target and return
OUT_col = texture( colorSource, uvScene.xy );
}

View 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.
//-----------------------------------------------------------------------------
#include "hlslCompat.glsl"
in vec2 vTexCoord0;
#define uvCoord vTexCoord0
out vec4 offscreenPos;
out vec4 backbufferPos;
#define OUT_hpos gl_Position
#define OUT_offscreenPos offscreenPos
#define OUT_backbufferPos backbufferPos
uniform vec4 screenRect; // point, extent
void main()
{
OUT_hpos = vec4(uvCoord.xy, 1.0, 1.0);
OUT_hpos.xy *= screenRect.zw;
OUT_hpos.xy += screenRect.xy;
OUT_backbufferPos = OUT_hpos;
OUT_offscreenPos = OUT_hpos;
correctSSP(gl_Position);
}

View file

@ -0,0 +1,113 @@
//-----------------------------------------------------------------------------
// 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"
#include "hlslCompat.glsl"
// 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;
//uniform vec3 vEye;
uniform vec4 prePassTargetParams;
#endif
#define CLIP_Z // TODO: Make this a proper macro
in vec4 color;
in vec2 uv0;
in vec4 pos;
#define IN_color color
#define IN_uv0 uv0
#define IN_pos pos
uniform sampler2D diffuseMap;
uniform sampler2D paraboloidLightMap;
vec4 lmSample( vec3 nrm )
{
bool calcBack = (nrm.z < 0.0);
if ( calcBack )
nrm.z = nrm.z * -1.0;
vec2 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 texture(paraboloidLightMap, lmCoord);
}
uniform float alphaFactor;
uniform float alphaScale;
out vec4 OUT_col;
void main()
{
float softBlend = 1;
#ifdef SOFTPARTICLES
vec2 tc = IN_pos.xy * vec2(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
vec4 diffuse = texture( diffuseMap, IN_uv0 );
//OUT_col = vec4( lmSample(vec3(0, 0, -1)).rgb, IN_color.a * diffuse.a * softBlend * alphaScale);
// Scale output color by the alpha factor (turn LerpAlpha into pre-multiplied alpha)
vec3 colorScale = ( alphaFactor < 0.0 ? IN_color.rgb * diffuse.rgb : vec3( alphaFactor > 0.0 ? IN_color.a * diffuse.a * alphaFactor * softBlend : softBlend ) );
OUT_col = hdrEncode( vec4( IN_color.rgb * diffuse.rgb * colorScale,
IN_color.a * diffuse.a * softBlend * alphaScale ) );
}

View file

@ -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.
//-----------------------------------------------------------------------------
#include "hlslCompat.glsl"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
#define In_pos vPosition
#define In_color vColor
#define In_uv0 vTexCoord0
out vec4 color;
out vec2 uv0;
out vec4 pos;
#define OUT_hpos gl_Position
#define OUT_color color
#define OUT_uv0 uv0
#define OUT_pos pos
uniform mat4 modelViewProj;
uniform mat4 fsModelViewProj;
void main()
{
OUT_hpos = tMul( modelViewProj, In_pos );
OUT_pos = tMul( fsModelViewProj, In_pos );
OUT_color = In_color;
OUT_uv0 = In_uv0;
correctSSP(gl_Position);
}

View file

@ -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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap, refractMap, bumpMap;
uniform vec4 shadeColor;
in vec2 TEX0;
in vec4 TEX1;
out vec4 OUT_col;
//-----------------------------------------------------------------------------
// 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 = texture( 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 = texture( diffuseMap, TEX0 );
vec4 reflectColor = textureProj( refractMap, texIndex );
OUT_col = diffuseColor + reflectColor * diffuseColor.a;
}

View file

@ -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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec2 TEX0;
out 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 * vPosition;
TEX0 = vTexCoord0.st;
TEX1 = texGenTest * gl_Position;
TEX1.y = -TEX1.y;
gl_Position.y *= -1;
}

View 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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap, refractMap;
uniform vec4 shadeColor;
in vec2 TEX0;
in vec4 TEX1;
out vec4 OUT_col;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
vec4 diffuseColor = texture( diffuseMap, TEX0 );
vec4 reflectColor = textureProj( refractMap, TEX1 );
OUT_col = diffuseColor + reflectColor * diffuseColor.a;
}

View file

@ -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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4 modelview;
out vec2 TEX0;
out 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 * vPosition;
TEX0 = vTexCoord0;
TEX1 = texGenTest * gl_Position;
TEX1.y = -TEX1.y;
}

View file

@ -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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;
out vec4 OUT_col;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
OUT_col = texture(diffuseMap, texCoord) * color;
}

View file

@ -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.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4 modelview;
uniform vec3 cameraPos, ambient;
uniform vec2 fadeStartEnd;
out vec4 color;
out vec2 texCoord;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
gl_Position = modelview * vPosition;
texCoord = vTexCoord0.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 - vPosition.xyz );
color.a = abs( clamp( ( distance - fadeStartEnd.x ) / ( fadeStartEnd.y - fadeStartEnd.x ), 0.0, 1.0 ) - 1.0 );
}
gl_Position.y *= -1;
}

View 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.
//-----------------------------------------------------------------------------
in vec2 texCoord;
in vec4 color;
in float fade;
out vec4 OUT_col;
uniform sampler2D inputTex;
uniform vec4 ambient;
void main()
{
float shadow = texture( inputTex, texCoord ).a * color.a;
OUT_col = ( ambient * shadow ) + ( 1 - shadow );
}

View 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 "hlslCompat.glsl"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
in vec2 vTexCoord1;
out vec2 texCoord;
out vec4 color;
out float fade;
uniform mat4 modelview;
uniform float shadowLength;
uniform vec3 shadowCasterPosition;
void main()
{
gl_Position = modelview * vec4(vPosition.xyz, 1.0);
color = vColor;
texCoord = vTexCoord0.st;
float fromCasterDist = length(vPosition.xyz - shadowCasterPosition) - shadowLength;
fade = 1.0 - clamp( fromCasterDist / shadowLength , 0.0, 1.0 );
correctSSP(gl_Position);
}

View file

@ -0,0 +1,72 @@
//-----------------------------------------------------------------------------
// 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"
#include "hlslCompat.glsl"
// Conn
in vec4 rayleighColor;
#define IN_rayleighColor rayleighColor
in vec4 mieColor;
#define IN_mieColor mieColor
in vec3 v3Direction;
#define IN_v3Direction v3Direction
in vec3 pos;
#define IN_pos pos
uniform samplerCube nightSky ;
uniform vec4 nightColor;
uniform vec2 nightInterpAndExposure;
uniform float useCubemap;
uniform vec3 lightDir;
uniform vec3 sunDir;
out vec4 OUT_col;
void main()
{
float fCos = dot( lightDir, IN_v3Direction ) / length(IN_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 = IN_rayleighColor + fMiePhase * IN_mieColor;
color.a = color.b;
vec4 nightSkyColor = texture(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 ) );
OUT_col = mix( color, nightSkyColor, nightInterpAndExposure.y );
OUT_col.a = 1;
OUT_col = clamp(OUT_col, 0.0, 1.0);
OUT_col = hdrEncode( OUT_col );
}

View file

@ -0,0 +1,154 @@
//-----------------------------------------------------------------------------
// 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"
// 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;
}
in vec4 vPosition;
// This is the shader input vertex structure.
#define IN_position vPosition
// This is the shader output data.
out vec4 rayleighColor;
#define OUT_rayleighColor rayleighColor
out vec4 mieColor;
#define OUT_mieColor mieColor
out vec3 v3Direction;
#define OUT_v3Direction v3Direction
out vec3 pos;
#define OUT_pos pos
uniform mat4 modelView;
uniform vec4 misc;
uniform vec4 sphereRadii;
uniform vec4 scatteringCoeffs;
uniform vec3 camPos;
uniform vec3 lightDir;
uniform vec4 invWaveLength;
uniform vec4 colorize;
vec3 desaturate(const vec3 color, const float desaturation)
{
const vec3 gray_conv = vec3 (0.30, 0.59, 0.11);
return mix(color, vec3(dot(gray_conv , color)), desaturation);
}
void main()
{
// 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 = vec3(IN_position / 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 fStartOffset = fDepth * 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;
float vscale3 = vernierScale( fCameraAngle );
float vscale2 = vernierScale( fLightAngle );
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 * IN_position;
OUT_mieColor.rgb = v3FrontColor * mieBrightness;
OUT_mieColor.a = 1.0;
OUT_rayleighColor.rgb = v3FrontColor * (invWaveLength.xyz * rayleighBrightness);
OUT_rayleighColor.a = 1.0;
OUT_v3Direction = newCamPos - v3Pos.xyz;
OUT_pos = IN_position.xyz;
#ifdef USE_COLORIZE
OUT_rayleighColor.rgb = desaturate(OUT_rayleighColor.rgb, 1) * colorize.a;
OUT_rayleighColor.r *= colorize.r;
OUT_rayleighColor.g *= colorize.g;
OUT_rayleighColor.b *= colorize.b;
#endif
correctSSP(gl_Position);
}

View file

@ -0,0 +1,339 @@
//-----------------------------------------------------------------------------
// 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 = texture( texMap, texCoord ).a/(PARALLAX_REFINE_STEPS*2);
vec2 offset = negViewTS.xy * vec2( depth * depthScale )/vec2(PARALLAX_REFINE_STEPS*2);
for ( int i=0; i < PARALLAX_REFINE_STEPS; i++ )
{
depth = ( depth + texture( texMap, texCoord + offset ).a )/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * vec2( depth * depthScale )/vec2(PARALLAX_REFINE_STEPS*2);
}
return offset;
}
/// Same as parallaxOffset but for dxtnm where depth is stored in the red channel instead of the alpha
vec2 parallaxOffsetDxtnm(sampler2D texMap, vec2 texCoord, vec3 negViewTS, float depthScale)
{
float depth = texture(texMap, texCoord).r/(PARALLAX_REFINE_STEPS*2);
vec2 offset = negViewTS.xy * vec2(depth * depthScale)/vec2(PARALLAX_REFINE_STEPS*2);
for (int i = 0; i < PARALLAX_REFINE_STEPS; i++)
{
depth = (depth + texture(texMap, texCoord + offset).r)/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * vec2(depth * depthScale)/vec2(PARALLAX_REFINE_STEPS*2);
}
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;
}
#ifdef TORQUE_PIXEL_SHADER
/// Called from the visibility feature to do screen
/// door transparency for fading of objects.
void fizzle(vec2 vpos, float visibility)
{
// NOTE: The magic values below are what give us
// the nice even pattern during the fizzle.
//
// These values can be changed to get different
// patterns... some better than others.
//
// Horizontal Blinds - { vpos.x, 0.916, vpos.y, 0 }
// Vertical Lines - { vpos.x, 12.9898, vpos.y, 78.233 }
//
// I'm sure there are many more patterns here to
// discover for different effects.
mat2x2 m = mat2x2( vpos.x, vpos.y, 0.916, 0.350 );
if( (visibility - fract( determinant( m ) )) < 0 ) //if(a < 0) discard;
discard;
}
#endif //TORQUE_PIXEL_SHADER
/// 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)) { OUT_col = color; return; } }
// Deferred Shading: Material Info Flag Check
bool getFlag(float flags, float num)
{
float process = round(flags * 255);
float squareNum = pow(2.0, num);
return (mod(process, pow(2.0, squareNum)) >= squareNum);
}
// #define TORQUE_STOCK_GAMMA
#ifdef TORQUE_STOCK_GAMMA
// Sample in linear space. Decodes gamma.
vec4 toLinear(vec4 tex)
{
return tex;
}
// Encodes gamma.
vec4 toGamma(vec4 tex)
{
return tex;
}
vec3 toLinear(vec3 tex)
{
return tex;
}
// Encodes gamma.
vec3 toGamma(vec3 tex)
{
return tex;
}
#else
// Sample in linear space. Decodes gamma.
vec4 toLinear(vec4 tex)
{
return vec4(pow(abs(tex.rgb), vec3(2.2)), tex.a);
}
// Encodes gamma.
vec4 toGamma(vec4 tex)
{
return vec4(pow(abs(tex.rgb), vec3(1.0/2.2)), tex.a);
}
// Sample in linear space. Decodes gamma.
vec3 toLinear(vec3 tex)
{
return pow(abs(tex), vec3(2.2));
}
// Encodes gamma.
vec3 toGamma(vec3 tex)
{
return pow(abs(tex), vec3(1.0/2.2));
}
#endif //
#endif // _TORQUE_GLSL_

View file

@ -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.
//-----------------------------------------------------------------------------
uniform sampler2D diffMap;
uniform sampler2D bumpMap;
uniform samplerCube cubeMap;
uniform vec4 specularColor;
uniform float specularPower;
uniform vec4 ambient;
uniform float accumTime;
in vec2 TEX0;
in vec4 outLightVec;
in vec3 outPos;
in vec3 outEyePos;
out vec4 OUT_col;
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 = texture(bumpMap, texOffset) * 2.0 - 1.0;
vec4 diffuse = texture(diffMap, texOffset);
OUT_col = 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);
OUT_col += specularColor * specular;
}

View 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;
}

View file

@ -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.
//-----------------------------------------------------------------------------
#include "hlslStructs.hlsl"
#include "shaderModel.hlsl"
struct MaterialDecoratorConnectV
{
float4 hpos : TORQUE_POSITION;
float2 uv0 : TEXCOORD0;
};
uniform float4x4 modelview : register(C0);
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
MaterialDecoratorConnectV main( VertexIn_PCT IN )
{
MaterialDecoratorConnectV OUT;
OUT.hpos = mul(modelview, float4(IN.pos,1.0));
OUT.uv0 = IN.uv0;
return OUT;
}

View file

@ -0,0 +1,116 @@
//-----------------------------------------------------------------------------
// 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_PNTT
{
float4 pos : POSITION;
float3 normal : NORMAL;
float3 tangent : TANGENT;
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;
};

View file

@ -0,0 +1,114 @@
//-----------------------------------------------------------------------------
// 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 float3 as our vertex structures in
// the engine output float3s for position.
struct VertexIn_P
{
float3 pos : POSITION;
};
struct VertexIn_PT
{
float3 pos : POSITION;
float2 uv0 : TEXCOORD0;
};
struct VertexIn_PTTT
{
float3 pos : POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
};
struct VertexIn_PC
{
float3 pos : POSITION;
float4 color : DIFFUSE;
};
struct VertexIn_PNC
{
float3 pos : POSITION;
float3 normal : NORMAL;
float4 color : DIFFUSE;
};
struct VertexIn_PCT
{
float3 pos : POSITION;
float4 color : DIFFUSE;
float2 uv0 : TEXCOORD0;
};
struct VertexIn_PN
{
float3 pos : POSITION;
float3 normal : NORMAL;
};
struct VertexIn_PNT
{
float3 pos : POSITION;
float3 normal : NORMAL;
float2 uv0 : TEXCOORD0;
};
struct VertexIn_PNTT
{
float3 pos : POSITION;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float2 uv0 : TEXCOORD0;
};
struct VertexIn_PNCT
{
float3 pos : POSITION;
float3 normal : NORMAL;
float4 color : DIFFUSE;
float2 uv0 : TEXCOORD0;
};
struct VertexIn_PNTTTB
{
float3 pos : POSITION;
float3 normal : NORMAL;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float3 T : TEXCOORD2;
float3 B : TEXCOORD3;
};

View 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 );
}

View file

@ -0,0 +1,249 @@
//-----------------------------------------------------------------------------
// 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"
#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;
#define ambientCameraFactor 0.3
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 )
{
// (R.V)^c
float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye );
// Return the specular factor.
return pow( max( specVal, 0.00001f ), AL_ConstantSpecularPower );
}
/// The output for Deferred 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.
///
float4 AL_DeferredOutput(
float3 lightColor,
float3 diffuseColor,
float4 matInfo,
float4 ambient,
float specular,
float shadowAttenuation)
{
float3 specularColor = float3(specular, specular, specular);
bool metalness = getFlag(matInfo.r, 3);
if ( metalness )
{
specularColor = 0.04 * (1 - specular) + diffuseColor * specular;
}
//specular = color * map * spec^gloss
float specularOut = (specularColor * matInfo.b * min(pow(abs(specular), max(( matInfo.a/ AL_ConstantSpecularPower),1.0f)),matInfo.a)).r;
lightColor *= shadowAttenuation;
lightColor += ambient.rgb;
return float4(lightColor.rgb, specularOut);
}

View file

@ -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.
//-----------------------------------------------------------------------------
#include "../../hlslStructs.hlsl"
#include "../../shaderModel.hlsl"
struct VertData
{
float3 pos : POSITION;
float4 color : COLOR;
};
struct ConvexConnectV
{
float4 hpos : TORQUE_POSITION;
float4 wsEyeDir : TEXCOORD0;
float4 ssPos : TEXCOORD1;
float4 vsEyeDir : TEXCOORD2;
};
ConvexConnectV main( VertData IN,
uniform float4x4 modelview,
uniform float4x4 objTrans,
uniform float4x4 worldViewOnly,
uniform float3 eyePosWorld )
{
ConvexConnectV OUT;
OUT.hpos = mul( modelview, float4(IN.pos,1.0) );
OUT.wsEyeDir = mul(objTrans, float4(IN.pos, 1.0)) - float4(eyePosWorld, 0.0);
OUT.vsEyeDir = mul(worldViewOnly, float4(IN.pos, 1.0));
OUT.ssPos = OUT.hpos;
return OUT;
}

View file

@ -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.
//-----------------------------------------------------------------------------
#include "../../postfx/postFx.hlsl"
TORQUE_UNIFORM_SAMPLER2D(colorBufferTex,0);
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
return float4(TORQUE_TEX2D( colorBufferTex, IN.uv0 ).rgb, 1.0);
}

View 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.
//-----------------------------------------------------------------------------
#include "../../postfx/postFx.hlsl"
#include "../../shaderModelAutoGen.hlsl"
TORQUE_UNIFORM_SAMPLER2D(prepassTex, 0);
TORQUE_UNIFORM_SAMPLER1D(depthViz, 1);
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
float depth = TORQUE_PREPASS_UNCONDITION( prepassTex, IN.uv0 ).w;
return float4( TORQUE_TEX1D( depthViz, depth ).rgb, 1.0 );
}

View file

@ -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.
//-----------------------------------------------------------------------------
#include "../../postfx/postFx.hlsl"
TORQUE_UNIFORM_SAMPLER2D(glowBuffer, 0);
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
return TORQUE_TEX2D(glowBuffer, IN.uv0);
}

View file

@ -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 "../../shaderModelAutoGen.hlsl"
#include "../../postfx/postFx.hlsl"
TORQUE_UNIFORM_SAMPLER2D(lightPrePassTex,0);
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
float4 lightColor = TORQUE_TEX2D( lightPrePassTex, IN.uv0 );
return float4( lightColor.rgb, 1.0 );
}

View file

@ -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.
//-----------------------------------------------------------------------------
#include "../../postfx/postFx.hlsl"
TORQUE_UNIFORM_SAMPLER2D(lightPrePassTex,0);
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
float specular = TORQUE_TEX2D( lightPrePassTex, IN.uv0 ).a;
return float4( specular, specular, specular, 1.0 );
}

View file

@ -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 "../../postfx/postFx.hlsl"
#include "../../shaderModelAutoGen.hlsl"
TORQUE_UNIFORM_SAMPLER2D(prepassTex, 0);
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
float3 normal = TORQUE_PREPASS_UNCONDITION( prepassTex, IN.uv0 ).xyz;
return float4( ( normal + 1.0 ) * 0.5, 1.0 );
}

View file

@ -0,0 +1,38 @@
//-----------------------------------------------------------------------------
// 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 "../../shaderModel.hlsl"
struct MaterialDecoratorConnectV
{
float4 hpos : TORQUE_POSITION;
float2 uv0 : TEXCOORD0;
};
TORQUE_UNIFORM_SAMPLER2D(shadowMap, 0);
TORQUE_UNIFORM_SAMPLER1D(depthViz, 1);
float4 main( MaterialDecoratorConnectV IN ) : TORQUE_TARGET0
{
float depth = saturate( TORQUE_TEX2D( shadowMap, IN.uv0 ).r );
return float4( TORQUE_TEX1D( depthViz, depth ).rgb, 1 );
}

View file

@ -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.
//-----------------------------------------------------------------------------
#include "../../postfx/postFx.hlsl"
TORQUE_UNIFORM_SAMPLER2D(matinfoTex,0);
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
float specular = TORQUE_TEX2D( matinfoTex, IN.uv0 ).b;
return float4( specular, specular, specular, 1.0 );
}

View file

@ -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.
//-----------------------------------------------------------------------------
#include "../../shaderModel.hlsl"
struct Conn
{
float4 hpos : TORQUE_POSITION;
};
struct Fragout
{
float4 col : TORQUE_TARGET0;
float4 col1 : TORQUE_TARGET1;
float4 col2 : TORQUE_TARGET2;
};
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Fragout main( Conn IN )
{
Fragout OUT;
// Clear Prepass Buffer ( Normals/Depth );
OUT.col = float4(1.0, 1.0, 1.0, 1.0);
// Clear Color Buffer.
OUT.col1 = float4(0.0, 0.0, 0.0, 1.0);
// Clear Material Info Buffer.
OUT.col2 = float4(0.0, 0.0, 0.0, 1.0);
return OUT;
}

View 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 "../../shaderModel.hlsl"
struct Appdata
{
float3 pos : POSITION;
float4 color : COLOR;
};
struct Conn
{
float4 hpos : TORQUE_POSITION;
};
uniform float4x4 modelview;
Conn main( Appdata In )
{
Conn Out;
Out.hpos = float4(In.pos,1.0);
return Out;
}

View 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.
//-----------------------------------------------------------------------------
#include "../../shaderModel.hlsl"
struct Fragout
{
float4 col : TORQUE_TARGET0;
float4 col1 : TORQUE_TARGET1;
float4 col2 : TORQUE_TARGET2;
};
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Fragout main( )
{
Fragout OUT;
OUT.col = float4(0.0, 0.0, 0.0, 0.0);
OUT.col1 = float4(1.0, 1.0, 1.0, 1.0);
// Draw on color buffer.
OUT.col2 = float4(1.0, 0.0, 0.0, 1.0);
return OUT;
}

View file

@ -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.
//-----------------------------------------------------------------------------
#include "../../shaderModelAutoGen.hlsl"
#include "../../postfx/postFx.hlsl"
#include "../../torque.hlsl"
TORQUE_UNIFORM_SAMPLER2D(colorBufferTex,0);
TORQUE_UNIFORM_SAMPLER2D(lightPrePassTex,1);
TORQUE_UNIFORM_SAMPLER2D(matInfoTex,2);
TORQUE_UNIFORM_SAMPLER2D(prepassTex,3);
float4 main( PFXVertToPix IN ) : TORQUE_TARGET0
{
float4 lightBuffer = TORQUE_TEX2D( lightPrePassTex, IN.uv0 );
float4 colorBuffer = TORQUE_TEX2D( colorBufferTex, IN.uv0 );
float4 matInfo = TORQUE_TEX2D( matInfoTex, IN.uv0 );
float specular = saturate(lightBuffer.a);
float depth = TORQUE_PREPASS_UNCONDITION( prepassTex, IN.uv0 ).w;
if (depth>0.9999)
return float4(0,0,0,0);
// Diffuse Color Altered by Metalness
bool metalness = getFlag(matInfo.r, 3);
if ( metalness )
{
colorBuffer *= (1.0 - colorBuffer.a);
}
colorBuffer += float4(specular, specular, specular, 1.0);
colorBuffer *= float4(lightBuffer.rgb, 1.0);
return hdrEncode( float4(colorBuffer.rgb, 1.0) );
}

View 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 "../../shaderModel.hlsl"
struct FarFrustumQuadConnectV
{
float4 hpos : TORQUE_POSITION;
float2 uv0 : TEXCOORD0;
float3 wsEyeRay : TEXCOORD1;
float3 vsEyeRay : TEXCOORD2;
};
struct FarFrustumQuadConnectP
{
float4 hpos : TORQUE_POSITION;
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;
}

View 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.hlsl"
#include "farFrustumQuad.hlsl"
FarFrustumQuadConnectV main( VertexIn_PNTT 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.tangent;
OUT.vsEyeRay = IN.normal;
return OUT;
}

View file

@ -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 "../../../gl/hlslCompat.glsl"
in vec4 vPosition;
#define IN_pos vPosition
out vec4 wsEyeDir;
out vec4 ssPos;
out vec4 vsEyeDir;
#define OUT_hpos gl_Position
#define OUT_wsEyeDir wsEyeDir
#define OUT_ssPos ssPos
#define OUT_vsEyeDir vsEyeDir
uniform mat4 modelview;
uniform mat4 objTrans;
uniform mat4 worldViewOnly;
uniform vec3 eyePosWorld;
void main()
{
OUT_hpos = tMul( modelview, IN_pos );
OUT_wsEyeDir = tMul( objTrans, IN_pos ) - vec4( eyePosWorld, 0.0 );
OUT_vsEyeDir = tMul( worldViewOnly, IN_pos );
OUT_ssPos = OUT_hpos;
correctSSP(gl_Position);
}

View 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.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
in vec2 uv0;
uniform sampler2D colorBufferTex;
out vec4 OUT_FragColor0;
void main()
{
OUT_FragColor0 = vec4(texture( colorBufferTex, uv0 ).rgb, 1.0);
}

View file

@ -0,0 +1,36 @@
//-----------------------------------------------------------------------------
// 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"
in vec2 uv0;
uniform sampler2D prepassTex;
uniform sampler1D depthViz;
out vec4 OUT_col;
void main()
{
float depth = prepassUncondition( prepassTex, uv0 ).w;
OUT_col = vec4( texture( depthViz, depth ).rgb, 1.0 );
}

View 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.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
in vec2 uv0;
uniform sampler2D glowBuffer;
out vec4 OUT_FragColor0;
void main()
{
OUT_FragColor0 = texture(glowBuffer, uv0);
}

View 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.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
in vec2 uv0;
uniform sampler2D lightPrePassTex;
out vec4 OUT_col;
void main()
{
vec4 lightColor = texture( lightPrePassTex, uv0 );
OUT_col = vec4( lightColor.rgb, 1.0 );
}

View 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.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
in vec2 uv0;
uniform sampler2D lightPrePassTex;
out vec4 OUT_col;
void main()
{
float specular = texture( lightPrePassTex, uv0 ).a;
OUT_col = vec4( specular, specular, specular, 1.0 );
}

View 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.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
#include "shadergen:/autogenConditioners.h"
in vec2 uv0;
uniform sampler2D prepassTex;
out vec4 OUT_col;
void main()
{
vec3 normal = prepassUncondition( prepassTex, uv0 ).xyz;
OUT_col = vec4( ( normal + 1.0 ) * 0.5, 1.0 );
}

View 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.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
in vec2 uv0;
uniform sampler2D shadowMap;
uniform sampler1D depthViz;
out vec4 OUT_col;
void main()
{
float depth = saturate( texture( shadowMap, uv0 ).r );
OUT_col = vec4( texture( depthViz, depth ).rgb, 1 );
}

View 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.
//-----------------------------------------------------------------------------
#include "../../../gl/hlslCompat.glsl"
in vec2 uv0;
uniform sampler2D matinfoTex;
out vec4 OUT_FragColor0;
void main()
{
float specular = texture( matinfoTex, uv0 ).a;
OUT_FragColor0 = vec4( specular, specular, specular, 1.0 );
}

View file

@ -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.
//-----------------------------------------------------------------------------
out vec4 OUT_col;
out vec4 OUT_col1;
out vec4 OUT_col2;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
// Clear Prepass Buffer ( Normals/Depth );
OUT_col = vec4(1.0, 1.0, 1.0, 1.0);
// Clear Color Buffer.
OUT_col1 = vec4(0.0, 0.0, 0.0, 1.0);
// Clear Material Info Buffer.
OUT_col2 = vec4(0.0, 0.0, 0.0, 1.0);
}

View 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.
//-----------------------------------------------------------------------------
layout (location = 0) out vec4 col;
layout (location = 1) out vec4 col1;
layout (location = 2) out vec4 col2;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
col = vec4(0.0, 0.0, 0.0, 0.0);
col1 = vec4(1.0, 1.0, 1.0, 1.0);
// Draw on color buffer.
col2 = vec4(1.0, 0.0, 0.0, 1.0);
}

View file

@ -0,0 +1,59 @@
//-----------------------------------------------------------------------------
// 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 "../../../postFx/gl/postFX.glsl"
#include "../../../gl/torque.glsl"
uniform sampler2D colorBufferTex;
uniform sampler2D lightPrePassTex;
uniform sampler2D matInfoTex;
uniform sampler2D prepassTex;
out vec4 OUT_col;
void main()
{
float depth = prepassUncondition( prepassTex, uv0 ).w;
if (depth>0.9999)
{
OUT_col = vec4(0.0);
return;
}
vec4 lightBuffer = texture( lightPrePassTex, uv0 );
vec4 colorBuffer = texture( colorBufferTex, uv0 );
vec4 matInfo = texture( matInfoTex, uv0 );
float specular = clamp(lightBuffer.a,0.0,1.0);
// Diffuse Color Altered by Metalness
bool metalness = getFlag(matInfo.r, 3);
if ( metalness )
{
colorBuffer *= (1.0 - colorBuffer.a);
}
colorBuffer += vec4(specular, specular, specular, 1.0);
colorBuffer *= vec4(lightBuffer.rgb, 1.0);
OUT_col = hdrEncode( vec4(colorBuffer.rgb, 1.0) );
}

View file

@ -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.y = 1.0 - outPos.y;
outPos = ( outPos * rtParams.zw ) + rtParams.xy;
return outPos;
}

Some files were not shown because too many files have changed in this diff Show more