mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 15:14:35 +00:00
diffuse/albedo texture linearization
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html
This commit is contained in:
parent
51b6469922
commit
ce2964d2d0
31 changed files with 396 additions and 107 deletions
|
|
@ -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_
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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_
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue