First pass of gamma correction reimplementation.

meow-7.2.2
Geenz 2013-04-17 15:53:09 -04:00
parent c72c3691ec
commit bb5bf632c6
18 changed files with 83 additions and 49 deletions

View File

@ -129,7 +129,7 @@ void main()
#else
vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy);
#endif
diff.rgb = pow(diff.rgb, vec3(2.2));
#if INDEX_MODE == NON_INDEXED_NO_COLOR
float vertex_color_alpha = 1.0;
#else
@ -173,7 +173,6 @@ void main()
#endif
color.rgb += diff.rgb * vary_pointlight_col * light_col;
frag_color = color;
}

View File

@ -181,21 +181,21 @@ void main()
vary_rotation[2] = vec3(t.z, b.z, n.z);
calcAtmospherics(pos.xyz);
vec3 dff = pow(diffuse_color.rgb, vec3(2.2));
//vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.));
vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a);
vary_pointlight_col = diffuse_color.rgb;
vary_pointlight_col = dff;
col.rgb = vec3(0,0,0);
// Add windlight lights
col.rgb = atmosAmbient(vec3(0.));
vary_ambient = col.rgb*diffuse_color.rgb;
vary_directional.rgb = atmosAffectDirectionalLight(1);
vary_ambient = col.rgb*dff;
col.rgb = col.rgb*diffuse_color.rgb;
col.rgb = col.rgb*dff;
#if INDEX_MODE != NON_INDEXED_NO_COLOR
vertex_color = col;
#endif

View File

@ -42,7 +42,7 @@ void main()
float shadow = 1.0;
vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color;
color.rgb = pow(color.rgb, vec3(2.2));
color.rgb = fullbrightAtmosTransport(color.rgb);
color.rgb = fullbrightScaleSoftClip(color.rgb);

View File

@ -43,7 +43,7 @@ void main()
float shadow = 1.0;
vec4 color = diffuseLookup(vary_texcoord0.xy)*vertex_color;
color.rgb = pow(color.rgb, vec3(2.2));
color.rgb = fullbrightAtmosTransport(color.rgb);
color.rgb = fullbrightScaleSoftClip(color.rgb);

View File

@ -93,7 +93,8 @@ void main()
norm = decode_normal(norm.xy); // unpack norm
norm = normalize(norm);
vec4 spec = texture2DRect(specularRect, frag.xy);
vec3 diff = texture2DRect(diffuseRect, frag.xy).rgb;
spec.rgb = pow(spec.rgb, vec3(2.2));
vec3 diff = pow(texture2DRect(diffuseRect, frag.xy).rgb, vec3(2.2));
float noise = texture2D(noiseMap, frag.xy/128.0).b;
vec3 out_col = vec3(0,0,0);
vec3 npos = normalize(-pos);
@ -128,8 +129,6 @@ void main()
dist_atten *= noise;
float lit = da * dist_atten;
lit = pow(lit,0.7);
vec3 col = light_col[i].rgb*lit*diff;

View File

