mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 16:44:36 +00:00
Full Template for ticket #1
This commit is contained in:
parent
74f265b3b3
commit
f439dc8dcd
2150 changed files with 286240 additions and 0 deletions
37
Templates/Full/game/shaders/common/gl/blurP.glsl
Normal file
37
Templates/Full/game/shaders/common/gl/blurP.glsl
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//*****************************************************************************
|
||||
// Glow Shader
|
||||
//*****************************************************************************
|
||||
uniform vec4 kernel;
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
varying vec2 texc0, texc1, texc2, texc3;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(diffuseMap, texc0) * kernel.x;
|
||||
gl_FragColor += texture2D(diffuseMap, texc1) * kernel.y;
|
||||
gl_FragColor += texture2D(diffuseMap, texc2) * kernel.z;
|
||||
gl_FragColor += texture2D(diffuseMap, texc3) * kernel.w;
|
||||
}
|
||||
43
Templates/Full/game/shaders/common/gl/blurV.glsl
Normal file
43
Templates/Full/game/shaders/common/gl/blurV.glsl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//*****************************************************************************
|
||||
// Glow shader
|
||||
//*****************************************************************************
|
||||
|
||||
uniform mat4 modelview;
|
||||
uniform vec2 offset0, offset1, offset2, offset3;
|
||||
|
||||
varying vec2 texc0, texc1, texc2, texc3;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
|
||||
vec2 tc = gl_MultiTexCoord0.st;
|
||||
tc.y = 1.0 - tc.y;
|
||||
|
||||
texc0 = tc + offset0;
|
||||
texc1 = tc + offset1;
|
||||
texc2 = tc + offset2;
|
||||
texc3 = tc + offset3;
|
||||
}
|
||||
139
Templates/Full/game/shaders/common/gl/cloudLayerP.glsl
Normal file
139
Templates/Full/game/shaders/common/gl/cloudLayerP.glsl
Normal file
|
|
@ -0,0 +1,139 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hlslCompat.glsl"
|
||||
|
||||
varying vec4 texCoord12;
|
||||
varying vec4 texCoord34;
|
||||
varying vec3 vLightTS; // light vector in tangent space, denormalized
|
||||
varying vec3 vViewTS; // view vector in tangent space, denormalized
|
||||
varying vec3 vNormalWS; // Normal vector in world space
|
||||
varying float worldDist;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uniforms
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform sampler2D normalHeightMap;
|
||||
uniform vec3 ambientColor;
|
||||
uniform vec3 sunColor;
|
||||
uniform float cloudCoverage;
|
||||
uniform vec3 cloudBaseColor;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Globals
|
||||
//-----------------------------------------------------------------------------
|
||||
// The per-color weighting to be used for luminance calculations in RGB order.
|
||||
const vec3 LUMINANCE_VECTOR = vec3(0.2125f, 0.7154f, 0.0721f);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// Calculates the Rayleigh phase function
|
||||
float getRayleighPhase( float angle )
|
||||
{
|
||||
return 0.75 * ( 1.0 + pow( angle, 2.0 ) );
|
||||
}
|
||||
|
||||
// Returns the output rgb color given a texCoord and parameters it uses
|
||||
// for lighting calculation.
|
||||
vec3 ComputeIllumination( vec2 texCoord,
|
||||
vec3 vLightTS,
|
||||
vec3 vViewTS,
|
||||
vec3 vNormalTS )
|
||||
{
|
||||
//return noiseNormal;
|
||||
//return vNormalTS;
|
||||
|
||||
vec3 vLightTSAdj = vec3( -vLightTS.x, -vLightTS.y, vLightTS.z );
|
||||
|
||||
float dp = dot( vNormalTS, vLightTSAdj );
|
||||
|
||||
// Calculate the amount of illumination (lightTerm)...
|
||||
|
||||
// We do both a rim lighting effect and a halfLambertian lighting effect
|
||||
// and combine the result.
|
||||
float halfLambertTerm = clamp( pow( dp * 0.5 + 0.5, 1.0 ), 0.0, 1.0 );
|
||||
float rimLightTerm = pow( ( 1.0 - dp ), 1.0 );
|
||||
float lightTerm = clamp( halfLambertTerm * 1.0 + rimLightTerm * dp, 0.0, 1.0 );
|
||||
lightTerm *= 0.5;
|
||||
|
||||
// Use a simple RayleighPhase function to simulate single scattering towards
|
||||
// the camera.
|
||||
float angle = dot( vLightTS, vViewTS );
|
||||
lightTerm *= getRayleighPhase( angle );
|
||||
|
||||
// Combine terms and colors into the output color.
|
||||
//vec3 lightColor = ( lightTerm * sunColor * fOcclusionShadow ) + ambientColor;
|
||||
vec3 lightColor = mix( ambientColor, sunColor, lightTerm );
|
||||
//lightColor = mix( lightColor, ambientColor, cloudCoverage );
|
||||
vec3 finalColor = cloudBaseColor * lightColor;
|
||||
|
||||
return finalColor;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
// Normalize the interpolated vectors:
|
||||
vec3 vViewTS = normalize( vViewTS );
|
||||
vec3 vLightTS = normalize( vLightTS );
|
||||
vec3 vNormalWS = normalize( vNormalWS );
|
||||
|
||||
vec4 cResultColor = float4( 0, 0, 0, 1 );
|
||||
|
||||
vec2 texSample = texCoord12.xy;
|
||||
|
||||
vec4 noise1 = texture2D( normalHeightMap, texCoord12.zw );
|
||||
noise1 = normalize( ( noise1 - 0.5 ) * 2.0 );
|
||||
//return noise1;
|
||||
|
||||
vec4 noise2 = texture2D( normalHeightMap, texCoord34.xy );
|
||||
noise2 = normalize( ( noise2 - 0.5 ) * 2.0 );
|
||||
//return noise2;
|
||||
|
||||
vec3 noiseNormal = normalize( noise1 + noise2 ).xyz;
|
||||
//return float4( noiseNormal, 1.0 );
|
||||
|
||||
float noiseHeight = noise1.a * noise2.a * ( cloudCoverage / 2.0 + 0.5 );
|
||||
|
||||
vec3 vNormalTS = normalize( texture2D( normalHeightMap, texSample ).xyz * 2.0 - 1.0 );
|
||||
vNormalTS += noiseNormal;
|
||||
vNormalTS = normalize( vNormalTS );
|
||||
|
||||
// Compute resulting color for the pixel:
|
||||
cResultColor.rgb = ComputeIllumination( texSample, vLightTS, vViewTS, vNormalTS );
|
||||
|
||||
float coverage = ( cloudCoverage - 0.5 ) * 2.0;
|
||||
cResultColor.a = texture2D( normalHeightMap, texSample ).a + coverage + noiseHeight;
|
||||
|
||||
if ( cloudCoverage > -1.0 )
|
||||
cResultColor.a /= 1.0 + coverage;
|
||||
|
||||
cResultColor.a = saturate( cResultColor.a * pow( saturate(cloudCoverage), 0.25 ) );
|
||||
|
||||
cResultColor.a = mix( cResultColor.a, 0.0, 1.0 - pow(worldDist,2.0) );
|
||||
|
||||
// If using HDR rendering, make sure to tonemap the resuld color prior to outputting it.
|
||||
// But since this example isn't doing that, we just output the computed result color here:
|
||||
gl_FragColor = cResultColor;
|
||||
}
|
||||
92
Templates/Full/game/shaders/common/gl/cloudLayerV.glsl
Normal file
92
Templates/Full/game/shaders/common/gl/cloudLayerV.glsl
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
varying vec4 texCoord12;
|
||||
varying vec4 texCoord34;
|
||||
varying vec3 vLightTS; // light vector in tangent space, denormalized
|
||||
varying vec3 vViewTS; // view vector in tangent space, denormalized
|
||||
varying vec3 vNormalWS; // Normal vector in world space
|
||||
varying float worldDist;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Uniforms
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform mat4 modelview;
|
||||
uniform vec3 eyePosWorld;
|
||||
uniform vec3 sunVec;
|
||||
uniform vec2 texOffset0;
|
||||
uniform vec2 texOffset1;
|
||||
uniform vec2 texOffset2;
|
||||
uniform vec3 texScale;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
vec4 pos = gl_Vertex;
|
||||
vec3 normal = gl_Normal;
|
||||
vec3 binormal = gl_MultiTexCoord0.xyz;
|
||||
vec3 tangent = gl_MultiTexCoord1.xyz;
|
||||
vec2 uv0 = gl_MultiTexCoord2.st;
|
||||
|
||||
gl_Position = modelview * pos;
|
||||
|
||||
// Offset the uv so we don't have a seam directly over our head.
|
||||
vec2 uv = uv0 + vec2( 0.5, 0.5 );
|
||||
|
||||
texCoord12.xy = uv * texScale.x;
|
||||
texCoord12.xy += texOffset0;
|
||||
|
||||
texCoord12.zw = uv * texScale.y;
|
||||
texCoord12.zw += texOffset1;
|
||||
|
||||
texCoord34.xy = uv * texScale.z;
|
||||
texCoord34.xy += texOffset2;
|
||||
|
||||
texCoord34.z = pos.z;
|
||||
texCoord34.w = 0.0;
|
||||
|
||||
// Transform the normal, tangent and binormal vectors from object space to
|
||||
// homogeneous projection space:
|
||||
vNormalWS = -normal;
|
||||
vec3 vTangentWS = -tangent;
|
||||
vec3 vBinormalWS = -binormal;
|
||||
|
||||
// Compute position in world space:
|
||||
vec4 vPositionWS = pos + vec4( eyePosWorld, 1 ); //mul( pos, objTrans );
|
||||
|
||||
// Compute and output the world view vector (unnormalized):
|
||||
vec3 vViewWS = eyePosWorld - vPositionWS.xyz;
|
||||
|
||||
// Compute denormalized light vector in world space:
|
||||
vec3 vLightWS = -sunVec;
|
||||
|
||||
// Normalize the light and view vectors and transform it to the tangent space:
|
||||
mat3 mWorldToTangent = mat3( vTangentWS, vBinormalWS, vNormalWS );
|
||||
|
||||
// Propagate the view and the light vectors (in tangent space):
|
||||
vLightTS = mWorldToTangent * vLightWS;
|
||||
vViewTS = vViewWS * mWorldToTangent;
|
||||
|
||||
worldDist = clamp( pow( pos.z, 2.0 ), 0.0, 1.0 );
|
||||
}
|
||||
34
Templates/Full/game/shaders/common/gl/debugInteriorsP.glsl
Normal file
34
Templates/Full/game/shaders/common/gl/debugInteriorsP.glsl
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform sampler2D diffuseMap;
|
||||
uniform vec4 shadeColor;
|
||||
|
||||
varying vec2 TEX0;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 diffuseColor = texture2D( diffuseMap, TEX0 );
|
||||
|
||||
gl_FragColor = diffuseColor;
|
||||
gl_FragColor *= shadeColor;
|
||||
}
|
||||
33
Templates/Full/game/shaders/common/gl/debugInteriorsV.glsl
Normal file
33
Templates/Full/game/shaders/common/gl/debugInteriorsV.glsl
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform mat4 modelview;
|
||||
|
||||
varying vec2 TEX0;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
TEX0 = gl_MultiTexCoord0.st;
|
||||
}
|
||||
|
||||
|
||||
196
Templates/Full/game/shaders/common/gl/foliage.glsl
Normal file
196
Templates/Full/game/shaders/common/gl/foliage.glsl
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// CornerId corresponds to this arrangement
|
||||
// from the perspective of the camera.
|
||||
//
|
||||
// 3 ---- 2
|
||||
// | |
|
||||
// 0 ---- 1
|
||||
//
|
||||
|
||||
#define MAX_COVERTYPES 8
|
||||
|
||||
uniform vec3 gc_camRight;
|
||||
uniform vec3 gc_camUp;
|
||||
uniform vec4 gc_typeRects[MAX_COVERTYPES];
|
||||
uniform vec2 gc_fadeParams;
|
||||
uniform vec2 gc_windDir;
|
||||
|
||||
// .x = gust length
|
||||
// .y = premultiplied simulation time and gust frequency
|
||||
// .z = gust strength
|
||||
uniform vec3 gc_gustInfo;
|
||||
|
||||
// .x = premultiplied simulation time and turbulance frequency
|
||||
// .y = turbulance strength
|
||||
uniform vec2 gc_turbInfo;
|
||||
|
||||
|
||||
//static float sMovableCorner[4] = { 0.0, 0.0, 1.0, 1.0 };
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// The following wind effect was derived from the GPU Gems 3 chapter...
|
||||
//
|
||||
// "Vegetation Procedural Animation and Shading in Crysis"
|
||||
// by Tiago Sousa, Crytek
|
||||
//
|
||||
|
||||
vec2 smoothCurve( vec2 x )
|
||||
{
|
||||
return x * x * ( 3.0 - 2.0 * x );
|
||||
}
|
||||
|
||||
vec2 triangleWave( vec2 x )
|
||||
{
|
||||
return abs( fract( x + 0.5 ) * 2.0 - 1.0 );
|
||||
}
|
||||
|
||||
vec2 smoothTriangleWave( vec2 x )
|
||||
{
|
||||
return smoothCurve( triangleWave( x ) );
|
||||
}
|
||||
|
||||
float windTurbulence( float bbPhase, float frequency, float strength )
|
||||
{
|
||||
// We create the input value for wave generation from the frequency and phase.
|
||||
vec2 waveIn = vec2( bbPhase + frequency );
|
||||
|
||||
// We use two square waves to generate the effect which
|
||||
// is then scaled by the overall strength.
|
||||
vec2 waves = ( fract( waveIn.xy * vec2( 1.975, 0.793 ) ) * 2.0 - 1.0 );
|
||||
waves = smoothTriangleWave( waves );
|
||||
|
||||
// Sum up the two waves into a single wave.
|
||||
return ( waves.x + waves.y ) * strength;
|
||||
}
|
||||
|
||||
vec2 windEffect( float bbPhase,
|
||||
vec2 windDirection,
|
||||
float gustLength,
|
||||
float gustFrequency,
|
||||
float gustStrength,
|
||||
float turbFrequency,
|
||||
float turbStrength )
|
||||
{
|
||||
// Calculate the ambient wind turbulence.
|
||||
float turbulence = windTurbulence( bbPhase, turbFrequency, turbStrength );
|
||||
|
||||
// We simulate the overall gust via a sine wave.
|
||||
float gustPhase = clamp( sin( ( bbPhase - gustFrequency ) / gustLength ) , 0.0, 1.0 );
|
||||
float gustOffset = ( gustPhase * gustStrength ) + ( ( 0.2 + gustPhase ) * turbulence );
|
||||
|
||||
// Return the final directional wind effect.
|
||||
return vec2(gustOffset) * windDirection.xy;
|
||||
}
|
||||
|
||||
void foliageProcessVert( inout vec3 position,
|
||||
inout vec4 diffuse,
|
||||
in vec4 texCoord,
|
||||
out vec2 outTexCoord,
|
||||
inout vec3 normal,
|
||||
inout vec3 T,
|
||||
in vec3 eyePos )
|
||||
{
|
||||
|
||||
float sCornerRight[4];
|
||||
sCornerRight[0] = -0.5;
|
||||
sCornerRight[1] = 0.5;
|
||||
sCornerRight[2] = 0.5;
|
||||
sCornerRight[3] = -0.5;
|
||||
|
||||
float sCornerUp[4];
|
||||
sCornerUp[0] = 0.0;
|
||||
sCornerUp[1] = 0.0;
|
||||
sCornerUp[2] = 1.0;
|
||||
sCornerUp[3] = 1.0;
|
||||
|
||||
vec2 sUVCornerExtent[4];
|
||||
sUVCornerExtent[0] = vec2( 0.0, 1.0 );
|
||||
sUVCornerExtent[1] = vec2( 1.0, 1.0 );
|
||||
sUVCornerExtent[2] = vec2( 1.0, 0.0 );
|
||||
sUVCornerExtent[3] = vec2( 0.0, 0.0 );
|
||||
|
||||
|
||||
// Assign the normal and tagent values.
|
||||
//normal = cross( gc_camUp, gc_camRight );
|
||||
T = gc_camRight;
|
||||
|
||||
// Pull out local vars we need for work.
|
||||
int corner = int( ( diffuse.a * 255.0 ) + 0.5 );
|
||||
vec2 size = texCoord.xy;
|
||||
int type = int( texCoord.z );
|
||||
|
||||
// The billboarding is based on the camera direction.
|
||||
vec3 rightVec = gc_camRight * sCornerRight[corner];
|
||||
vec3 upVec = gc_camUp * sCornerUp[corner];
|
||||
|
||||
// Figure out the corner position.
|
||||
vec3 outPos = ( upVec * size.y ) + ( rightVec * size.x );
|
||||
float len = length( outPos.xyz );
|
||||
|
||||
// We derive the billboard phase used for wind calculations from its position.
|
||||
float bbPhase = dot( position.xyz, vec3( 1.0 ) );
|
||||
|
||||
// Get the overall wind gust and turbulence effects.
|
||||
vec3 wind;
|
||||
wind.xy = windEffect( bbPhase,
|
||||
gc_windDir,
|
||||
gc_gustInfo.x, gc_gustInfo.y, gc_gustInfo.z,
|
||||
gc_turbInfo.x, gc_turbInfo.y );
|
||||
wind.z = 0.0;
|
||||
|
||||
// Add the summed wind effect into the point.
|
||||
outPos.xyz += wind.xyz * texCoord.w;
|
||||
|
||||
// Do a simple spherical clamp to keep the foliage
|
||||
// from stretching too much by wind effect.
|
||||
outPos.xyz = normalize( outPos.xyz ) * len;
|
||||
|
||||
// Move the point into world space.
|
||||
position += outPos;
|
||||
|
||||
// Grab the uv set and setup the texture coord.
|
||||
vec4 uvSet = gc_typeRects[type];
|
||||
outTexCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
|
||||
outTexCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
|
||||
|
||||
// Animate the normal to get lighting changes
|
||||
// across the the wind swept foliage.
|
||||
//
|
||||
// TODO: Expose the 10x as a factor to control
|
||||
// how much the wind effects the lighting on the grass.
|
||||
//
|
||||
normal.xy += wind.xy * ( 10.0 * texCoord.w );
|
||||
normal = normalize( normal );
|
||||
|
||||
|
||||
// Get the alpha fade value.
|
||||
|
||||
float fadeStart = gc_fadeParams.x;
|
||||
float fadeEnd = gc_fadeParams.y;
|
||||
float fadeRange = fadeEnd - fadeStart;
|
||||
|
||||
float dist = distance( eyePos, position.xyz ) - fadeStart;
|
||||
diffuse.a = 1.0 - clamp( dist / fadeRange, 0.0, 1.0 );
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform sampler2D diffuseMap, alphaMap;
|
||||
uniform vec4 groundAlpha;
|
||||
|
||||
varying vec4 color, groundAlphaCoeff;
|
||||
varying vec2 outTexCoord, alphaLookup;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
vec4 alpha = texture2D(alphaMap, alphaLookup);
|
||||
gl_FragColor = color * texture2D(diffuseMap, outTexCoord);
|
||||
gl_FragColor.a = gl_FragColor.a * min(alpha, groundAlpha + groundAlphaCoeff.x).x;
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform mat4 projection, world;
|
||||
uniform vec3 CameraPos;
|
||||
uniform float GlobalSwayPhase, SwayMagnitudeSide, SwayMagnitudeFront,
|
||||
GlobalLightPhase, LuminanceMagnitude, LuminanceMidpoint, DistanceRange;
|
||||
|
||||
varying vec4 color, groundAlphaCoeff;
|
||||
varying vec2 outTexCoord, alphaLookup;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
// Init a transform matrix to be used in the following steps
|
||||
mat4 trans = mat4(0.0);
|
||||
trans[0][0] = 1.0;
|
||||
trans[1][1] = 1.0;
|
||||
trans[2][2] = 1.0;
|
||||
trans[3][3] = 1.0;
|
||||
trans[3][0] = gl_Vertex.x;
|
||||
trans[3][1] = gl_Vertex.y;
|
||||
trans[3][2] = gl_Vertex.z;
|
||||
|
||||
// Billboard transform * world matrix
|
||||
mat4 o = world;
|
||||
o = o * trans;
|
||||
|
||||
// Keep only the up axis result and position transform.
|
||||
// This gives us "cheating" cylindrical billboarding.
|
||||
o[0][0] = 1.0;
|
||||
o[0][1] = 0.0;
|
||||
o[0][2] = 0.0;
|
||||
o[0][3] = 0.0;
|
||||
o[1][0] = 0.0;
|
||||
o[1][1] = 1.0;
|
||||
o[1][2] = 0.0;
|
||||
o[1][3] = 0.0;
|
||||
|
||||
// Handle sway. Sway is stored in a texture coord. The x coordinate is the sway phase multiplier,
|
||||
// the y coordinate determines if this vertex actually sways or not.
|
||||
float xSway, ySway;
|
||||
float wavePhase = GlobalSwayPhase * gl_MultiTexCoord1.x;
|
||||
ySway = sin(wavePhase);
|
||||
xSway = cos(wavePhase);
|
||||
xSway = xSway * gl_MultiTexCoord1.y * SwayMagnitudeSide;
|
||||
ySway = ySway * gl_MultiTexCoord1.y * SwayMagnitudeFront;
|
||||
vec4 p;
|
||||
p = o * vec4(gl_Normal.x + xSway, ySway, gl_Normal.z, 1.0);
|
||||
|
||||
// Project the point
|
||||
gl_Position = projection * p;
|
||||
|
||||
// Lighting
|
||||
float Luminance = LuminanceMidpoint + LuminanceMagnitude * cos(GlobalLightPhase + gl_Normal.y);
|
||||
|
||||
// Alpha
|
||||
vec3 worldPos = vec3(gl_Vertex.x, gl_Vertex.y, gl_Vertex.z);
|
||||
float alpha = abs(distance(worldPos, CameraPos)) / DistanceRange;
|
||||
alpha = clamp(alpha, 0.0, 1.0); //pass it through
|
||||
|
||||
alphaLookup = vec2(alpha, 0.0);
|
||||
bool alphaCoeff = bool(gl_Normal.z);
|
||||
groundAlphaCoeff = vec4(float(alphaCoeff));
|
||||
outTexCoord = gl_MultiTexCoord0.st;
|
||||
color = vec4(Luminance, Luminance, Luminance, 1.0);
|
||||
}
|
||||
35
Templates/Full/game/shaders/common/gl/guiMaterialV.glsl
Normal file
35
Templates/Full/game/shaders/common/gl/guiMaterialV.glsl
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform mat4x4 modelview;
|
||||
|
||||
varying vec4 hpos;
|
||||
varying vec2 uv0;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
hpos = vec4( modelview * gl_Vertex );
|
||||
gl_Position = hpos;
|
||||
|
||||
uv0 = gl_MultiTexCoord0.st;
|
||||
}
|
||||
43
Templates/Full/game/shaders/common/gl/hlslCompat.glsl
Normal file
43
Templates/Full/game/shaders/common/gl/hlslCompat.glsl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// These are some simple wrappers for simple
|
||||
// HLSL compatibility.
|
||||
|
||||
#define float4 vec4
|
||||
#define float3 vec3
|
||||
#define float2 vec2
|
||||
|
||||
#define texCUBE textureCube
|
||||
#define tex2D texture2D
|
||||
|
||||
#define lerp mix
|
||||
|
||||
float saturate( float val ) { return clamp( val, 0.0, 1.0 ); }
|
||||
vec2 saturate( vec2 val ) { return clamp( val, 0.0, 1.0 ); }
|
||||
vec3 saturate( vec3 val ) { return clamp( val, 0.0, 1.0 ); }
|
||||
vec4 saturate( vec4 val ) { return clamp( val, 0.0, 1.0 ); }
|
||||
|
||||
float round( float n ) { return sign( n ) * floor( abs( n ) + 0.5 ); }
|
||||
vec2 round( vec2 n ) { return sign( n ) * floor( abs( n ) + 0.5 ); }
|
||||
vec3 round( vec3 n ) { return sign( n ) * floor( abs( n ) + 0.5 ); }
|
||||
vec4 round( vec4 n ) { return sign( n ) * floor( abs( n ) + 0.5 ); }
|
||||
161
Templates/Full/game/shaders/common/gl/imposter.glsl
Normal file
161
Templates/Full/game/shaders/common/gl/imposter.glsl
Normal file
|
|
@ -0,0 +1,161 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "torque.glsl"
|
||||
|
||||
|
||||
#define IMPOSTER_MAX_UVS 64
|
||||
|
||||
|
||||
void imposter_v(
|
||||
// These parameters usually come from the vertex.
|
||||
vec3 center,
|
||||
int corner,
|
||||
float halfSize,
|
||||
vec3 imposterUp,
|
||||
vec3 imposterRight,
|
||||
|
||||
// These are from the imposter shader constant.
|
||||
int numEquatorSteps,
|
||||
int numPolarSteps,
|
||||
float polarAngle,
|
||||
bool includePoles,
|
||||
|
||||
// Other shader constants.
|
||||
vec3 camPos,
|
||||
vec4 uvs[IMPOSTER_MAX_UVS],
|
||||
|
||||
// The outputs of this function.
|
||||
out vec3 outWsPosition,
|
||||
out vec2 outTexCoord,
|
||||
out mat3 outWorldToTangent
|
||||
)
|
||||
{
|
||||
|
||||
float M_HALFPI_F = 1.57079632679489661923;
|
||||
float M_PI_F = 3.14159265358979323846;
|
||||
float M_2PI_F = 6.28318530717958647692;
|
||||
|
||||
|
||||
float sCornerRight[4];// = float[]( -1.0, 1.0, 1.0, -1.0 );
|
||||
sCornerRight[0] = -1.0;
|
||||
sCornerRight[1] = 1.0;
|
||||
sCornerRight[2] = 1.0;
|
||||
sCornerRight[3] = -1.0;
|
||||
float sCornerUp[4];// = float[]( -1.0, -1.0, 1.0, 1.0 );
|
||||
sCornerUp[0] = -1.0;
|
||||
sCornerUp[1] = -1.0;
|
||||
sCornerUp[2] = 1.0;
|
||||
sCornerUp[3] = 1.0;
|
||||
vec2 sUVCornerExtent[4];// = vec2[](vec2( 0.0, 1.0 ), vec2( 1.0, 1.0 ), vec2( 1.0, 0.0 ), vec2( 0.0, 0.0 ));
|
||||
sUVCornerExtent[0] = vec2( 0.0, 1.0 );
|
||||
sUVCornerExtent[1] = vec2( 1.0, 1.0 );
|
||||
sUVCornerExtent[2] = vec2( 1.0, 0.0 );
|
||||
sUVCornerExtent[3] = vec2( 0.0, 0.0 );
|
||||
|
||||
// TODO: This could all be calculated on the CPU.
|
||||
float equatorStepSize = M_2PI_F / float( numEquatorSteps );
|
||||
float equatorHalfStep = ( equatorStepSize / 2.0 ) - 0.0001;
|
||||
float polarStepSize = M_PI_F / float( numPolarSteps );
|
||||
float polarHalfStep = ( polarStepSize / 2.0 ) - 0.0001;
|
||||
|
||||
// The vector between the camera and the billboard.
|
||||
vec3 lookVec = normalize( camPos - center );
|
||||
|
||||
// Generate the camera up and right vectors from
|
||||
// the object transform and camera forward.
|
||||
vec3 camUp = imposterUp;
|
||||
vec3 camRight = cross( -lookVec, camUp );
|
||||
|
||||
// The billboarding is based on the camera directions.
|
||||
vec3 rightVec = camRight * sCornerRight[corner];
|
||||
vec3 upVec = camUp * sCornerUp[corner];
|
||||
|
||||
float lookPitch = acos( dot( imposterUp, lookVec ) );
|
||||
|
||||
// First check to see if we need to render the top billboard.
|
||||
int index;
|
||||
/*
|
||||
if ( includePoles && ( lookPitch < polarAngle || lookPitch > sPi - polarAngle ) )
|
||||
{
|
||||
index = numEquatorSteps * 3;
|
||||
|
||||
// When we render the top/bottom billboard we always use
|
||||
// a fixed vector that matches the rotation of the object.
|
||||
rightVec = vec3( 1, 0, 0 ) * sCornerRight[corner];
|
||||
upVec = vec3( 0, 1, 0 ) * sCornerUp[corner];
|
||||
|
||||
if ( lookPitch > sPi - polarAngle )
|
||||
{
|
||||
upVec = -upVec;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
else
|
||||
*/
|
||||
{
|
||||
// Calculate the rotation around the z axis then add the
|
||||
// equator half step. This gets the images to switch a
|
||||
// half step before the captured angle is met.
|
||||
float lookAzimuth = atan( lookVec.y, lookVec.x );
|
||||
float azimuth = atan( imposterRight.y, imposterRight.x );
|
||||
float rotZ = ( lookAzimuth - azimuth ) + equatorHalfStep;
|
||||
|
||||
// The y rotation is calculated from the look vector and
|
||||
// the object up vector.
|
||||
float rotY = lookPitch - polarHalfStep;
|
||||
|
||||
// TODO: How can we do this without conditionals?
|
||||
// Normalize the result to 0 to 2PI.
|
||||
if ( rotZ < 0.0 )
|
||||
rotZ += M_2PI_F;
|
||||
if ( rotZ > M_2PI_F )
|
||||
rotZ -= M_2PI_F;
|
||||
if ( rotY < 0.0 )
|
||||
rotY += M_2PI_F;
|
||||
if ( rotY > M_PI_F ) // Not M_2PI_F?
|
||||
rotY -= M_2PI_F;
|
||||
|
||||
float polarIdx = round( abs( rotY ) / polarStepSize );
|
||||
|
||||
// Get the index to the start of the right polar
|
||||
// images for this viewing angle.
|
||||
int numPolarOffset = int( float( numEquatorSteps ) * polarIdx );
|
||||
|
||||
// Calculate the final image index for lookup
|
||||
// of the texture coords.
|
||||
index = int( rotZ / equatorStepSize ) + numPolarOffset;
|
||||
}
|
||||
|
||||
// Generate the final world space position.
|
||||
outWsPosition = center + ( upVec * halfSize ) + ( rightVec * halfSize );
|
||||
|
||||
// Grab the uv set and setup the texture coord.
|
||||
vec4 uvSet = uvs[index];
|
||||
outTexCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
|
||||
outTexCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
|
||||
|
||||
// Needed for normal mapping and lighting.
|
||||
outWorldToTangent[0] = vec3( 1, 0, 0 );
|
||||
outWorldToTangent[1] = vec3( 0, 1, 0 );
|
||||
outWorldToTangent[2] = vec3( 0, 0, -1 );
|
||||
}
|
||||
115
Templates/Full/game/shaders/common/gl/lighting.glsl
Normal file
115
Templates/Full/game/shaders/common/gl/lighting.glsl
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// These are the uniforms used by most lighting shaders.
|
||||
|
||||
uniform vec3 inLightPos[4];
|
||||
uniform vec4 inLightInvRadiusSq;
|
||||
uniform vec4 inLightColor[4];
|
||||
uniform vec4 ambient;
|
||||
uniform float specularPower;
|
||||
uniform vec4 specularColor;
|
||||
|
||||
|
||||
// This is used to limit the maximum processed
|
||||
// lights in the compute4Lights down for really
|
||||
// low end GPUs.
|
||||
//
|
||||
// NOTE: If you want to support 10.5.x, this needs to be changed to 2.
|
||||
#define C4L_MAX_LIGHTS 4
|
||||
|
||||
|
||||
void compute4Lights( vec3 wsView,
|
||||
vec3 wsPosition,
|
||||
vec3 wsNormal,
|
||||
out vec4 outDiffuse,
|
||||
out vec4 outSpecular )
|
||||
{
|
||||
#ifdef PHONG_SPECULAR
|
||||
// (R.V)^c
|
||||
float reflected = reflect( wsView, wsNormal );
|
||||
#endif
|
||||
|
||||
vec4 nDotL = vec4( 0.0 );
|
||||
vec4 rDotL = vec4( 0.0 );
|
||||
vec4 sqDists = vec4( 0.0 );
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < C4L_MAX_LIGHTS; ++i )
|
||||
{
|
||||
vec3 lightVector = inLightPos[i] - wsPosition;
|
||||
vec3 lightDirection = normalize( lightVector );
|
||||
|
||||
nDotL[i] = max( dot( lightDirection, wsNormal ), 0.0 );
|
||||
|
||||
#ifdef PHONG_SPECULAR
|
||||
rDotL[i] = saturate( dot( lightDirection, reflected ) );
|
||||
#else
|
||||
// (N.H)^c [Blinn-Phong, TGEA style, default]
|
||||
rDotL[i] = dot( wsNormal, normalize( lightDirection + wsView ) );
|
||||
#endif
|
||||
|
||||
sqDists[i] = dot( lightVector, lightVector );
|
||||
}
|
||||
|
||||
// Attenuation
|
||||
vec4 atten = vec4( 1.0 ) - ( sqDists * inLightInvRadiusSq );
|
||||
|
||||
// Combine the light colors for output.
|
||||
vec4 diffuse = clamp( nDotL * atten, vec4( 0.0 ), vec4( 1.0 ) );
|
||||
outDiffuse = vec4( 0.0 );
|
||||
for ( i = 0; i < C4L_MAX_LIGHTS; ++i )
|
||||
outDiffuse += vec4( diffuse[i] ) * inLightColor[i];
|
||||
|
||||
// Output the specular power.
|
||||
rDotL = max( rDotL, vec4( 0.00001 ) );
|
||||
outSpecular = pow( rDotL, vec4( specularPower ) );
|
||||
}
|
||||
|
||||
|
||||
/// The standard specular calculation.
|
||||
///
|
||||
/// @param toLight Normalized vector representing direction from the pixel
|
||||
/// being lit, to the light source, in world space.
|
||||
///
|
||||
/// @param normal Normalized surface normal.
|
||||
///
|
||||
/// @param toEye The normalized vector representing direction from the pixel
|
||||
/// being lit to the camera.
|
||||
///
|
||||
/// @param specPwr The specular exponent.
|
||||
///
|
||||
/// @param specScale A scalar on the specular output used in RGB accumulation.
|
||||
///
|
||||
float calcSpecular( vec3 toLight, vec3 normal, vec3 toEye, float specPwr )
|
||||
{
|
||||
#ifdef PHONG_SPECULAR
|
||||
// (R.V)^c
|
||||
float specVal = dot( normalize( -reflect( toLight, normal ) ), toEye );
|
||||
#else
|
||||
// (N.H)^c [Blinn-Phong, TGEA style, default]
|
||||
float specVal = dot( normal, normalize( toLight + toEye ) );
|
||||
#endif
|
||||
|
||||
// Return the specular factor.
|
||||
return pow( max( specVal, 0.00001f ), specPwr );
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "torque.glsl"
|
||||
|
||||
uniform sampler2D colorSource;
|
||||
uniform vec4 offscreenTargetParams;
|
||||
|
||||
#ifdef TORQUE_LINEAR_DEPTH
|
||||
#define REJECT_EDGES
|
||||
uniform sampler2D edgeSource;
|
||||
uniform vec4 edgeTargetParams;
|
||||
#endif
|
||||
|
||||
varying vec4 backbufferPos;
|
||||
varying vec4 offscreenPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Off-screen particle source screenspace position in XY
|
||||
// Back-buffer screenspace position in ZW
|
||||
vec4 ssPos = vec4(offscreenPos.xy / offscreenPos.w, backbufferPos.xy / backbufferPos.w);
|
||||
|
||||
vec4 uvScene = ( ssPos + 1.0 ) / 2.0;
|
||||
uvScene.yw = 1.0 - uvScene.yw;
|
||||
uvScene.xy = viewportCoordToRenderTarget(uvScene.xy, offscreenTargetParams);
|
||||
|
||||
#ifdef REJECT_EDGES
|
||||
// Cut out particles along the edges, this will create the stencil mask
|
||||
uvScene.zw = viewportCoordToRenderTarget(uvScene.zw, edgeTargetParams);
|
||||
float edge = texture2D( edgeSource, uvScene.zw ).r;
|
||||
if (-edge < 0.0)
|
||||
discard;
|
||||
#endif
|
||||
|
||||
// Sample offscreen target and return
|
||||
gl_FragColor = texture2D( colorSource, uvScene.xy );
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform mat4 modelViewProj;
|
||||
uniform mat4 targetModelViewProj;
|
||||
|
||||
varying vec4 offscreenPos;
|
||||
varying vec4 backbufferPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelViewProj * gl_Vertex;
|
||||
backbufferPos = gl_Position;
|
||||
offscreenPos = targetModelViewProj * gl_Vertex;
|
||||
}
|
||||
|
||||
82
Templates/Full/game/shaders/common/gl/particlesP.glsl
Normal file
82
Templates/Full/game/shaders/common/gl/particlesP.glsl
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "hlslCompat.glsl"
|
||||
#include "torque.glsl"
|
||||
|
||||
// With advanced lighting we get soft particles.
|
||||
#ifdef TORQUE_LINEAR_DEPTH
|
||||
#define SOFTPARTICLES
|
||||
#endif
|
||||
|
||||
#define CLIP_Z // TODO: Make this a proper macro
|
||||
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
#ifdef SOFTPARTICLES
|
||||
|
||||
#include "shadergen:/autogenConditioners.h"
|
||||
|
||||
uniform float oneOverSoftness;
|
||||
uniform float oneOverFar;
|
||||
uniform sampler2D prepassTex;
|
||||
//uniform vec3 vEye;
|
||||
uniform vec4 prePassTargetParams;
|
||||
#endif
|
||||
|
||||
uniform float alphaFactor;
|
||||
uniform float alphaScale;
|
||||
|
||||
varying vec4 color;
|
||||
varying vec2 uv0;
|
||||
varying vec4 pos;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
float softBlend = 1.0;
|
||||
|
||||
#ifdef SOFTPARTICLES
|
||||
float2 tc = pos.xy * vec2(1.0, -1.0 ) / pos.w;
|
||||
tc = viewportCoordToRenderTarget(saturate( ( tc + 1.0 ) * 0.5 ), prePassTargetParams);
|
||||
|
||||
float sceneDepth = prepassUncondition( prepassTex, tc ).w;
|
||||
float depth = pos.w * oneOverFar;
|
||||
float diff = sceneDepth - depth;
|
||||
#ifdef CLIP_Z
|
||||
// If drawing offscreen, this acts as the depth test, since we don't line up with the z-buffer
|
||||
// When drawing high-res, though, we want to be able to take advantage of hi-z
|
||||
// so this is #ifdef'd out
|
||||
if (diff < 0.0)
|
||||
discard;
|
||||
#endif
|
||||
softBlend = saturate( diff * oneOverSoftness );
|
||||
#endif
|
||||
|
||||
vec4 diffuse = texture2D( diffuseMap, uv0 );
|
||||
|
||||
// Scale output color by the alpha factor (turn LerpAlpha into pre-multiplied alpha)
|
||||
vec3 colorScale = ( alphaFactor < 0.0 ? color.rgb * diffuse.rgb : ( alphaFactor > 0.0 ? vec3(color.a * alphaFactor * diffuse.a * softBlend) : vec3(softBlend) ) );
|
||||
|
||||
gl_FragColor = hdrEncode( vec4(color.rgb * diffuse.rgb * colorScale, softBlend * color.a * diffuse.a * alphaScale) );
|
||||
}
|
||||
|
||||
37
Templates/Full/game/shaders/common/gl/particlesV.glsl
Normal file
37
Templates/Full/game/shaders/common/gl/particlesV.glsl
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
varying vec4 color;
|
||||
varying vec2 uv0;
|
||||
varying vec4 pos;
|
||||
|
||||
uniform mat4 modelViewProj;
|
||||
uniform mat4 fsModelViewProj;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelViewProj * gl_Vertex;
|
||||
pos = fsModelViewProj * gl_Vertex;
|
||||
color = gl_Color;
|
||||
uv0 = gl_MultiTexCoord0.st;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform sampler2D diffuseMap, refractMap, bumpMap;
|
||||
uniform vec4 shadeColor;
|
||||
|
||||
varying vec2 TEX0;
|
||||
varying vec4 TEX1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Fade edges of axis for texcoord passed in
|
||||
//-----------------------------------------------------------------------------
|
||||
float fadeAxis( float val )
|
||||
{
|
||||
// Fades from 1.0 to 0.0 when less than 0.1
|
||||
float fadeLow = clamp( val * 10.0, 0.0, 1.0 );
|
||||
|
||||
// Fades from 1.0 to 0.0 when greater than 0.9
|
||||
float fadeHigh = 1.0 - clamp( (val - 0.9) * 10.0, 0.0, 1.0 );
|
||||
|
||||
return fadeLow * fadeHigh;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
vec3 bumpNorm = texture2D( bumpMap, TEX0 ).rgb * 2.0 - 1.0;
|
||||
vec2 offset = vec2( bumpNorm.x, bumpNorm.y );
|
||||
vec4 texIndex = TEX1;
|
||||
|
||||
// The fadeVal is used to "fade" the distortion at the edges of the screen.
|
||||
// This is done so it won't sample the reflection texture out-of-bounds and create artifacts
|
||||
// Note - this can be done more efficiently with a texture lookup
|
||||
float fadeVal = fadeAxis( texIndex.x / texIndex.w ) * fadeAxis( texIndex.y / texIndex.w );
|
||||
|
||||
const float distortion = 0.2;
|
||||
texIndex.xy += offset * distortion * fadeVal;
|
||||
|
||||
vec4 diffuseColor = texture2D( diffuseMap, TEX0 );
|
||||
vec4 reflectColor = texture2DProj( refractMap, texIndex );
|
||||
|
||||
gl_FragColor = diffuseColor + reflectColor * diffuseColor.a;
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform mat4 modelview;
|
||||
|
||||
varying vec2 TEX0;
|
||||
varying vec4 TEX1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
mat4 texGenTest = mat4(0.5, 0.0, 0.0, 0.0,
|
||||
0.0, -0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.5, 0.5, 0.0, 1.0);
|
||||
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
|
||||
TEX0 = gl_MultiTexCoord0.st;
|
||||
|
||||
TEX1 = texGenTest * gl_Position;
|
||||
TEX1.y = -TEX1.y;
|
||||
|
||||
}
|
||||
41
Templates/Full/game/shaders/common/gl/planarReflectP.glsl
Normal file
41
Templates/Full/game/shaders/common/gl/planarReflectP.glsl
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform sampler2D diffuseMap, refractMap;
|
||||
uniform vec4 shadeColor;
|
||||
|
||||
varying vec2 TEX0;
|
||||
varying vec4 TEX1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
vec4 diffuseColor = texture2D( diffuseMap, TEX0 );
|
||||
vec4 reflectColor = texture2DProj( refractMap, TEX1 );
|
||||
|
||||
gl_FragColor = diffuseColor + reflectColor * diffuseColor.a;
|
||||
}
|
||||
48
Templates/Full/game/shaders/common/gl/planarReflectV.glsl
Normal file
48
Templates/Full/game/shaders/common/gl/planarReflectV.glsl
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform mat4 modelview;
|
||||
|
||||
varying vec2 TEX0;
|
||||
varying vec4 TEX1;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
mat4 texGenTest = mat4(0.5, 0.0, 0.0, 0.0,
|
||||
0.0, -0.5, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
0.5, 0.5, 0.0, 1.0);
|
||||
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
|
||||
TEX0 = gl_MultiTexCoord0.st;
|
||||
|
||||
TEX1 = texGenTest * gl_Position;
|
||||
TEX1.y = -TEX1.y;
|
||||
|
||||
}
|
||||
37
Templates/Full/game/shaders/common/gl/precipP.glsl
Normal file
37
Templates/Full/game/shaders/common/gl/precipP.glsl
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform sampler2D diffuseMap;
|
||||
|
||||
varying vec4 color;
|
||||
varying vec2 texCoord;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(diffuseMap, texCoord) * color;
|
||||
}
|
||||
50
Templates/Full/game/shaders/common/gl/precipV.glsl
Normal file
50
Templates/Full/game/shaders/common/gl/precipV.glsl
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Data
|
||||
//-----------------------------------------------------------------------------
|
||||
uniform mat4 modelview;
|
||||
uniform vec3 cameraPos, ambient;
|
||||
uniform vec2 fadeStartEnd;
|
||||
|
||||
varying vec4 color;
|
||||
varying vec2 texCoord;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Main
|
||||
//-----------------------------------------------------------------------------
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * gl_Vertex;
|
||||
texCoord = gl_MultiTexCoord0.st;
|
||||
color = vec4( ambient.r, ambient.g, ambient.b, 1.0 );
|
||||
|
||||
// Do we need to do a distance fade?
|
||||
if ( fadeStartEnd.x < fadeStartEnd.y )
|
||||
{
|
||||
|
||||
float distance = length( cameraPos - gl_Vertex.xyz );
|
||||
color.a = abs( clamp( ( distance - fadeStartEnd.x ) / ( fadeStartEnd.y - fadeStartEnd.x ), 0.0, 1.0 ) - 1.0 );
|
||||
}
|
||||
}
|
||||
|
||||
46
Templates/Full/game/shaders/common/gl/projectedShadowP.glsl
Normal file
46
Templates/Full/game/shaders/common/gl/projectedShadowP.glsl
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec4 color;
|
||||
varying float fade;
|
||||
|
||||
uniform sampler2D inputTex;
|
||||
uniform vec4 ambient;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 LUMINANCE_VECTOR = vec3(0.2125f, 0.4154f, 0.1721f);
|
||||
float esmFactor = 200.0;
|
||||
|
||||
float lum = dot( ambient.rgb, LUMINANCE_VECTOR );
|
||||
|
||||
gl_FragColor.rgb = ambient.rgb * lum;
|
||||
gl_FragColor.a = 0.0;
|
||||
float depth = texture2D(inputTex, texCoord).a;
|
||||
|
||||
depth = depth * exp(depth - 10.0);
|
||||
depth = exp(esmFactor * depth) - 1.0;
|
||||
|
||||
gl_FragColor.a = clamp(depth * 300.0, 0.0, 1.0) * (1.0 - lum) * fade * color.a;
|
||||
}
|
||||
44
Templates/Full/game/shaders/common/gl/projectedShadowV.glsl
Normal file
44
Templates/Full/game/shaders/common/gl/projectedShadowV.glsl
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//*****************************************************************************
|
||||
// Precipitation vertex shader
|
||||
//*****************************************************************************
|
||||
|
||||
varying vec2 texCoord;
|
||||
varying vec4 color;
|
||||
varying float fade;
|
||||
|
||||
uniform mat4 modelview;
|
||||
uniform float shadowLength;
|
||||
uniform vec3 shadowCasterPosition;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = modelview * vec4(gl_Vertex.xyz, 1.0);
|
||||
|
||||
color = gl_Color;
|
||||
texCoord = gl_MultiTexCoord1.st;
|
||||
|
||||
float fromCasterDist = length(gl_Vertex.xyz - shadowCasterPosition) - shadowLength;
|
||||
fade = 1.0 - clamp(fromCasterDist/shadowLength, 0.0, 1.0);
|
||||
}
|
||||
79
Templates/Full/game/shaders/common/gl/scatterSkyP.glsl
Normal file
79
Templates/Full/game/shaders/common/gl/scatterSkyP.glsl
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "torque.glsl"
|
||||
|
||||
// Calculates the Mie phase function
|
||||
float getMiePhase(float fCos, float fCos2, float g, float g2)
|
||||
{
|
||||
return 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos2) / pow(abs(1.0 + g2 - 2.0*g*fCos), 1.5);
|
||||
}
|
||||
|
||||
// Calculates the Rayleigh phase function
|
||||
float getRayleighPhase(float fCos2)
|
||||
{
|
||||
//return 1.0;
|
||||
return 0.75 + 0.75*fCos2;
|
||||
}
|
||||
|
||||
varying vec4 rayleighColor;
|
||||
varying vec4 mieColor;
|
||||
varying vec3 v3Direction;
|
||||
varying float zPosition;
|
||||
varying vec3 pos;
|
||||
|
||||
uniform samplerCube nightSky;
|
||||
uniform vec4 nightColor;
|
||||
uniform vec2 nightInterpAndExposure;
|
||||
uniform float useCubemap;
|
||||
uniform vec3 lightDir;
|
||||
uniform vec3 sunDir;
|
||||
|
||||
void main()
|
||||
{
|
||||
float fCos = dot( lightDir, v3Direction ) / length(v3Direction);
|
||||
float fCos2 = fCos*fCos;
|
||||
|
||||
float g = -0.991;
|
||||
float g2 = -0.991 * -0.991;
|
||||
|
||||
float fMiePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + fCos2) / pow(abs(1.0 + g2 - 2.0*g*fCos), 1.5);
|
||||
|
||||
vec4 color = rayleighColor + fMiePhase * mieColor;
|
||||
color.a = color.b;
|
||||
|
||||
vec4 nightSkyColor = textureCube(nightSky, -v3Direction);
|
||||
nightSkyColor = mix(nightColor, nightSkyColor, useCubemap);
|
||||
|
||||
float fac = dot( normalize( pos ), sunDir );
|
||||
fac = max( nightInterpAndExposure.y, pow( clamp( fac, 0.0, 1.0 ), 2 ) );
|
||||
gl_FragColor = mix( color, nightSkyColor, nightInterpAndExposure.y );
|
||||
|
||||
// Clip based on the camera-relative
|
||||
// z position of the vertex, passed through
|
||||
// from the vertex position.
|
||||
if(zPosition < 0.0)
|
||||
discard;
|
||||
|
||||
gl_FragColor.a = 1;
|
||||
gl_FragColor = hdrEncode( gl_FragColor );
|
||||
}
|
||||
165
Templates/Full/game/shaders/common/gl/scatterSkyV.glsl
Normal file
165
Templates/Full/game/shaders/common/gl/scatterSkyV.glsl
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const int nSamples = 4;
|
||||
const float fSamples = 4.0;
|
||||
|
||||
// The scale depth (the altitude at which the average atmospheric density is found)
|
||||
const float fScaleDepth = 0.25;
|
||||
const float fInvScaleDepth = 1.0 / 0.25;
|
||||
|
||||
// The scale equation calculated by Vernier's Graphical Analysis
|
||||
float vernierScale(float fCos)
|
||||
{
|
||||
float x = 1.0 - fCos;
|
||||
float x5 = x * 5.25;
|
||||
float x5p6 = (-6.80 + x5);
|
||||
float xnew = (3.83 + x * x5p6);
|
||||
float xfinal = (0.459 + x * xnew);
|
||||
float xfinal2 = -0.00287 + x * xfinal;
|
||||
float outx = exp( xfinal2 );
|
||||
return 0.25 * outx;
|
||||
}
|
||||
|
||||
// This is the shader output data.
|
||||
varying vec4 rayleighColor;
|
||||
varying vec4 mieColor;
|
||||
varying vec3 v3Direction;
|
||||
varying float zPosition;
|
||||
varying vec3 pos;
|
||||
|
||||
uniform mat4 modelView;
|
||||
uniform vec4 misc;
|
||||
uniform vec4 sphereRadii;
|
||||
uniform vec4 scatteringCoeffs;
|
||||
uniform vec3 camPos;
|
||||
uniform vec3 lightDir;
|
||||
uniform vec4 invWaveLength;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 position = gl_Vertex.xyzw;
|
||||
vec3 normal = gl_Normal.xyz;
|
||||
vec4 color = gl_MultiTexCoord0.xyzw;
|
||||
|
||||
// Pull some variables out:
|
||||
float camHeight = misc.x;
|
||||
float camHeightSqr = misc.y;
|
||||
|
||||
float scale = misc.z;
|
||||
float scaleOverScaleDepth = misc.w;
|
||||
|
||||
float outerRadius = sphereRadii.x;
|
||||
float outerRadiusSqr = sphereRadii.y;
|
||||
|
||||
float innerRadius = sphereRadii.z;
|
||||
float innerRadiusSqr = sphereRadii.w;
|
||||
|
||||
float rayleighBrightness = scatteringCoeffs.x; // Kr * ESun
|
||||
float rayleigh4PI = scatteringCoeffs.y; // Kr * 4 * PI
|
||||
|
||||
float mieBrightness = scatteringCoeffs.z; // Km * ESun
|
||||
float mie4PI = scatteringCoeffs.w; // Km * 4 * PI
|
||||
|
||||
// Get the ray from the camera to the vertex,
|
||||
// and its length (which is the far point of the ray
|
||||
// passing through the atmosphere).
|
||||
vec3 v3Pos = position.xyz / 6378000.0;// / outerRadius;
|
||||
vec3 newCamPos = vec3( 0, 0, camHeight );
|
||||
v3Pos.z += innerRadius;
|
||||
vec3 v3Ray = v3Pos.xyz - newCamPos;
|
||||
float fFar = length(v3Ray);
|
||||
v3Ray /= fFar;
|
||||
|
||||
// Calculate the ray's starting position,
|
||||
// then calculate its scattering offset.
|
||||
vec3 v3Start = newCamPos;
|
||||
float fHeight = length(v3Start);
|
||||
float fDepth = exp(scaleOverScaleDepth * (innerRadius - camHeight));
|
||||
float fStartAngle = dot(v3Ray, v3Start) / fHeight;
|
||||
|
||||
float x = 1.0 - fStartAngle;
|
||||
float x5 = x * 5.25;
|
||||
float x5p6 = (-6.80 + x5);
|
||||
float xnew = (3.83 + x * x5p6);
|
||||
float xfinal = (0.459 + x * xnew);
|
||||
float xfinal2 = -0.00287 + x * xfinal;
|
||||
float othx = exp( xfinal2 );
|
||||
float vscale1 = 0.25 * othx;
|
||||
|
||||
float fStartOffset = fDepth * vscale1;//vernierScale(fStartAngle);
|
||||
|
||||
// Initialize the scattering loop variables.
|
||||
float fSampleLength = fFar / 2.0;
|
||||
float fScaledLength = fSampleLength * scale;
|
||||
vec3 v3SampleRay = v3Ray * fSampleLength;
|
||||
vec3 v3SamplePoint = v3Start + v3SampleRay * 0.5;
|
||||
|
||||
// Now loop through the sample rays
|
||||
vec3 v3FrontColor = vec3(0.0, 0.0, 0.0);
|
||||
for(int i=0; i<2; i++)
|
||||
{
|
||||
float fHeight = length(v3SamplePoint);
|
||||
float fDepth = exp(scaleOverScaleDepth * (innerRadius - fHeight));
|
||||
float fLightAngle = dot(lightDir, v3SamplePoint) / fHeight;
|
||||
float fCameraAngle = dot(v3Ray, v3SamplePoint) / fHeight;
|
||||
|
||||
x = 1.0 - fCameraAngle;
|
||||
x5 = x * 5.25;
|
||||
x5p6 = (-6.80 + x5);
|
||||
xnew = (3.83 + x * x5p6);
|
||||
xfinal = (0.459 + x * xnew);
|
||||
xfinal2 = -0.00287 + x * xfinal;
|
||||
othx = exp( xfinal2 );
|
||||
float vscale3 = 0.25 * othx;
|
||||
|
||||
|
||||
x = 1.0 - fLightAngle;
|
||||
x5 = x * 5.25;
|
||||
x5p6 = (-6.80 + x5);
|
||||
xnew = (3.83 + x * x5p6);
|
||||
xfinal = (0.459 + x * xnew);
|
||||
xfinal2 = -0.00287 + x * xfinal;
|
||||
othx = exp( xfinal2 );
|
||||
float vscale2 = 0.25 * othx;
|
||||
|
||||
float fScatter = (fStartOffset + fDepth*(vscale2 - vscale3));
|
||||
vec3 v3Attenuate = exp(-fScatter * (invWaveLength.xyz * rayleigh4PI + mie4PI));
|
||||
v3FrontColor += v3Attenuate * (fDepth * fScaledLength);
|
||||
v3SamplePoint += v3SampleRay;
|
||||
}
|
||||
|
||||
// Finally, scale the Mie and Rayleigh colors
|
||||
// and set up the varying variables for the pixel shader.
|
||||
gl_Position = modelView * position;
|
||||
mieColor.rgb = v3FrontColor * mieBrightness;
|
||||
mieColor.a = 1.0;
|
||||
rayleighColor.rgb = v3FrontColor * (invWaveLength.xyz * rayleighBrightness);
|
||||
rayleighColor.a = 1.0;
|
||||
v3Direction = newCamPos - v3Pos.xyz;
|
||||
|
||||
// This offset is to get rid of the black line between the atmosky and the waterPlane
|
||||
// along the horizon.
|
||||
zPosition = position.z + 4000.0;
|
||||
pos = position.xyz;
|
||||
}
|
||||
|
||||
246
Templates/Full/game/shaders/common/gl/torque.glsl
Normal file
246
Templates/Full/game/shaders/common/gl/torque.glsl
Normal file
|
|
@ -0,0 +1,246 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef _TORQUE_GLSL_
|
||||
#define _TORQUE_GLSL_
|
||||
|
||||
|
||||
float M_HALFPI_F = 1.57079632679489661923;
|
||||
float M_PI_F = 3.14159265358979323846;
|
||||
float M_2PI_F = 6.28318530717958647692;
|
||||
|
||||
/// Calculate fog based on a start and end positions in worldSpace.
|
||||
float computeSceneFog( vec3 startPos,
|
||||
vec3 endPos,
|
||||
float fogDensity,
|
||||
float fogDensityOffset,
|
||||
float fogHeightFalloff )
|
||||
{
|
||||
float f = length( startPos - endPos ) - fogDensityOffset;
|
||||
float h = 1.0 - ( endPos.z * fogHeightFalloff );
|
||||
return exp( -fogDensity * f * h );
|
||||
}
|
||||
|
||||
|
||||
/// Calculate fog based on a start and end position and a height.
|
||||
/// Positions do not need to be in worldSpace but height does.
|
||||
float computeSceneFog( vec3 startPos,
|
||||
vec3 endPos,
|
||||
float height,
|
||||
float fogDensity,
|
||||
float fogDensityOffset,
|
||||
float fogHeightFalloff )
|
||||
{
|
||||
float f = length( startPos - endPos ) - fogDensityOffset;
|
||||
float h = 1.0 - ( height * fogHeightFalloff );
|
||||
return exp( -fogDensity * f * h );
|
||||
}
|
||||
|
||||
|
||||
/// Calculate fog based on a distance, height is not used.
|
||||
float computeSceneFog( float dist, float fogDensity, float fogDensityOffset )
|
||||
{
|
||||
float f = dist - fogDensityOffset;
|
||||
return exp( -fogDensity * f );
|
||||
}
|
||||
|
||||
|
||||
/// Convert a vec4 uv in viewport space to render target space.
|
||||
vec2 viewportCoordToRenderTarget( vec4 inCoord, vec4 rtParams )
|
||||
{
|
||||
vec2 outCoord = inCoord.xy / inCoord.w;
|
||||
outCoord = ( outCoord * rtParams.zw ) + rtParams.xy;
|
||||
return outCoord;
|
||||
}
|
||||
|
||||
|
||||
/// Convert a vec2 uv in viewport space to render target space.
|
||||
vec2 viewportCoordToRenderTarget( vec2 inCoord, vec4 rtParams )
|
||||
{
|
||||
vec2 outCoord = ( inCoord * rtParams.zw ) + rtParams.xy;
|
||||
return outCoord;
|
||||
}
|
||||
|
||||
|
||||
/// Convert a vec4 quaternion into a 3x3 matrix.
|
||||
mat3x3 quatToMat( vec4 quat )
|
||||
{
|
||||
float xs = quat.x * 2.0;
|
||||
float ys = quat.y * 2.0;
|
||||
float zs = quat.z * 2.0;
|
||||
|
||||
float wx = quat.w * xs;
|
||||
float wy = quat.w * ys;
|
||||
float wz = quat.w * zs;
|
||||
|
||||
float xx = quat.x * xs;
|
||||
float xy = quat.x * ys;
|
||||
float xz = quat.x * zs;
|
||||
|
||||
float yy = quat.y * ys;
|
||||
float yz = quat.y * zs;
|
||||
float zz = quat.z * zs;
|
||||
|
||||
mat3x3 mat;
|
||||
|
||||
mat[0][0] = 1.0 - (yy + zz);
|
||||
mat[1][0] = xy - wz;
|
||||
mat[2][0] = xz + wy;
|
||||
|
||||
mat[0][1] = xy + wz;
|
||||
mat[1][1] = 1.0 - (xx + zz);
|
||||
mat[2][1] = yz - wx;
|
||||
|
||||
mat[0][2] = xz - wy;
|
||||
mat[1][2] = yz + wx;
|
||||
mat[2][2] = 1.0 - (xx + yy);
|
||||
|
||||
return mat;
|
||||
}
|
||||
|
||||
/// The number of additional substeps we take when refining
|
||||
/// the results of the offset parallax mapping function below.
|
||||
///
|
||||
/// You should turn down the number of steps if your needing
|
||||
/// more performance out of your parallax surfaces. Increasing
|
||||
/// the number doesn't yeild much better results and is rarely
|
||||
/// worth the additional cost.
|
||||
///
|
||||
#define PARALLAX_REFINE_STEPS 3
|
||||
|
||||
/// Performs fast parallax offset mapping using
|
||||
/// multiple refinement steps.
|
||||
////// @param texMap The texture map whos alpha channel we sample the parallax depth.
|
||||
/// @param texCoord The incoming texture coordinate for sampling the parallax depth.
|
||||
/// @param negViewTS The negative view vector in tangent space.
|
||||
/// @param depthScale The parallax factor used to scale the depth result.
|
||||
///
|
||||
vec2 parallaxOffset( sampler2D texMap, vec2 texCoord, vec3 negViewTS, float depthScale )
|
||||
{
|
||||
float depth = texture2D( texMap, texCoord ).a;
|
||||
vec2 offset = negViewTS.xy * ( depth * depthScale );
|
||||
|
||||
for ( int i=0; i < PARALLAX_REFINE_STEPS; i++ )
|
||||
{
|
||||
depth = ( depth + texture2D( texMap, texCoord + offset ).a ) * 0.5;
|
||||
offset = negViewTS.xy * ( depth * depthScale );
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
/// The maximum value for 16bit per component integer HDR encoding.
|
||||
const float HDR_RGB16_MAX = 100.0;
|
||||
/// The maximum value for 10bit per component integer HDR encoding.const float HDR_RGB10_MAX = 4.0;
|
||||
|
||||
/// Encodes an HDR color for storage into a target.
|
||||
vec3 hdrEncode( vec3 sample ){
|
||||
#if defined( TORQUE_HDR_RGB16 )
|
||||
|
||||
return sample / HDR_RGB16_MAX;
|
||||
|
||||
#elif defined( TORQUE_HDR_RGB10 )
|
||||
|
||||
return sample / HDR_RGB10_MAX;
|
||||
|
||||
#else
|
||||
|
||||
// No encoding.
|
||||
return sample;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Encodes an HDR color for storage into a target.
|
||||
vec4 hdrEncode( vec4 sample )
|
||||
{
|
||||
return vec4( hdrEncode( sample.rgb ), sample.a );
|
||||
}
|
||||
|
||||
/// Decodes an HDR color from a target.
|
||||
vec3 hdrDecode( vec3 sample )
|
||||
{
|
||||
#if defined( TORQUE_HDR_RGB16 )
|
||||
|
||||
return sample * HDR_RGB16_MAX;
|
||||
|
||||
#elif defined( TORQUE_HDR_RGB10 )
|
||||
|
||||
return sample * HDR_RGB10_MAX;
|
||||
|
||||
#else
|
||||
|
||||
// No encoding.
|
||||
return sample;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Decodes an HDR color from a target.
|
||||
vec4 hdrDecode( vec4 sample )
|
||||
{
|
||||
return vec4( hdrDecode( sample.rgb ), sample.a );
|
||||
}
|
||||
|
||||
/// Returns the luminance for an HDR pixel.
|
||||
float hdrLuminance( vec3 sample )
|
||||
{
|
||||
// There are quite a few different ways to
|
||||
// calculate luminance from an rgb value.
|
||||
//
|
||||
// If you want to use a different technique
|
||||
// then plug it in here.
|
||||
//
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Max component luminance.
|
||||
//
|
||||
//float lum = max( sample.r, max( sample.g, sample.b ) );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// The perceptual relative luminance.
|
||||
//
|
||||
// See http://en.wikipedia.org/wiki/Luminance_(relative)
|
||||
//
|
||||
const vec3 RELATIVE_LUMINANCE = vec3( 0.2126, 0.7152, 0.0722 );
|
||||
float lum = dot( sample, RELATIVE_LUMINANCE );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// The average component luminance.
|
||||
//
|
||||
//const vec3 AVERAGE_LUMINANCE = vec3( 0.3333, 0.3333, 0.3333 );
|
||||
//float lum = dot( sample, AVERAGE_LUMINANCE );
|
||||
|
||||
return lum;
|
||||
}
|
||||
|
||||
|
||||
/// Basic assert macro. If the condition fails, then the shader will output color.
|
||||
/// @param condition This should be a bvec[2-4]. If any items is false, condition is considered to fail.
|
||||
/// @param color The color that should be outputted if the condition fails.
|
||||
/// @note This macro will only work in the void main() method of a pixel shader.
|
||||
#define assert(condition, color) { if(!any(condition)) { gl_FragColor = color; return; } }
|
||||
|
||||
#endif // _TORQUE_GLSL_
|
||||
55
Templates/Full/game/shaders/common/gl/wavesP.glsl
Normal file
55
Templates/Full/game/shaders/common/gl/wavesP.glsl
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
uniform sampler2D diffMap;
|
||||
uniform sampler2D bumpMap;
|
||||
uniform samplerCube cubeMap;
|
||||
uniform vec4 specularColor;
|
||||
uniform float specularPower;
|
||||
uniform vec4 ambient;
|
||||
uniform float accumTime;
|
||||
|
||||
varying vec2 TEX0;
|
||||
varying vec4 outLightVec;
|
||||
varying vec3 outPos;
|
||||
varying vec3 outEyePos;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 texOffset;
|
||||
float sinOffset1 = sin( accumTime * 1.5 + TEX0.y * 6.28319 * 3.0 ) * 0.03;
|
||||
float sinOffset2 = sin( accumTime * 3.0 + TEX0.y * 6.28319 ) * 0.04;
|
||||
|
||||
texOffset.x = TEX0.x + sinOffset1 + sinOffset2;
|
||||
texOffset.y = TEX0.y + cos( accumTime * 3.0 + TEX0.x * 6.28319 * 2.0 ) * 0.05;
|
||||
|
||||
vec4 bumpNorm = texture2D(bumpMap, texOffset) * 2.0 - 1.0;
|
||||
vec4 diffuse = texture2D(diffMap, texOffset);
|
||||
|
||||
gl_FragColor = diffuse * (clamp(dot(outLightVec.xyz, bumpNorm.xyz), 0.0, 1.0) + ambient);
|
||||
|
||||
vec3 eyeVec = normalize(outEyePos - outPos);
|
||||
vec3 halfAng = normalize(eyeVec + outLightVec.xyz);
|
||||
float specular = clamp(dot(bumpNorm.xyz, halfAng), 0.0, 1.0) * outLightVec.w;
|
||||
specular = pow(specular, specularPower);
|
||||
gl_FragColor += specularColor * specular;
|
||||
}
|
||||
101
Templates/Full/game/shaders/common/gl/wind.glsl
Normal file
101
Templates/Full/game/shaders/common/gl/wind.glsl
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//
|
||||
// A tip of the hat....
|
||||
//
|
||||
// The following wind effects were derived from the GPU Gems
|
||||
// 3 chapter "Vegetation Procedural Animation and Shading in Crysis"
|
||||
// by Tiago Sousa of Crytek.
|
||||
//
|
||||
|
||||
vec4 smoothCurve( vec4 x )
|
||||
{
|
||||
return x * x * ( 3.0 - 2.0 * x );
|
||||
}
|
||||
|
||||
vec4 triangleWave( vec4 x )
|
||||
{
|
||||
return abs( fract( x + 0.5 ) * 2.0 - 1.0 );
|
||||
}
|
||||
|
||||
vec4 smoothTriangleWave( vec4 x )
|
||||
{
|
||||
return smoothCurve( triangleWave( x ) );
|
||||
}
|
||||
|
||||
vec3 windTrunkBending( vec3 vPos, vec2 vWind, float fBendFactor )
|
||||
{
|
||||
// Smooth the bending factor and increase
|
||||
// the near by height limit.
|
||||
fBendFactor += 1.0;
|
||||
fBendFactor *= fBendFactor;
|
||||
fBendFactor = fBendFactor * fBendFactor - fBendFactor;
|
||||
|
||||
// Displace the vert.
|
||||
vec3 vNewPos = vPos;
|
||||
vNewPos.xy += vWind * fBendFactor;
|
||||
|
||||
// Limit the length which makes the bend more
|
||||
// spherical and prevents stretching.
|
||||
float fLength = length( vPos );
|
||||
vPos = normalize( vNewPos ) * fLength;
|
||||
|
||||
return vPos;
|
||||
}
|
||||
|
||||
vec3 windBranchBending( vec3 vPos,
|
||||
vec3 vNormal,
|
||||
|
||||
float fTime,
|
||||
float fWindSpeed,
|
||||
|
||||
float fBranchPhase,
|
||||
float fBranchAmp,
|
||||
float fBranchAtten,
|
||||
|
||||
float fDetailPhase,
|
||||
float fDetailAmp,
|
||||
float fDetailFreq,
|
||||
|
||||
float fEdgeAtten )
|
||||
{
|
||||
float fVertPhase = dot( vPos, vec3( fDetailPhase + fBranchPhase ) );
|
||||
|
||||
vec2 vWavesIn = fTime + vec2( fVertPhase, fBranchPhase );
|
||||
|
||||
vec4 vWaves = ( fract( vWavesIn.xxyy *
|
||||
vec4( 1.975, 0.793, 0.375, 0.193 ) ) *
|
||||
2.0 - 1.0 ) * fWindSpeed * fDetailFreq;
|
||||
|
||||
vWaves = smoothTriangleWave( vWaves );
|
||||
|
||||
vec2 vWavesSum = vWaves.xz + vWaves.yw;
|
||||
|
||||
// We want the branches to bend both up and down.
|
||||
vWavesSum.y = 1.0 - ( vWavesSum.y * 2.0 );
|
||||
|
||||
vPos += vWavesSum.xxy * vec3( fEdgeAtten * fDetailAmp * vNormal.xy,
|
||||
fBranchAtten * fBranchAmp );
|
||||
|
||||
return vPos;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue