Changes to GLSL files for OpenGL

This commit is contained in:
LuisAntonRebollo 2014-04-13 19:48:51 +02:00
parent 2142d452d4
commit 6aea37b407
98 changed files with 3366 additions and 2686 deletions

View file

@ -26,12 +26,12 @@
uniform vec4 kernel;
uniform sampler2D diffuseMap;
varying vec2 texc0, texc1, texc2, texc3;
in 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;
OUT_FragColor0 = texture(diffuseMap, texc0) * kernel.x;
OUT_FragColor0 += texture(diffuseMap, texc1) * kernel.y;
OUT_FragColor0 += texture(diffuseMap, texc2) * kernel.z;
OUT_FragColor0 += texture(diffuseMap, texc3) * kernel.w;
}

View file

@ -24,20 +24,25 @@
// Glow shader
//*****************************************************************************
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
uniform mat4 modelview;
uniform vec2 offset0, offset1, offset2, offset3;
varying vec2 texc0, texc1, texc2, texc3;
out vec2 texc0, texc1, texc2, texc3;
void main()
{
gl_Position = modelview * gl_Vertex;
gl_Position = modelview * vPosition;
vec2 tc = gl_MultiTexCoord0.st;
vec2 tc = vTexCoord0.st;
tc.y = 1.0 - tc.y;
texc0 = tc + offset0;
texc1 = tc + offset1;
texc2 = tc + offset2;
texc3 = tc + offset3;
gl_Position.y *= -1;
}

View file

@ -22,12 +22,20 @@
#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;
//-----------------------------------------------------------------------------
// Structures
//-----------------------------------------------------------------------------
//ConnectData
in vec4 texCoord12;
#define IN_texCoord12 texCoord12
in vec4 texCoord34;
#define IN_texCoord34 texCoord34
in vec3 vLightTS; // light vector in tangent space, denormalized
#define IN_vLightTS vLightTS
in vec3 vViewTS; // view vector in tangent space, denormalized
#define IN_vViewTS vViewTS
in float worldDist;
#define IN_worldDist worldDist
//-----------------------------------------------------------------------------
// Uniforms
@ -37,6 +45,7 @@ uniform vec3 ambientColor;
uniform vec3 sunColor;
uniform float cloudCoverage;
uniform vec3 cloudBaseColor;
uniform float cloudExposure;
//-----------------------------------------------------------------------------
// Globals
@ -97,26 +106,25 @@ 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 );
vec4 cResultColor = vec4( 0, 0, 0, 1 );
vec2 texSample = texCoord12.xy;
vec2 texSample = IN_texCoord12.xy;
vec4 noise1 = texture2D( normalHeightMap, texCoord12.zw );
vec4 noise1 = texture( normalHeightMap, IN_texCoord12.zw );
noise1 = normalize( ( noise1 - 0.5 ) * 2.0 );
//return noise1;
vec4 noise2 = texture2D( normalHeightMap, texCoord34.xy );
vec4 noise2 = texture( normalHeightMap, IN_texCoord34.xy );
noise2 = normalize( ( noise2 - 0.5 ) * 2.0 );
//return noise2;
vec3 noiseNormal = normalize( noise1 + noise2 ).xyz;
//return float4( noiseNormal, 1.0 );
//return vec4( 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 );
vec3 vNormalTS = normalize( texture( normalHeightMap, texSample ).xyz * 2.0 - 1.0 );
vNormalTS += noiseNormal;
vNormalTS = normalize( vNormalTS );
@ -124,16 +132,14 @@ void main()
cResultColor.rgb = ComputeIllumination( texSample, vLightTS, vViewTS, vNormalTS );
float coverage = ( cloudCoverage - 0.5 ) * 2.0;
cResultColor.a = texture2D( normalHeightMap, texSample ).a + coverage + noiseHeight;
cResultColor.a = texture( 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 = clamp( cResultColor.a * pow( saturate(cloudCoverage), 0.25 ), 0.0, 1.0 );
cResultColor.a = mix( cResultColor.a, 0.0, 1.0 - pow(worldDist,2.0) );
cResultColor.a = mix( cResultColor.a, 0.0, 1.0 - pow(IN_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;
OUT_FragColor0 = cResultColor;
}

View file

@ -20,12 +20,24 @@
// 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;
#include "hlslCompat.glsl"
in vec4 vPosition;
in vec3 vNormal;
in vec3 vBinormal;
in vec3 vTangent;
in vec2 vTexCoord0;
out vec4 texCoord12;
#define OUT_texCoord12 texCoord12
out vec4 texCoord34;
#define OUT_texCoord34 texCoord34
out vec3 vLightTS; // light vector in tangent space, denormalized
#define OUT_vLightTS vLightTS
out vec3 vViewTS; // view vector in tangent space, denormalized
#define OUT_vViewTS vViewTS
out float worldDist;
#define OUT_worldDist worldDist
//-----------------------------------------------------------------------------
// Uniforms
@ -43,37 +55,37 @@ uniform vec3 texScale;
//-----------------------------------------------------------------------------
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;
vec4 IN_pos = vPosition;
vec3 IN_normal = vNormal;
vec3 IN_binormal = vBinormal;
vec3 IN_tangent = vTangent;
vec2 IN_uv0 = vTexCoord0.st;
gl_Position = modelview * pos;
gl_Position = modelview * IN_pos;
// Offset the uv so we don't have a seam directly over our head.
vec2 uv = uv0 + vec2( 0.5, 0.5 );
vec2 uv = IN_uv0 + vec2( 0.5, 0.5 );
texCoord12.xy = uv * texScale.x;
texCoord12.xy += texOffset0;
OUT_texCoord12.xy = uv * texScale.x;
OUT_texCoord12.xy += texOffset0;
texCoord12.zw = uv * texScale.y;
texCoord12.zw += texOffset1;
OUT_texCoord12.zw = uv * texScale.y;
OUT_texCoord12.zw += texOffset1;
texCoord34.xy = uv * texScale.z;
texCoord34.xy += texOffset2;
OUT_texCoord34.xy = uv * texScale.z;
OUT_texCoord34.xy += texOffset2;
texCoord34.z = pos.z;
texCoord34.w = 0.0;
OUT_texCoord34.z = IN_pos.z;
OUT_texCoord34.w = 0.0;
// Transform the normal, tangent and binormal vectors from object space to
// homogeneous projection space:
vNormalWS = -normal;
vec3 vTangentWS = -tangent;
vec3 vBinormalWS = -binormal;
vec3 vNormalWS = -IN_normal;
vec3 vTangentWS = -IN_tangent;
vec3 vBinormalWS = -IN_binormal;
// Compute position in world space:
vec4 vPositionWS = pos + vec4( eyePosWorld, 1 ); //mul( pos, objTrans );
vec4 vPositionWS = IN_pos + vec4( eyePosWorld, 1 ); //tMul( IN_pos, objTrans );
// Compute and output the world view vector (unnormalized):
vec3 vViewWS = eyePosWorld - vPositionWS.xyz;
@ -81,12 +93,14 @@ void main()
// Compute denormalized light vector in world space:
vec3 vLightWS = -sunVec;
// Normalize the light and view vectors and transform it to the tangent space:
// Normalize the light and view vectors and transform it to the IN_tangent space:
mat3 mWorldToTangent = mat3( vTangentWS, vBinormalWS, vNormalWS );
// Propagate the view and the light vectors (in tangent space):
vLightTS = mWorldToTangent * vLightWS;
vViewTS = vViewWS * mWorldToTangent;
worldDist = clamp( pow( pos.z, 2.0 ), 0.0, 1.0 );
OUT_vLightTS = vLightWS * mWorldToTangent;
OUT_vViewTS = mWorldToTangent * vViewWS;
OUT_worldDist = clamp( pow( max( IN_pos.z, 0 ), 2 ), 0.0, 1.0 );
correctSSP(gl_Position);
}

View file

@ -46,7 +46,19 @@ uniform vec3 gc_gustInfo;
uniform vec2 gc_turbInfo;
//static float sMovableCorner[4] = { 0.0, 0.0, 1.0, 1.0 };
const float sCornerRight[4] = float[]( -0.5, 0.5, 0.5, -0.5 );
const float sCornerUp[4] = float[]( 0, 0, 1, 1 );
const float sMovableCorner[4] = float[]( 0, 0, 1, 1 );
const vec2 sUVCornerExtent[4] = vec2[]
(
vec2( 0, 1 ),
vec2( 1, 1 ),
vec2( 1, 0 ),
vec2( 0, 0 )
);
///////////////////////////////////////////////////////////////////////////////
@ -106,34 +118,13 @@ vec2 windEffect( float bbPhase,
void foliageProcessVert( inout vec3 position,
inout vec4 diffuse,
in vec4 texCoord,
out vec2 outTexCoord,
inout vec4 texCoord,
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 );
//normal = vec3( 0, 0, 1 );//cross( gc_camUp, gc_camRight );
T = gc_camRight;
// Pull out local vars we need for work.
@ -172,8 +163,8 @@ void foliageProcessVert( inout vec3 position,
// 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 );
texCoord.x = uvSet.x + ( uvSet.z * sUVCornerExtent[corner].x );
texCoord.y = uvSet.y + ( uvSet.w * sUVCornerExtent[corner].y );
// Animate the normal to get lighting changes
// across the the wind swept foliage.
@ -184,7 +175,6 @@ void foliageProcessVert( inout vec3 position,
normal.xy += wind.xy * ( 10.0 * texCoord.w );
normal = normalize( normal );
// Get the alpha fade value.
float fadeStart = gc_fadeParams.x;

View file

@ -26,15 +26,15 @@
uniform sampler2D diffuseMap, alphaMap;
uniform vec4 groundAlpha;
varying vec4 color, groundAlphaCoeff;
varying vec2 outTexCoord, alphaLookup;
in vec4 color, groundAlphaCoeff;
in 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;
vec4 alpha = texture(alphaMap, alphaLookup);
OUT_FragColor0 = color * texture(diffuseMap, outTexCoord);
OUT_FragColor0.a = OUT_FragColor0.a * min(alpha, groundAlpha + groundAlphaCoeff.x).x;
}

View file

@ -23,13 +23,20 @@
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec3 vNormal;
in vec4 vColor;
in vec2 vTexCoord0;
in vec2 vTexCoord1;
in vec2 vTexCoord2;
uniform mat4 projection, world;
uniform vec3 CameraPos;
uniform float GlobalSwayPhase, SwayMagnitudeSide, SwayMagnitudeFront,
GlobalLightPhase, LuminanceMagnitude, LuminanceMidpoint, DistanceRange;
varying vec4 color, groundAlphaCoeff;
varying vec2 outTexCoord, alphaLookup;
out vec4 color, groundAlphaCoeff;
out vec2 outTexCoord, alphaLookup;
//-----------------------------------------------------------------------------
// Main
@ -42,9 +49,9 @@ void main()
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;
trans[3][0] = vPosition.x;
trans[3][1] = vPosition.y;
trans[3][2] = vPosition.z;
// Billboard transform * world matrix
mat4 o = world;
@ -64,28 +71,29 @@ void main()
// 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;
float wavePhase = GlobalSwayPhase * vTexCoord1.x;
ySway = sin(wavePhase);
xSway = cos(wavePhase);
xSway = xSway * gl_MultiTexCoord1.y * SwayMagnitudeSide;
ySway = ySway * gl_MultiTexCoord1.y * SwayMagnitudeFront;
xSway = xSway * vTexCoord1.y * SwayMagnitudeSide;
ySway = ySway * vTexCoord1.y * SwayMagnitudeFront;
vec4 p;
p = o * vec4(gl_Normal.x + xSway, ySway, gl_Normal.z, 1.0);
p = o * vec4(vNormal.x + xSway, ySway, vNormal.z, 1.0);
// Project the point
gl_Position = projection * p;
// Lighting
float Luminance = LuminanceMidpoint + LuminanceMagnitude * cos(GlobalLightPhase + gl_Normal.y);
float Luminance = LuminanceMidpoint + LuminanceMagnitude * cos(GlobalLightPhase + vNormal.y);
// Alpha
vec3 worldPos = vec3(gl_Vertex.x, gl_Vertex.y, gl_Vertex.z);
vec3 worldPos = vec3(vPosition.x, vPosition.y, vPosition.z);
float alpha = abs(distance(worldPos, CameraPos)) / DistanceRange;
alpha = clamp(alpha, 0.0, 1.0); //pass it through
alphaLookup = vec2(alpha, 0.0);
bool alphaCoeff = bool(gl_Normal.z);
bool alphaCoeff = bool(vNormal.z);
groundAlphaCoeff = vec4(float(alphaCoeff));
outTexCoord = gl_MultiTexCoord0.st;
outTexCoord = vTexCoord0.st;
color = vec4(Luminance, Luminance, Luminance, 1.0);
gl_Position.y *= -1;
}

View file

@ -20,16 +20,20 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4x4 modelview;
varying vec4 hpos;
varying vec2 uv0;
out vec4 hpos;
out vec2 uv0;
void main()
{
hpos = vec4( modelview * gl_Vertex );
hpos = vec4( modelview * vPosition );
gl_Position = hpos;
uv0 = gl_MultiTexCoord0.st;
uv0 = vTexCoord0.st;
gl_Position.y *= -1;
}

View file

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

View file

@ -20,73 +20,181 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef TORQUE_SHADERGEN
// These are the uniforms used by most lighting shaders.
uniform vec3 inLightPos[4];
uniform vec4 inLightPos[3];
uniform vec4 inLightInvRadiusSq;
uniform vec4 inLightColor[4];
#ifndef TORQUE_BL_NOSPOTLIGHT
uniform vec4 inLightSpotDir[3];
uniform vec4 inLightSpotAngle;
uniform vec4 inLightSpotFalloff;
#endif
uniform vec4 ambient;
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
#endif // !TORQUE_SHADERGEN
void compute4Lights( vec3 wsView,
vec3 wsPosition,
vec3 wsNormal,
vec3 wsNormal,
vec4 shadowMask,
#ifdef TORQUE_SHADERGEN
vec4 inLightPos[3],
vec4 inLightInvRadiusSq,
vec4 inLightColor[4],
vec4 inLightSpotDir[3],
vec4 inLightSpotAngle,
vec4 inLightSpotFalloff,
float specularPower,
vec4 specularColor,
#endif // TORQUE_SHADERGEN
out vec4 outDiffuse,
out vec4 outSpecular )
{
#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 );
// NOTE: The light positions and spotlight directions
// are stored in SoA order, so inLightPos[0] is the
// x coord for all 4 lights... inLightPos[1] is y... etc.
//
// This is the key to fully utilizing the vector units and
// saving a huge amount of instructions.
//
// For example this change saved more than 10 instructions
// over a simple for loop for each light.
int i;
for ( i = 0; i < C4L_MAX_LIGHTS; ++i )
{
vec3 lightVector = inLightPos[i] - wsPosition;
vec3 lightDirection = normalize( lightVector );
vec4 lightVectors[3];
for ( i = 0; i < 3; i++ )
lightVectors[i] = wsPosition[i] - inLightPos[i];
nDotL[i] = max( dot( lightDirection, wsNormal ), 0.0 );
vec4 squareDists = vec4(0);
for ( i = 0; i < 3; i++ )
squareDists += lightVectors[i] * lightVectors[i];
#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
// Accumulate the dot product between the light
// vector and the normal.
//
// The normal is negated because it faces away from
// the surface and the light faces towards the
// surface... this keeps us from needing to flip
// the light vector direction which complicates
// the spot light calculations.
//
// We normalize the result a little later.
//
vec4 nDotL = vec4(0);
for ( i = 0; i < 3; i++ )
nDotL += lightVectors[i] * -wsNormal[i];
sqDists[i] = dot( lightVector, lightVector );
}
vec4 rDotL = vec4(0);
#ifndef TORQUE_BL_NOSPECULAR
// Attenuation
vec4 atten = vec4( 1.0 ) - ( sqDists * inLightInvRadiusSq );
// We're using the Phong specular reflection model
// here where traditionally Torque has used Blinn-Phong
// which has proven to be more accurate to real materials.
//
// We do so because its cheaper as do not need to
// calculate the half angle for all 4 lights.
//
// Advanced Lighting still uses Blinn-Phong, but the
// specular reconstruction it does looks fairly similar
// to this.
//
vec3 R = reflect( wsView, -wsNormal );
for ( i = 0; i < 3; i++ )
rDotL += lightVectors[i] * R[i];
#endif
// Normalize the dots.
//
// Notice we're using the half type here to get a
// much faster sqrt via the rsq_pp instruction at
// the loss of some precision.
//
// Unless we have some extremely large point lights
// i don't believe the precision loss will matter.
//
half4 correction = half4(inversesqrt( squareDists ));
nDotL = saturate( nDotL * correction );
rDotL = clamp( rDotL * correction, 0.00001, 1.0 );
// First calculate a simple point light linear
// attenuation factor.
//
// If this is a directional light the inverse
// radius should be greater than the distance
// causing the attenuation to have no affect.
//
vec4 atten = saturate( 1.0 - ( squareDists * inLightInvRadiusSq ) );
#ifndef TORQUE_BL_NOSPOTLIGHT
// The spotlight attenuation factor. This is really
// fast for what it does... 6 instructions for 4 spots.
vec4 spotAtten = vec4(0);
for ( i = 0; i < 3; i++ )
spotAtten += lightVectors[i] * inLightSpotDir[i];
vec4 cosAngle = ( spotAtten * correction ) - inLightSpotAngle;
atten *= saturate( cosAngle * inLightSpotFalloff );
#endif
// Finally apply the shadow masking on the attenuation.
atten *= shadowMask;
// Get the final light intensity.
vec4 intensity = nDotL * atten;
// Combine the light colors for output.
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];
outDiffuse = vec4(0);
for ( i = 0; i < 4; i++ )
outDiffuse += intensity[i] * inLightColor[i];
// Output the specular power.
rDotL = max( rDotL, vec4( 0.00001 ) );
outSpecular = pow( rDotL, vec4( specularPower ) );
vec4 specularIntensity = pow( rDotL, vec4(specularPower) ) * atten;
// Apply the per-light specular attenuation.
vec4 specular = vec4(0,0,0,1);
for ( i = 0; i < 4; i++ )
specular += vec4( inLightColor[i].rgb * inLightColor[i].a * specularIntensity[i], 1 );
// Add the final specular intensity values together
// using a single dot product operation then get the
// final specular lighting color.
outSpecular = specularColor * specular;
}
/// The standard specular calculation.
// This value is used in AL as a constant power to raise specular values
// to, before storing them into the light info buffer. The per-material
// specular value is then computer by using the integer identity of
// exponentiation:
//
// (a^m)^n = a^(m*n)
//
// or
//
// (specular^constSpecular)^(matSpecular/constSpecular) = specular^(matSpecular*constSpecular)
//
#define AL_ConstantSpecularPower 12.0f
/// The specular calculation used in Advanced Lighting.
///
/// @param toLight Normalized vector representing direction from the pixel
/// being lit, to the light source, in world space.
@ -96,11 +204,7 @@ void compute4Lights( vec3 wsView,
/// @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 )
float AL_CalcSpecular( vec3 toLight, vec3 normal, vec3 toEye )
{
#ifdef PHONG_SPECULAR
// (R.V)^c
@ -111,5 +215,5 @@ float calcSpecular( vec3 toLight, vec3 normal, vec3 toEye, float specPwr )
#endif
// Return the specular factor.
return pow( max( specVal, 0.00001f ), specPwr );
return pow( max( specVal, 0.00001f ), AL_ConstantSpecularPower );
}

View file

@ -21,6 +21,13 @@
//-----------------------------------------------------------------------------
#include "torque.glsl"
#include "hlslCompat.glsl"
in vec4 offscreenPos;
in vec4 backbufferPos;
#define IN_offscreenPos offscreenPos
#define IN_backbufferPos backbufferPos
uniform sampler2D colorSource;
uniform vec4 offscreenTargetParams;
@ -31,8 +38,6 @@ uniform sampler2D edgeSource;
uniform vec4 edgeTargetParams;
#endif
varying vec4 backbufferPos;
varying vec4 offscreenPos;
void main()
{
@ -47,11 +52,10 @@ void main()
#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;
float edge = texture( edgeSource, uvScene.zw ).r;
clip( -edge );
#endif
// Sample offscreen target and return
gl_FragColor = texture2D( colorSource, uvScene.xy );
}
OUT_FragColor0 = texture( colorSource, uvScene.xy );
}

View file

@ -20,16 +20,29 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
uniform mat4 modelViewProj;
uniform mat4 targetModelViewProj;
#include "hlslCompat.glsl"
varying vec4 offscreenPos;
varying vec4 backbufferPos;
in vec2 vTexCoord0;
#define uvCoord vTexCoord0
out vec4 offscreenPos;
out vec4 backbufferPos;
#define OUT_hpos gl_Position
#define OUT_offscreenPos offscreenPos
#define OUT_backbufferPos backbufferPos
uniform vec4 screenRect; // point, extent
void main()
{
gl_Position = modelViewProj * gl_Vertex;
backbufferPos = gl_Position;
offscreenPos = targetModelViewProj * gl_Vertex;
OUT_hpos = vec4(uvCoord.xy, 1.0, 1.0);
OUT_hpos.xy *= screenRect.zw;
OUT_hpos.xy += screenRect.xy;
OUT_backbufferPos = OUT_hpos;
OUT_offscreenPos = OUT_hpos;
correctSSP(gl_Position);
}

View file

@ -20,63 +20,92 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#include "hlslCompat.glsl"
#include "torque.glsl"
#include "hlslCompat.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 sampler2D prepassTex;
//uniform vec3 vEye;
uniform vec4 prePassTargetParams;
#endif
#define CLIP_Z // TODO: Make this a proper macro
in vec4 color;
in vec2 uv0;
in vec4 pos;
#define IN_color color
#define IN_uv0 uv0
#define IN_pos pos
uniform sampler2D diffuseMap;
uniform sampler2D paraboloidLightMap;
vec4 lmSample( vec3 nrm )
{
bool calcBack = (nrm.z < 0.0);
if ( calcBack )
nrm.z = nrm.z * -1.0;
vec2 lmCoord;
lmCoord.x = (nrm.x / (2*(1 + nrm.z))) + 0.5;
lmCoord.y = 1-((nrm.y / (2*(1 + nrm.z))) + 0.5);
// If this is the back, offset in the atlas
if ( calcBack )
lmCoord.x += 1.0;
// Atlasing front and back maps, so scale
lmCoord.x *= 0.5;
return texture(paraboloidLightMap, lmCoord);
}
uniform float alphaFactor;
uniform float alphaScale;
varying vec4 color;
varying vec2 uv0;
varying vec4 pos;
void main()
{
float softBlend = 1.0;
float softBlend = 1;
#ifdef SOFTPARTICLES
float2 tc = pos.xy * vec2(1.0, -1.0 ) / pos.w;
vec2 tc = IN_pos.xy * vec2(1.0, -1.0) / IN_pos.w;
tc = viewportCoordToRenderTarget(saturate( ( tc + 1.0 ) * 0.5 ), prePassTargetParams);
float sceneDepth = prepassUncondition( prepassTex, tc ).w;
float depth = pos.w * oneOverFar;
float diff = sceneDepth - depth;
float depth = IN_pos.w * oneOverFar;
float diff = sceneDepth - depth;
#ifdef CLIP_Z
// If drawing offscreen, this acts as the depth test, since we don't line up with the z-buffer
// When drawing high-res, though, we want to be able to take advantage of hi-z
// so this is #ifdef'd out
if (diff < 0.0)
discard;
//clip(diff);
#endif
softBlend = saturate( diff * oneOverSoftness );
#endif
vec4 diffuse = texture2D( diffuseMap, uv0 );
vec4 diffuse = texture( diffuseMap, IN_uv0 );
//OUT_FragColor0 = vec4( lmSample(vec3(0, 0, -1)).rgb, IN_color.a * diffuse.a * softBlend * alphaScale);
// Scale output color by the alpha factor (turn LerpAlpha into pre-multiplied alpha)
vec3 colorScale = ( alphaFactor < 0.0 ? color.rgb * diffuse.rgb : ( alphaFactor > 0.0 ? vec3(color.a * alphaFactor * diffuse.a * softBlend) : vec3(softBlend) ) );
vec3 colorScale = ( alphaFactor < 0.0 ? IN_color.rgb * diffuse.rgb : vec3( alphaFactor > 0.0 ? IN_color.a * diffuse.a * alphaFactor * softBlend : softBlend ) );
gl_FragColor = hdrEncode( vec4(color.rgb * diffuse.rgb * colorScale, softBlend * color.a * diffuse.a * alphaScale) );
OUT_FragColor0 = hdrEncode( vec4( IN_color.rgb * diffuse.rgb * colorScale,
IN_color.a * diffuse.a * softBlend * alphaScale ) );
}

View file

@ -20,18 +20,35 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
varying vec4 color;
varying vec2 uv0;
varying vec4 pos;
#include "hlslCompat.glsl"
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
#define In_pos vPosition
#define In_color vColor
#define In_uv0 vTexCoord0
out vec4 color;
out vec2 uv0;
out vec4 pos;
#define OUT_hpos gl_Position
#define OUT_color color
#define OUT_uv0 uv0
#define OUT_pos pos
uniform mat4 modelViewProj;
uniform mat4 fsModelViewProj;
void main()
{
gl_Position = modelViewProj * gl_Vertex;
pos = fsModelViewProj * gl_Vertex;
color = gl_Color;
uv0 = gl_MultiTexCoord0.st;
OUT_hpos = tMul( modelViewProj, In_pos );
OUT_pos = tMul( fsModelViewProj, In_pos );
OUT_color = In_color;
OUT_uv0 = In_uv0;
correctSSP(gl_Position);
}

View file

@ -26,8 +26,8 @@
uniform sampler2D diffuseMap, refractMap, bumpMap;
uniform vec4 shadeColor;
varying vec2 TEX0;
varying vec4 TEX1;
in vec2 TEX0;
in vec4 TEX1;
//-----------------------------------------------------------------------------
// Fade edges of axis for texcoord passed in
@ -49,7 +49,7 @@ float fadeAxis( float val )
//-----------------------------------------------------------------------------
void main()
{
vec3 bumpNorm = texture2D( bumpMap, TEX0 ).rgb * 2.0 - 1.0;
vec3 bumpNorm = texture( bumpMap, TEX0 ).rgb * 2.0 - 1.0;
vec2 offset = vec2( bumpNorm.x, bumpNorm.y );
vec4 texIndex = TEX1;
@ -61,8 +61,8 @@ void main()
const float distortion = 0.2;
texIndex.xy += offset * distortion * fadeVal;
vec4 diffuseColor = texture2D( diffuseMap, TEX0 );
vec4 reflectColor = texture2DProj( refractMap, texIndex );
vec4 diffuseColor = texture( diffuseMap, TEX0 );
vec4 reflectColor = textureProj( refractMap, texIndex );
gl_FragColor = diffuseColor + reflectColor * diffuseColor.a;
OUT_FragColor0 = diffuseColor + reflectColor * diffuseColor.a;
}

View file

@ -23,10 +23,13 @@
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4 modelview;
varying vec2 TEX0;
varying vec4 TEX1;
out vec2 TEX0;
out vec4 TEX1;
//-----------------------------------------------------------------------------
// Main
@ -38,11 +41,11 @@ void main()
0.0, 0.0, 1.0, 0.0,
0.5, 0.5, 0.0, 1.0);
gl_Position = modelview * gl_Vertex;
gl_Position = modelview * vPosition;
TEX0 = gl_MultiTexCoord0.st;
TEX0 = vTexCoord0.st;
TEX1 = texGenTest * gl_Position;
TEX1.y = -TEX1.y;
gl_Position.y *= -1;
}

View file

@ -26,16 +26,16 @@
uniform sampler2D diffuseMap, refractMap;
uniform vec4 shadeColor;
varying vec2 TEX0;
varying vec4 TEX1;
in vec2 TEX0;
in vec4 TEX1;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
vec4 diffuseColor = texture2D( diffuseMap, TEX0 );
vec4 reflectColor = texture2DProj( refractMap, TEX1 );
vec4 diffuseColor = texture( diffuseMap, TEX0 );
vec4 reflectColor = textureProj( refractMap, TEX1 );
gl_FragColor = diffuseColor + reflectColor * diffuseColor.a;
OUT_FragColor0 = diffuseColor + reflectColor * diffuseColor.a;
}

View file

@ -23,10 +23,13 @@
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4 modelview;
varying vec2 TEX0;
varying vec4 TEX1;
out vec2 TEX0;
out vec4 TEX1;
//-----------------------------------------------------------------------------
// Main
@ -38,9 +41,9 @@ void main()
0.0, 0.0, 1.0, 0.0,
0.5, 0.5, 0.0, 1.0);
gl_Position = modelview * gl_Vertex;
gl_Position = modelview * vPosition;
TEX0 = gl_MultiTexCoord0.st;
TEX0 = vTexCoord0;
TEX1 = texGenTest * gl_Position;
TEX1.y = -TEX1.y;

View file

@ -25,13 +25,13 @@
//-----------------------------------------------------------------------------
uniform sampler2D diffuseMap;
varying vec4 color;
varying vec2 texCoord;
in vec4 color;
in vec2 texCoord;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
gl_FragColor = texture2D(diffuseMap, texCoord) * color;
OUT_FragColor0 = texture(diffuseMap, texCoord) * color;
}

View file

@ -23,28 +23,32 @@
//-----------------------------------------------------------------------------
// Data
//-----------------------------------------------------------------------------
in vec4 vPosition;
in vec2 vTexCoord0;
uniform mat4 modelview;
uniform vec3 cameraPos, ambient;
uniform vec2 fadeStartEnd;
varying vec4 color;
varying vec2 texCoord;
out vec4 color;
out vec2 texCoord;
//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
gl_Position = modelview * gl_Vertex;
texCoord = gl_MultiTexCoord0.st;
gl_Position = modelview * vPosition;
texCoord = vTexCoord0.st;
color = vec4( ambient.r, ambient.g, ambient.b, 1.0 );
// Do we need to do a distance fade?
if ( fadeStartEnd.x < fadeStartEnd.y )
{
float distance = length( cameraPos - gl_Vertex.xyz );
float distance = length( cameraPos - vPosition.xyz );
color.a = abs( clamp( ( distance - fadeStartEnd.x ) / ( fadeStartEnd.y - fadeStartEnd.x ), 0.0, 1.0 ) - 1.0 );
}
gl_Position.y *= -1;
}

View file

@ -20,9 +20,11 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
varying vec2 texCoord;
varying vec4 color;
varying float fade;
in vec2 texCoord;
in vec4 color;
in float fade;
out vec4 OUT_FragColor0;
uniform sampler2D inputTex;
uniform vec4 ambient;
@ -30,17 +32,6 @@ 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;
float shadow = texture( inputTex, texCoord ).a * color.a;
OUT_FragColor0 = ( ambient * shadow ) + ( 1 - shadow );
}

View file

@ -20,13 +20,16 @@
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
//*****************************************************************************
// Precipitation vertex shader
//*****************************************************************************
#include "hlslCompat.glsl"
varying vec2 texCoord;
varying vec4 color;
varying float fade;
in vec4 vPosition;
in vec4 vColor;
in vec2 vTexCoord0;
in vec2 vTexCoord1;
out vec2 texCoord;
out vec4 color;
out float fade;
uniform mat4 modelview;
uniform float shadowLength;
@ -34,11 +37,13 @@ uniform vec3 shadowCasterPosition;
void main()
{
gl_Position = modelview * vec4(gl_Vertex.xyz, 1.0);
gl_Position = modelview * vec4(vPosition.xyz, 1.0);
color = gl_Color;
texCoord = gl_MultiTexCoord1.st;
color = vColor;
texCoord = vTexCoord1.st;
float fromCasterDist = length(gl_Vertex.xyz - shadowCasterPosition) - shadowLength;
fade = 1.0 - clamp(fromCasterDist/shadowLength, 0.0, 1.0);
float fromCasterDist = length(vPosition.xyz - shadowCasterPosition) - shadowLength;
fade = 1.0 - clamp( fromCasterDist / shadowLength , 0.0, 1.0 );
correctSSP(gl_Position);
}

View file

@ -21,36 +21,32 @@
//-----------------------------------------------------------------------------
#include "torque.glsl"
#include "hlslCompat.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;
}
// Conn
in vec4 rayleighColor;
#define IN_rayleighColor rayleighColor
in vec4 mieColor;
#define IN_mieColor mieColor
in vec3 v3Direction;
#define IN_v3Direction v3Direction
in float zPosition;
#define IN_zPosition zPosition
in vec3 pos;
#define IN_pos pos
varying vec4 rayleighColor;
varying vec4 mieColor;
varying vec3 v3Direction;
varying float zPosition;
varying vec3 pos;
uniform samplerCube nightSky;
uniform samplerCube nightSky ;
uniform vec4 nightColor;
uniform vec2 nightInterpAndExposure;
uniform float useCubemap;
uniform vec3 lightDir;
uniform vec3 sunDir;
void main()
void main()
{
float fCos = dot( lightDir, v3Direction ) / length(v3Direction);
float fCos = dot( lightDir, IN_v3Direction ) / length(IN_v3Direction);
float fCos2 = fCos*fCos;
float g = -0.991;
@ -58,15 +54,15 @@ void main()
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;
vec4 color = IN_rayleighColor + fMiePhase * IN_mieColor;
color.a = color.b;
vec4 nightSkyColor = textureCube(nightSky, -v3Direction);
vec4 nightSkyColor = texture(nightSky, -v3Direction);
nightSkyColor = mix(nightColor, nightSkyColor, useCubemap);
float fac = dot( normalize( pos ), sunDir );
fac = max( nightInterpAndExposure.y, pow( clamp( fac, 0.0, 1.0 ), 2 ) );
gl_FragColor = mix( color, nightSkyColor, nightInterpAndExposure.y );
OUT_FragColor0 = mix( color, nightSkyColor, nightInterpAndExposure.y );
// Clip based on the camera-relative
// z position of the vertex, passed through
@ -74,6 +70,6 @@ void main()
if(zPosition < 0.0)
discard;
gl_FragColor.a = 1;
gl_FragColor = hdrEncode( gl_FragColor );
OUT_FragColor0.a = 1;
OUT_FragColor0 = hdrEncode( OUT_FragColor0 );
}

View file

@ -20,12 +20,7 @@
// 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;
#include "hlslCompat.glsl"
// The scale equation calculated by Vernier's Graphical Analysis
float vernierScale(float fCos)
@ -40,12 +35,27 @@ float vernierScale(float fCos)
return 0.25 * outx;
}
in vec4 vPosition;
in vec3 vNormal;
in vec4 vColor;
in vec2 vTexCoord0;
// This is the shader input vertex structure.
#define IN_position vPosition
#define IN_normal vNormal
#define IN_color vColor
// This is the shader output data.
varying vec4 rayleighColor;
varying vec4 mieColor;
varying vec3 v3Direction;
varying float zPosition;
varying vec3 pos;
out vec4 rayleighColor;
#define OUT_rayleighColor rayleighColor
out vec4 mieColor;
#define OUT_mieColor mieColor
out vec3 v3Direction;
#define OUT_v3Direction v3Direction
out float zPosition;
#define OUT_zPosition zPosition
out vec3 pos;
#define OUT_pos pos
uniform mat4 modelView;
uniform vec4 misc;
@ -54,13 +64,16 @@ 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;
uniform vec4 colorize;
vec3 desaturate(const vec3 color, const float desaturation)
{
const vec3 gray_conv = vec3 (0.30, 0.59, 0.11);
return mix(color, vec3(dot(gray_conv , color)), desaturation);
}
void main()
{
// Pull some variables out:
float camHeight = misc.x;
float camHeightSqr = misc.y;
@ -83,7 +96,7 @@ void main()
// 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 v3Pos = vec3(IN_position / 6378000.0);// / outerRadius;
vec3 newCamPos = vec3( 0, 0, camHeight );
v3Pos.z += innerRadius;
vec3 v3Ray = v3Pos.xyz - newCamPos;
@ -97,16 +110,7 @@ void main()
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);
float fStartOffset = fDepth * vernierScale( fStartAngle );
// Initialize the scattering loop variables.
float fSampleLength = fFar / 2.0;
@ -123,24 +127,8 @@ void main()
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 vscale3 = vernierScale( fCameraAngle );
float vscale2 = vernierScale( fLightAngle );
float fScatter = (fStartOffset + fDepth*(vscale2 - vscale3));
vec3 v3Attenuate = exp(-fScatter * (invWaveLength.xyz * rayleigh4PI + mie4PI));
@ -150,16 +138,24 @@ void main()
// 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;
gl_Position = modelView * IN_position;
OUT_mieColor.rgb = v3FrontColor * mieBrightness;
OUT_mieColor.a = 1.0;
OUT_rayleighColor.rgb = v3FrontColor * (invWaveLength.xyz * rayleighBrightness);
OUT_rayleighColor.a = 1.0;
OUT_v3Direction = newCamPos - v3Pos.xyz;
OUT_pos = IN_position.xyz;
// 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;
#ifdef USE_COLORIZE
OUT_rayleighColor.rgb = desaturate(OUT_rayleighColor.rgb, 1) * colorize.a;
OUT_rayleighColor.r *= colorize.r;
OUT_rayleighColor.g *= colorize.g;
OUT_rayleighColor.b *= colorize.b;
#endif
correctSSP(gl_Position);
}

View file

@ -117,6 +117,7 @@ mat3x3 quatToMat( vec4 quat )
return mat;
}
/// The number of additional substeps we take when refining
/// the results of the offset parallax mapping function below.
///
@ -129,19 +130,20 @@ mat3x3 quatToMat( vec4 quat )
/// Performs fast parallax offset mapping using
/// multiple refinement steps.
////// @param texMap The texture map whos alpha channel we sample the parallax depth.
///
/// @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;
float depth = texture( 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;
depth = ( depth + texture( texMap, texCoord + offset ).a ) * 0.5;
offset = negViewTS.xy * ( depth * depthScale );
}
@ -151,59 +153,61 @@ vec2 parallaxOffset( sampler2D texMap, vec2 texCoord, vec3 negViewTS, float dept
/// 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;
/// 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 ){
vec3 hdrEncode( vec3 _sample )
{
#if defined( TORQUE_HDR_RGB16 )
return sample / HDR_RGB16_MAX;
return _sample / HDR_RGB16_MAX;
#elif defined( TORQUE_HDR_RGB10 )
return sample / HDR_RGB10_MAX;
return _sample / HDR_RGB10_MAX;
#else
// No encoding.
return sample;
return _sample;
#endif
}
/// Encodes an HDR color for storage into a target.
vec4 hdrEncode( vec4 sample )
vec4 hdrEncode( vec4 _sample )
{
return vec4( hdrEncode( sample.rgb ), sample.a );
return vec4( hdrEncode( _sample.rgb ), _sample.a );
}
/// Decodes an HDR color from a target.
vec3 hdrDecode( vec3 sample )
vec3 hdrDecode( vec3 _sample )
{
#if defined( TORQUE_HDR_RGB16 )
return sample * HDR_RGB16_MAX;
return _sample * HDR_RGB16_MAX;
#elif defined( TORQUE_HDR_RGB10 )
return sample * HDR_RGB10_MAX;
return _sample * HDR_RGB10_MAX;
#else
// No encoding.
return sample;
return _sample;
#endif
}
/// Decodes an HDR color from a target.
vec4 hdrDecode( vec4 sample )
vec4 hdrDecode( vec4 _sample )
{
return vec4( hdrDecode( sample.rgb ), sample.a );
return vec4( hdrDecode( _sample.rgb ), _sample.a );
}
/// Returns the luminance for an HDR pixel.
float hdrLuminance( vec3 sample )
float hdrLuminance( vec3 _sample )
{
// There are quite a few different ways to
// calculate luminance from an rgb value.
@ -216,7 +220,7 @@ float hdrLuminance( vec3 sample )
//
// Max component luminance.
//
//float lum = max( sample.r, max( sample.g, sample.b ) );
//float lum = max( _sample.r, max( _sample.g, _sample.b ) );
////////////////////////////////////////////////////////////////////////////
// The perceptual relative luminance.
@ -224,23 +228,45 @@ float hdrLuminance( vec3 sample )
// 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 );
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 );
//float lum = dot( _sample, AVERAGE_LUMINANCE );
return lum;
}
#ifdef TORQUE_PIXEL_SHADER
/// Called from the visibility feature to do screen
/// door transparency for fading of objects.
void fizzle(vec2 vpos, float visibility)
{
// NOTE: The magic values below are what give us
// the nice even pattern during the fizzle.
//
// These values can be changed to get different
// patterns... some better than others.
//
// Horizontal Blinds - { vpos.x, 0.916, vpos.y, 0 }
// Vertical Lines - { vpos.x, 12.9898, vpos.y, 78.233 }
//
// I'm sure there are many more patterns here to
// discover for different effects.
mat2x2 m = mat2x2( vpos.x, vpos.y, 0.916, 0.350 );
if( (visibility - fract( determinant( m ) )) < 0 ) //if(a < 0) discard;
discard;
}
#endif //TORQUE_PIXEL_SHADER
/// Basic assert macro. If the condition fails, then the shader will output color.
/// @param condition This should be a bvec[2-4]. If any items is false, condition is considered to fail.
/// @param color The color that should be outputted if the condition fails.
/// @note This macro will only work in the void main() method of a pixel shader.
#define assert(condition, color) { if(!any(condition)) { gl_FragColor = color; return; } }
#define assert(condition, color) { if(!any(condition)) { OUT_FragColor0 = color; return; } }
#endif // _TORQUE_GLSL_

View file

@ -28,10 +28,10 @@ uniform float specularPower;
uniform vec4 ambient;
uniform float accumTime;
varying vec2 TEX0;
varying vec4 outLightVec;
varying vec3 outPos;
varying vec3 outEyePos;
in vec2 TEX0;
in vec4 outLightVec;
in vec3 outPos;
in vec3 outEyePos;
void main()
{
@ -42,14 +42,14 @@ void main()
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);
vec4 bumpNorm = texture(bumpMap, texOffset) * 2.0 - 1.0;
vec4 diffuse = texture(diffMap, texOffset);
gl_FragColor = diffuse * (clamp(dot(outLightVec.xyz, bumpNorm.xyz), 0.0, 1.0) + ambient);
OUT_FragColor0 = 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;
OUT_FragColor0 += specularColor * specular;
}