@ -181,6 +181,7 @@ void main()
vec3 col = vec3(0,0,0);
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
diff_tex = pow(diff_tex, vec3(2.2));
float noise = texture2D(noiseMap, frag.xy/128.0).b;
if (proj_tc.z > 0.0 &&
@ -202,8 +203,6 @@ void main()
vec3 lcol = color.rgb * plcol.rgb * plcol.a;
lit = da * dist_atten * noise;
lit = pow(lit, 0.7);
col = lcol*lit*diff_tex;
amb_da += (da*0.5)*proj_ambiance;
@ -223,6 +222,8 @@ void main()
vec4 spec = texture2DRect(specularRect, frag.xy);
spec.rgb = pow(spec.rgb, vec3(2.2));
if (spec.a > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);

View File

@ -108,16 +108,15 @@ void main()
float noise = texture2D(noiseMap, frag.xy/128.0).b;
vec3 col = texture2DRect(diffuseRect, frag.xy).rgb;
vec3 col = pow(texture2DRect(diffuseRect, frag.xy).rgb, vec3(2.2));
float fa = falloff+1.0;
float dist_atten = clamp(1.0-(dist2-1.0*(1.0-fa))/fa, 0.0, 1.0);
float lit = da * dist_atten * noise;
lit = pow(lit, 0.7);
col = color.rgb*lit*col;
vec4 spec = texture2DRect(specularRect, frag.xy);
spec.rgb = pow(spec.rgb, vec3(2.2));
if (spec.a > 0.0)
{
vec3 npos = -normalize(pos);

View File

@ -42,6 +42,6 @@ void main()
vec4 diff = texture2DRect(diffuseRect, vary_fragcoord.xy);
vec4 bloom = texture2D(bloomMap, vary_fragcoord.xy/screen_res);
frag_color = diff + bloom;
frag_color = pow(diff + bloom, vec4(0.454545, 0.454545, 0.454545, 1.0));
}

View File

@ -60,6 +60,7 @@ uniform float density_multiplier;
uniform float distance_multiplier;
uniform float max_y;
uniform vec4 glow;
uniform float global_gamma;
uniform float scene_light_strength;
uniform mat3 env_mat;
uniform mat3 ssao_effect_mat;
@ -230,9 +231,9 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) {
+ tmpAmbient)));
//brightness of surface both sunlight and ambient
setSunlitColor(vec3(sunlight * .5));
setAmblitColor(vec3(tmpAmbient * .25));
setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1));
setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * 3.3);
setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * 3.3);
setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * 3.3);
}
vec3 atmosLighting(vec3 light)
@ -291,12 +292,11 @@ void main()
norm.xyz = decode_normal(norm.xy); // unpack norm
float da = max(dot(norm.xyz, sun_dir.xyz), 0.0);
da = pow(da, 0.7);
vec4 diffuse = texture2DRect(diffuseRect, tc);
diffuse.rgb = pow(diffuse.rgb, vec3(2.2));
vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
spec.rgb = pow(spec.rgb, vec3(2.2));
vec3 col;
float bloom = 0.0;
if (diffuse.a < 0.9)
@ -323,7 +323,7 @@ void main()
//add environmentmap
vec3 env_vec = env_mat * refnormpersp;
col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb,
col = mix(col.rgb, pow(textureCube(environmentMap, env_vec).rgb, vec3(2.2)) * 2.2,
max(envIntensity-diffuse.a*2.0, 0.0));
}

View File

@ -35,6 +35,6 @@ void main()
//transform vertex
vec4 pos = modelview_projection_matrix * vec4(position.xyz, 1.0);
gl_Position = pos;
vary_fragcoord = (pos.xy*0.5+0.5)*screen_res;
}

View File

@ -84,6 +84,7 @@ vec3 decode_normal (vec2 enc)
vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = pow(ret.rgb, vec3(2.2));
vec2 dist = tc-vec2(0.5);
@ -99,7 +100,8 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)
vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = pow(ret.rgb, vec3(2.2));
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
float det = min(lod/(proj_lod*0.5), 1.0);
@ -116,7 +118,8 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)
vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = pow(ret.rgb, vec3(2.2));
vec2 dist = tc-vec2(0.5);
float d = dot(dist,dist);
@ -184,6 +187,7 @@ void main()
vec3 col = vec3(0,0,0);
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
diff_tex = pow(diff_tex, vec3(2.2));
float noise = texture2D(noiseMap, frag.xy/128.0).b;
if (proj_tc.z > 0.0 &&
@ -205,8 +209,6 @@ void main()
vec3 lcol = color.rgb * plcol.rgb * plcol.a;
lit = da * dist_atten * noise;
lit = pow(lit, 0.7);
col = lcol*lit*diff_tex;
amb_da += (da*0.5)*proj_ambiance;
@ -226,6 +228,8 @@ void main()
vec4 spec = texture2DRect(specularRect, frag.xy);
spec.rgb = pow(spec.rgb, vec3(2.2));
if (spec.a > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);

View File

@ -215,7 +215,7 @@ void main()
#else
vec4 diff = texture2D(diffuseMap,vary_texcoord0.xy);
#endif
diff.rgb = pow(diff.rgb, vec3(2.2));
#if INDEX_MODE == NON_INDEXED_NO_COLOR
float vertex_color_alpha = 1.0;
#else

View File

@ -186,17 +186,19 @@ void main()
//vec4 color = calcLighting(pos.xyz, norm, diffuse_color, vec4(0.));
vec4 col = vec4(0.0, 0.0, 0.0, diffuse_color.a);
vary_pointlight_col = diffuse_color.rgb;
vec3 dff = pow(diffuse_color.rgb, vec3(2.2));
vary_pointlight_col = dff;
col.rgb = vec3(0,0,0);
// Add windlight lights
col.rgb = atmosAmbient(vec3(0.));
vary_ambient = col.rgb*diffuse_color.rgb;
vary_directional.rgb = atmosAffectDirectionalLight(1);
vary_ambient = col.rgb*dff;
col.rgb = col.rgb*diffuse_color.rgb;
col.rgb = col.rgb*dff;
#if INDEX_MODE != NON_INDEXED_NO_COLOR
vertex_color = col;

View File

@ -82,6 +82,7 @@ vec3 decode_normal (vec2 enc)
vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = pow(ret.rgb, vec3(2.2));
vec2 dist = tc-vec2(0.5);
@ -97,6 +98,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)
vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = pow(ret.rgb, vec3(2.2));
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
@ -114,6 +116,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)
vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = pow(ret.rgb, vec3(2.2));
vec2 dist = tc-vec2(0.5);
@ -193,6 +196,7 @@ void main()
vec3 col = vec3(0,0,0);
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
diff_tex = pow(diff_tex, vec3(2.2));
float noise = texture2D(noiseMap, frag.xy/128.0).b;
if (proj_tc.z > 0.0 &&
@ -214,8 +218,6 @@ void main()
vec3 lcol = color.rgb * plcol.rgb * plcol.a;
lit = da * dist_atten * noise;
lit = pow(lit, 0.7);
col = lcol*lit*diff_tex*shadow;
amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance;
@ -235,6 +237,8 @@ void main()
vec4 spec = texture2DRect(specularRect, frag.xy);
spec.rgb = pow(spec.rgb, vec3(2.2));
if (spec.a > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);

View File

@ -60,6 +60,7 @@ uniform float density_multiplier;
uniform float distance_multiplier;
uniform float max_y;
uniform vec4 glow;
uniform float global_gamma;
uniform float scene_light_strength;
uniform mat3 env_mat;
uniform vec4 shadow_clip;
@ -233,9 +234,9 @@ void calcAtmospherics(vec3 inPositionEye, float ambFactor) {
+ tmpAmbient)));
//brightness of surface both sunlight and ambient
setSunlitColor(vec3(sunlight * .5));
setAmblitColor(vec3(tmpAmbient * .25));
setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1));
setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * 3.3);
setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * 3.3);
setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * 3.3);
}
vec3 atmosLighting(vec3 light)
@ -293,9 +294,9 @@ void main()
float envIntensity = norm.z;
norm.xyz = decode_normal(norm.xy);
float da = max(dot(norm.xyz, sun_dir.xyz), 0.0);
da = pow(da, 0.7);
vec4 diffuse = texture2DRect(diffuseRect, tc);
diffuse.rgb = pow(diffuse.rgb, vec3(2.2));
vec3 col;
float bloom = 0.0;
@ -303,6 +304,7 @@ void main()
if (diffuse.a < 0.9)
{
vec4 spec = texture2DRect(specularRect, vary_fragcoord.xy);
spec.rgb = pow(spec.rgb, vec3(2.2));
vec2 scol_ambocc = texture2DRect(lightMap, vary_fragcoord.xy).rg;
float scol = max(scol_ambocc.r, diffuse.a);
@ -330,7 +332,7 @@ void main()
//add environmentmap
vec3 env_vec = env_mat * refnormpersp;
col = mix(col.rgb, textureCube(environmentMap, env_vec).rgb,
col = mix(col.rgb, pow(textureCube(environmentMap, env_vec).rgb, vec3(2.2)) * 2.2,
max(envIntensity-diffuse.a*2.0, 0.0));
}

View File

@ -83,6 +83,7 @@ vec3 decode_normal (vec2 enc)
vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = pow(ret.rgb, vec3(2.2));
vec2 dist = tc-vec2(0.5);
@ -98,6 +99,7 @@ vec4 texture2DLodSpecular(sampler2D projectionMap, vec2 tc, float lod)
vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = pow(ret.rgb, vec3(2.2));
vec2 dist = vec2(0.5) - abs(tc-vec2(0.5));
@ -115,6 +117,7 @@ vec4 texture2DLodDiffuse(sampler2D projectionMap, vec2 tc, float lod)
vec4 texture2DLodAmbient(sampler2D projectionMap, vec2 tc, float lod)
{
vec4 ret = texture2DLod(projectionMap, tc, lod);
ret.rgb = pow(ret.rgb, vec3(2.2));
vec2 dist = tc-vec2(0.5);
@ -194,6 +197,8 @@ void main()
vec3 col = vec3(0,0,0);
vec3 diff_tex = texture2DRect(diffuseRect, frag.xy).rgb;
diff_tex = pow(diff_tex, vec3(2.2));
float noise = texture2D(noiseMap, frag.xy/128.0).b;
if (proj_tc.z > 0.0 &&
@ -215,8 +220,6 @@ void main()
vec3 lcol = color.rgb * plcol.rgb * plcol.a;
lit = da * dist_atten * noise;
lit = pow(lit, 0.7);
col = lcol*lit*diff_tex*shadow;
amb_da += (da*0.5)*(1.0-shadow)*proj_ambiance;
@ -236,6 +239,7 @@ void main()
vec4 spec = texture2DRect(specularRect, frag.xy);
spec.rgb = pow(spec.rgb, vec3(2.2));
if (spec.a > 0.0)
{
vec3 ref = reflect(normalize(pos), norm);

View File

@ -54,6 +54,7 @@ uniform float density_multiplier;
uniform float distance_multiplier;
uniform float max_y;
uniform vec4 glow;
uniform float global_gamma;
void calcAtmospherics(vec3 inPositionEye) {
@ -129,11 +130,17 @@ void calcAtmospherics(vec3 inPositionEye) {
vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow) + tmpAmbient)
+ (haze_horizon * haze_weight) * (sunlight*(1.-cloud_shadow) * temp2.x
+ tmpAmbient)));
float gammaScale = 1.0;
if (global_gamma > 1.0)
{
gammaScale = global_gamma / 2 + global_gamma;
}
//brightness of surface both sunlight and ambient
setSunlitColor(vec3(sunlight * .5));
setAmblitColor(vec3(tmpAmbient * .25));
setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1));
setSunlitColor(pow(vec3(sunlight * .5), vec3(global_gamma)) * gammaScale);
setAmblitColor(pow(vec3(tmpAmbient * .25), vec3(global_gamma)) * gammaScale);
setAdditiveColor(pow(getAdditiveColor() * vec3(1.0 - temp1), vec3(global_gamma)) * gammaScale);
// vary_SunlitColor = vec3(0);
// vary_AmblitColor = vec3(0);

View File

@ -912,7 +912,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
if (!mDeferredDepth.allocate(resX, resY, 0, TRUE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE, samples)) return false;
if (!addDeferredAttachments(mDeferredScreen)) return false;
if (!mScreen.allocate(resX, resY, GL_RGBA12, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE, samples)) return false;
if (!mScreen.allocate(resX, resY, GL_RGBA16, FALSE, FALSE, LLTexUnit::TT_RECT_TEXTURE, FALSE, samples)) return false;
if (samples > 0)
{
if (!mFXAABuffer.allocate(resX, resY, GL_RGBA, FALSE, FALSE, LLTexUnit::TT_TEXTURE, FALSE, samples)) return false;
@ -1326,8 +1326,6 @@ void LLPipeline::createLUTBuffers()
// Note: This is the full equation that applies the full normalization curve, not an approximation.
// This is fine, given we only need to create our LUT once per buffer initialization.
spec *= (((n + 2) * (n + 4)) / (8 * F_PI * (powf(2, -n/2) + n)));
spec = powf(spec, 0.6f);
// Since we use R16F, we no longer have a dynamic range issue we need to work around here.
// Though some older drivers may not like this, newer drivers shouldn't have this problem.
@ -8267,6 +8265,10 @@ void LLPipeline::renderDeferredLighting()
continue;
}
col.mV[0] = powf(col.mV[0], 2.2f);
col.mV[1] = powf(col.mV[1], 2.2f);
col.mV[2] = powf(col.mV[2], 2.2f);
LLFastTimer ftm(FTM_LOCAL_LIGHTS);
gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s*s);
@ -8323,6 +8325,9 @@ void LLPipeline::renderDeferredLighting()
setupSpotLight(gDeferredSpotLightProgram, drawablep);
LLColor3 col = volume->getLightColor();
col.mV[0] = powf(col.mV[0], 2.2f);
col.mV[1] = powf(col.mV[1], 2.2f);
col.mV[2] = powf(col.mV[2], 2.2f);
gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s*s);
@ -8371,7 +8376,11 @@ void LLPipeline::renderDeferredLighting()
fullscreen_lights.pop_front();
col[count] = light_colors.front();
light_colors.pop_front();
col[count].mV[0] = powf(col[count].mV[0], 2.2f);
col[count].mV[1] = powf(col[count].mV[1], 2.2f);
col[count].mV[2] = powf(col[count].mV[2], 2.2f);
far_z = llmin(light[count].mV[2]-sqrtf(light[count].mV[3]), far_z);
//col[count] = pow4fsrgb(col[count], 2.2f);
count++;
@ -8415,6 +8424,10 @@ void LLPipeline::renderDeferredLighting()
LLColor3 col = volume->getLightColor();
col.mV[0] = powf(col.mV[0], 2.2f);
col.mV[1] = powf(col.mV[1], 2.2f);
col.mV[2] = powf(col.mV[2], 2.2f);
gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, tc.v);
gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s*s);
gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);