diffuse/albedo texture linearization

http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html
This commit is contained in:
Azaezel 2015-11-11 13:52:46 -06:00
parent 51b6469922
commit ce2964d2d0
31 changed files with 396 additions and 107 deletions

View file

@ -284,4 +284,37 @@ void fizzle(vec2 vpos, float visibility)
/// @note This macro will only work in the void main() method of a pixel shader.
#define assert(condition, color) { if(!any(condition)) { OUT_col = color; return; } }
// Deferred Shading: Material Info Flag Check
bool getFlag(float flags, int num)
{
float process = round(flags * 255);
float squareNum = pow(2, num);
return (mod(process, pow(2, squareNum)) >= squareNum);
}
// #define TORQUE_STOCK_GAMMA
#ifdef TORQUE_STOCK_GAMMA
// Sample in linear space. Decodes gamma.
vec4 toLinear(vec4 tex)
{
return tex;
}
// Encodes gamma.
vec4 toGamma(vec4 tex)
{
return tex;
}
#else
// Sample in linear space. Decodes gamma.
vec4 toLinear(vec4 tex)
{
return vec4(pow(abs(tex.rgb), vec3(2.2)), tex.a);
}
// Encodes gamma.
vec4 toGamma(vec4 tex)
{
return vec4(pow(abs(tex.rgb), vec3(1.0/2.2)), tex.a);
}
#endif //
#endif // _TORQUE_GLSL_

View file

@ -28,7 +28,8 @@ uniform sampler2D backBuffer : register(S0);
uniform sampler1D colorCorrectionTex : register( s1 );
uniform float OneOverGamma;
uniform float Brightness;
uniform float Contrast;
float4 main( PFXVertToPix IN ) : COLOR0
{
@ -42,5 +43,11 @@ float4 main( PFXVertToPix IN ) : COLOR0
// Apply gamma correction
color.rgb = pow( abs(color.rgb), OneOverGamma );
// Apply contrast
color.rgb = ((color.rgb - 0.5f) * Contrast) + 0.5f;
// Apply brightness
color.rgb += Brightness;
return color;
}

View file

@ -28,6 +28,8 @@ uniform sampler2D backBuffer;
uniform sampler1D colorCorrectionTex;
uniform float OneOverGamma;
uniform float Brightness;
uniform float Contrast;
in vec2 uv0;
@ -45,5 +47,11 @@ void main()
// Apply gamma correction
color.rgb = pow( abs(color.rgb), vec3(OneOverGamma) );
// Apply contrast
color.rgb = ((color.rgb - 0.5f) * Contrast) + 0.5f;
// Apply brightness
color.rgb += Brightness;
OUT_col = color;
}

View file

@ -41,6 +41,8 @@ uniform float3 g_fBlueShiftColor;
uniform float g_fBloomScale;
uniform float g_fOneOverGamma;
uniform float Brightness;
uniform float Contrast;
float4 main( PFXVertToPix IN ) : COLOR0
@ -90,6 +92,12 @@ float4 main( PFXVertToPix IN ) : COLOR0
// Apply gamma correction
sample.rgb = pow( abs(sample.rgb), g_fOneOverGamma );
// Apply contrast
sample.rgb = ((sample.rgb - 0.5f) * Contrast) + 0.5f;
// Apply brightness
sample.rgb += Brightness;
return sample;
}

View file

@ -42,6 +42,8 @@ uniform vec3 g_fBlueShiftColor;
uniform float g_fBloomScale;
uniform float g_fOneOverGamma;
uniform float Brightness;
uniform float Contrast;
out vec4 OUT_col;
@ -93,6 +95,12 @@ void main()
// Apply gamma correction
_sample.rgb = pow( abs(_sample.rgb), vec3(g_fOneOverGamma) );
// Apply contrast
_sample.rgb = ((_sample.rgb - 0.5f) * Contrast) + 0.5f;
// Apply brightness
_sample.rgb += Brightness;
OUT_col = _sample;
}

View file

@ -277,5 +277,37 @@ void fizzle(float2 vpos, float visibility)
clip( visibility - frac( determinant( m ) ) );
}
// Deferred Shading: Material Info Flag Check
bool getFlag(float flags, int num)
{
int process = round(flags * 255);
int squareNum = pow(2, num);
return (fmod(process, pow(2, squareNum)) >= squareNum);
}
// #define TORQUE_STOCK_GAMMA
#ifdef TORQUE_STOCK_GAMMA
// Sample in linear space. Decodes gamma.
float4 toLinear(float4 tex)
{
return tex;
}
// Encodes gamma.
float4 toLinear(float4 tex)
{
return tex;
}
#else
// Sample in linear space. Decodes gamma.
float4 toLinear(float4 tex)
{
return float4(pow(abs(tex.rgb), 2.2), tex.a);
}
// Encodes gamma.
float4 toGamma(float4 tex)
{
return float4(pow(abs(tex.rgb), 1.0/2.2), tex.a);
}
#endif //
#endif // _TORQUE_HLSL_

View file

@ -120,6 +120,7 @@ void main()
{
// Modulate baseColor by the ambientColor.
vec4 waterBaseColor = baseColor * vec4( ambientColor.rgb, 1 );
waterBaseColor = toLinear(waterBaseColor);
// Get the bumpNorm...
vec3 bumpNorm = ( texture( bumpMap, IN_rippleTexCoord01.xy ).rgb * 2.0 - 1.0 ) * rippleMagnitude.x;

View file

@ -324,6 +324,7 @@ void main()
// Calculate the water "base" color based on depth.
vec4 waterBaseColor = baseColor * texture( depthGradMap, saturate( delta / depthGradMax ) );
waterBaseColor = toLinear(waterBaseColor);
// Modulate baseColor by the ambientColor.
waterBaseColor *= vec4( ambientColor.rgb, 1 );

View file

@ -117,6 +117,7 @@ float4 main( ConnectData IN ) : COLOR
{
// Modulate baseColor by the ambientColor.
float4 waterBaseColor = baseColor * float4( ambientColor.rgb, 1 );
waterBaseColor = toLinear(waterBaseColor);
// Get the bumpNorm...
float3 bumpNorm = ( tex2D( bumpMap, IN.rippleTexCoord01.xy ).rgb * 2.0 - 1.0 ) * rippleMagnitude.x;

View file

@ -311,6 +311,7 @@ float4 main( ConnectData IN ) : COLOR
// Calculate the water "base" color based on depth.
float4 waterBaseColor = baseColor * tex1D( depthGradMap, saturate( delta / depthGradMax ) );
waterBaseColor = toLinear(waterBaseColor);
// Modulate baseColor by the ambientColor.
waterBaseColor *= float4( ambientColor.rgb, 1 );