Skip to content

Commit

Permalink
Merge pull request #988 from BeamNG/clean_opengl_fragment_out
Browse files Browse the repository at this point in the history
Clean GLSL fragment shader out.
  • Loading branch information
LuisAntonRebollo committed Dec 1, 2014
2 parents 7bf99e3 + ed0febe commit 5e74a46
Show file tree
Hide file tree
Showing 135 changed files with 452 additions and 240 deletions.
2 changes: 1 addition & 1 deletion Engine/source/shaderGen/GLSL/shaderGenGLSL.cpp
Expand Up @@ -75,7 +75,7 @@ void ShaderGenPrinterGLSL::printPixelShaderOutputStruct( Stream& stream, const M
}

WRITESTR(avar("//Fragment shader OUT\r\n"));
//WRITESTR(avar("out vec4 OUT_col;\r\n", i)); // @todo OUT_col defined on hlslCompat.glsl
WRITESTR(avar("out vec4 OUT_col;\r\n"));
for( U32 i = 1; i < 4; i++ )
{
if( numMRTs & 1 << i )
Expand Down
Expand Up @@ -24,9 +24,9 @@ uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;

out vec4 OUT_FragColor0;
out vec4 OUT_col;

void main()
{
OUT_FragColor0 = vec4(color.rgb, color.a * texture(diffuseMap, texCoord).a);
OUT_col = vec4(color.rgb, color.a * texture(diffuseMap, texCoord).a);
}
Expand Up @@ -22,9 +22,9 @@

in vec4 color;

out vec4 OUT_FragColor0;
out vec4 OUT_col;

void main()
{
OUT_FragColor0 = color;
OUT_col = color;
}
Expand Up @@ -24,9 +24,9 @@ uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;

out vec4 OUT_FragColor0;
out vec4 OUT_col;

void main()
{
OUT_FragColor0 = texture(diffuseMap, texCoord) * color;
OUT_col = texture(diffuseMap, texCoord) * color;
}
Expand Up @@ -23,9 +23,9 @@
uniform sampler2D diffuseMap;
in vec2 texCoord;

out vec4 OUT_FragColor0;
out vec4 OUT_col;

void main()
{
OUT_FragColor0 = texture(diffuseMap, texCoord);
OUT_col = texture(diffuseMap, texCoord);
}
4 changes: 3 additions & 1 deletion Templates/Empty/game/shaders/common/gl/basicCloudsP.glsl
Expand Up @@ -30,8 +30,10 @@ in vec2 texCoord;

uniform sampler2D diffuseMap ;

out vec4 OUT_col;

void main()
{
vec4 col = texture( diffuseMap, IN_texCoord );
OUT_FragColor0 = hdrEncode( col );
OUT_col = hdrEncode( col );
}
10 changes: 6 additions & 4 deletions Templates/Empty/game/shaders/common/gl/blurP.glsl
Expand Up @@ -28,10 +28,12 @@ uniform sampler2D diffuseMap;

in vec2 texc0, texc1, texc2, texc3;

out vec4 OUT_col;

void main()
{
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;
OUT_col = texture(diffuseMap, texc0) * kernel.x;
OUT_col += texture(diffuseMap, texc1) * kernel.y;
OUT_col += texture(diffuseMap, texc2) * kernel.z;
OUT_col += texture(diffuseMap, texc3) * kernel.w;
}
4 changes: 3 additions & 1 deletion Templates/Empty/game/shaders/common/gl/cloudLayerP.glsl
Expand Up @@ -47,6 +47,8 @@ uniform float cloudCoverage;
uniform vec3 cloudBaseColor;
uniform float cloudExposure;

out vec4 OUT_col;

//-----------------------------------------------------------------------------
// Globals
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -141,5 +143,5 @@ void main()

cResultColor.a = mix( cResultColor.a, 0.0, 1.0 - pow(IN_worldDist,2.0) );

OUT_FragColor0 = cResultColor;
OUT_col = cResultColor;
}
Expand Up @@ -29,12 +29,14 @@ uniform vec4 groundAlpha;
in vec4 color, groundAlphaCoeff;
in vec2 outTexCoord, alphaLookup;

out vec4 OUT_col;

//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
vec4 alpha = texture(alphaMap, alphaLookup);
OUT_FragColor0 = color * texture(diffuseMap, outTexCoord);
OUT_FragColor0.a = OUT_FragColor0.a * min(alpha, groundAlpha + groundAlphaCoeff.x).x;
OUT_col = color * texture(diffuseMap, outTexCoord);
OUT_col.a = OUT_col.a * min(alpha, groundAlpha + groundAlphaCoeff.x).x;
}
3 changes: 0 additions & 3 deletions Templates/Empty/game/shaders/common/gl/hlslCompat.glsl
Expand Up @@ -100,7 +100,4 @@ mat4 mat4FromRow( float r0c0, float r0c1, float r0c2, float r0c3,

#ifdef TORQUE_PIXEL_SHADER
void clip(float a) { if(a < 0) discard;}

out vec4 OUT_col;
#define OUT_FragColor0 OUT_col
#endif
Expand Up @@ -38,6 +38,7 @@ uniform sampler2D edgeSource;
uniform vec4 edgeTargetParams;
#endif

out vec4 OUT_col;

void main()
{
Expand All @@ -57,5 +58,5 @@ void main()
#endif

// Sample offscreen target and return
OUT_FragColor0 = texture( colorSource, uvScene.xy );
OUT_col = texture( colorSource, uvScene.xy );
}
6 changes: 4 additions & 2 deletions Templates/Empty/game/shaders/common/gl/particlesP.glsl
Expand Up @@ -78,6 +78,8 @@ vec4 lmSample( vec3 nrm )
uniform float alphaFactor;
uniform float alphaScale;

out vec4 OUT_col;

void main()
{
float softBlend = 1;
Expand All @@ -100,12 +102,12 @@ void main()

vec4 diffuse = texture( diffuseMap, IN_uv0 );

//OUT_FragColor0 = vec4( lmSample(vec3(0, 0, -1)).rgb, IN_color.a * diffuse.a * softBlend * alphaScale);
//OUT_col = vec4( lmSample(vec3(0, 0, -1)).rgb, IN_color.a * diffuse.a * softBlend * alphaScale);

// Scale output color by the alpha factor (turn LerpAlpha into pre-multiplied alpha)
vec3 colorScale = ( alphaFactor < 0.0 ? IN_color.rgb * diffuse.rgb : vec3( alphaFactor > 0.0 ? IN_color.a * diffuse.a * alphaFactor * softBlend : softBlend ) );

OUT_FragColor0 = hdrEncode( vec4( IN_color.rgb * diffuse.rgb * colorScale,
OUT_col = hdrEncode( vec4( IN_color.rgb * diffuse.rgb * colorScale,
IN_color.a * diffuse.a * softBlend * alphaScale ) );
}

Expand Up @@ -29,6 +29,8 @@ uniform vec4 shadeColor;
in vec2 TEX0;
in vec4 TEX1;

out vec4 OUT_col;

//-----------------------------------------------------------------------------
// Fade edges of axis for texcoord passed in
//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -64,5 +66,5 @@ void main()
vec4 diffuseColor = texture( diffuseMap, TEX0 );
vec4 reflectColor = textureProj( refractMap, texIndex );

OUT_FragColor0 = diffuseColor + reflectColor * diffuseColor.a;
OUT_col = diffuseColor + reflectColor * diffuseColor.a;
}
4 changes: 3 additions & 1 deletion Templates/Empty/game/shaders/common/gl/planarReflectP.glsl
Expand Up @@ -29,6 +29,8 @@ uniform vec4 shadeColor;
in vec2 TEX0;
in vec4 TEX1;

out vec4 OUT_col;

//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
Expand All @@ -37,5 +39,5 @@ void main()
vec4 diffuseColor = texture( diffuseMap, TEX0 );
vec4 reflectColor = textureProj( refractMap, TEX1 );

OUT_FragColor0 = diffuseColor + reflectColor * diffuseColor.a;
OUT_col = diffuseColor + reflectColor * diffuseColor.a;
}
4 changes: 3 additions & 1 deletion Templates/Empty/game/shaders/common/gl/precipP.glsl
Expand Up @@ -28,10 +28,12 @@ uniform sampler2D diffuseMap;
in vec4 color;
in vec2 texCoord;

out vec4 OUT_col;

//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------
void main()
{
OUT_FragColor0 = texture(diffuseMap, texCoord) * color;
OUT_col = texture(diffuseMap, texCoord) * color;
}
4 changes: 2 additions & 2 deletions Templates/Empty/game/shaders/common/gl/projectedShadowP.glsl
Expand Up @@ -24,7 +24,7 @@ in vec2 texCoord;
in vec4 color;
in float fade;

out vec4 OUT_FragColor0;
out vec4 OUT_col;

uniform sampler2D inputTex;
uniform vec4 ambient;
Expand All @@ -33,5 +33,5 @@ uniform vec4 ambient;
void main()
{
float shadow = texture( inputTex, texCoord ).a * color.a;
OUT_FragColor0 = ( ambient * shadow ) + ( 1 - shadow );
OUT_col = ( ambient * shadow ) + ( 1 - shadow );
}
8 changes: 5 additions & 3 deletions Templates/Empty/game/shaders/common/gl/scatterSkyP.glsl
Expand Up @@ -43,6 +43,8 @@ uniform float useCubemap;
uniform vec3 lightDir;
uniform vec3 sunDir;

out vec4 OUT_col;

void main()
{

Expand All @@ -62,14 +64,14 @@ void main()

float fac = dot( normalize( pos ), sunDir );
fac = max( nightInterpAndExposure.y, pow( clamp( fac, 0.0, 1.0 ), 2 ) );
OUT_FragColor0 = mix( color, nightSkyColor, nightInterpAndExposure.y );
OUT_col = 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;

OUT_FragColor0.a = 1;
OUT_FragColor0 = hdrEncode( OUT_FragColor0 );
OUT_col.a = 1;
OUT_col = hdrEncode( OUT_col );
}
2 changes: 1 addition & 1 deletion Templates/Empty/game/shaders/common/gl/torque.glsl
Expand Up @@ -267,6 +267,6 @@ void fizzle(vec2 vpos, float visibility)
/// @param condition This should be a bvec[2-4]. If any items is false, condition is considered to fail.
/// @param color The color that should be outputted if the condition fails.
/// @note This macro will only work in the void main() method of a pixel shader.
#define assert(condition, color) { if(!any(condition)) { OUT_FragColor0 = color; return; } }
#define assert(condition, color) { if(!any(condition)) { OUT_col = color; return; } }

#endif // _TORQUE_GLSL_
6 changes: 4 additions & 2 deletions Templates/Empty/game/shaders/common/gl/wavesP.glsl
Expand Up @@ -33,6 +33,8 @@ in vec4 outLightVec;
in vec3 outPos;
in vec3 outEyePos;

out vec4 OUT_col;

void main()
{
vec2 texOffset;
Expand All @@ -45,11 +47,11 @@ void main()
vec4 bumpNorm = texture(bumpMap, texOffset) * 2.0 - 1.0;
vec4 diffuse = texture(diffMap, texOffset);

OUT_FragColor0 = diffuse * (clamp(dot(outLightVec.xyz, bumpNorm.xyz), 0.0, 1.0) + ambient);
OUT_col = diffuse * (clamp(dot(outLightVec.xyz, bumpNorm.xyz), 0.0, 1.0) + ambient);

vec3 eyeVec = normalize(outEyePos - outPos);
vec3 halfAng = normalize(eyeVec + outLightVec.xyz);
float specular = clamp(dot(bumpNorm.xyz, halfAng), 0.0, 1.0) * outLightVec.w;
specular = pow(specular, specularPower);
OUT_FragColor0 += specularColor * specular;
OUT_col += specularColor * specular;
}
Expand Up @@ -27,8 +27,10 @@ in vec2 uv0;
uniform sampler2D prepassBuffer;
uniform sampler1D depthViz;

out vec4 OUT_col;

void main()
{
float depth = prepassUncondition( prepassBuffer, uv0 ).w;
OUT_FragColor0 = vec4( texture( depthViz, depth ).rgb, 1.0 );
OUT_col = vec4( texture( depthViz, depth ).rgb, 1.0 );
}
Expand Up @@ -26,10 +26,12 @@
in vec2 uv0;
uniform sampler2D lightInfoBuffer;

out vec4 OUT_col;

void main()
{
vec3 lightcolor;
float nl_Att, specular;
lightinfoUncondition( texture( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
OUT_FragColor0 = vec4( lightcolor, 1.0 );
OUT_col = vec4( lightcolor, 1.0 );
}
Expand Up @@ -26,10 +26,12 @@
in vec2 uv0;
uniform sampler2D lightInfoBuffer;

out vec4 OUT_col;

void main()
{
vec3 lightcolor;
float nl_Att, specular;
lightinfoUncondition( texture( lightInfoBuffer, uv0 ), lightcolor, nl_Att, specular );
OUT_FragColor0 = vec4( specular, specular, specular, 1.0 );
OUT_col = vec4( specular, specular, specular, 1.0 );
}
Expand Up @@ -26,8 +26,10 @@
in vec2 uv0;
uniform sampler2D prepassBuffer;

out vec4 OUT_col;

void main()
{
vec3 normal = prepassUncondition( prepassBuffer, uv0 ).xyz;
OUT_FragColor0 = vec4( ( normal + 1.0 ) * 0.5, 1.0 );
OUT_col = vec4( ( normal + 1.0 ) * 0.5, 1.0 );
}
Expand Up @@ -25,8 +25,10 @@ in vec2 uv0;
uniform sampler2D shadowMap;
uniform sampler1D depthViz;

out vec4 OUT_col;

void main()
{
float depth = saturate( texture( shadowMap, uv0 ).r );
OUT_FragColor0 = vec4( texture( depthViz, depth ).rgb, 1 );
OUT_col = vec4( texture( depthViz, depth ).rgb, 1 );
}
Expand Up @@ -122,6 +122,7 @@ uniform mat3 viewToLightProj;
uniform vec4 lightParams;
uniform float shadowSoftness;

out vec4 OUT_col;

void main()
{
Expand Down Expand Up @@ -229,5 +230,5 @@ void main()
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
}

OUT_FragColor0 = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
OUT_col = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
}
Expand Up @@ -63,6 +63,8 @@ uniform mat4 viewToLightProj;
uniform vec4 lightParams;
uniform float shadowSoftness;

out vec4 OUT_col;

void main()
{
// Compute scene UV
Expand Down Expand Up @@ -162,5 +164,5 @@ void main()
addToResult = ( 1.0 - shadowed ) * abs(lightMapParams);
}

OUT_FragColor0 = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
OUT_col = lightinfoCondition( lightColorOut, Sat_NL_Att, specular, addToResult );
}

0 comments on commit 5e74a46

Please sign in to comment.