提交 af236a42 编写于 作者: B Ben Houston

completing adjustable gamma - still one bug left.

上级 1c24e4d1
......@@ -225,11 +225,7 @@ THREE.ShaderDeferred = {
"#endif",
"#ifdef GAMMA_INPUT",
"cubeColor.xyz *= cubeColor.xyz;",
"#endif",
"cubeColor.xyz = inputToLinear( cubeColor.xyz );",
"if ( combine == 1 ) {",
......
......@@ -134,12 +134,8 @@ THREE.ShaderTerrain = {
"vec4 colDiffuse1 = texture2D( tDiffuse1, uvOverlay );",
"vec4 colDiffuse2 = texture2D( tDiffuse2, uvOverlay );",
"#ifdef GAMMA_INPUT",
"colDiffuse1.xyz *= colDiffuse1.xyz;",
"colDiffuse2.xyz *= colDiffuse2.xyz;",
"#endif",
"colDiffuse1.xyz = inputToLinear( colDiffuse1.xyz );",
"colDiffuse2.xyz = inputToLinear( colDiffuse2.xyz );",
"gl_FragColor = gl_FragColor * mix ( colDiffuse1, colDiffuse2, 1.0 - texture2D( tDisplacement, uvBase ) );",
......
#ifdef USE_COLOR
#ifdef GAMMA_INPUT
vColor = square( color );
#else
vColor = color;
#endif
vColor.xyz = inputToLinear( color.xyz );
#endif
\ No newline at end of file
......@@ -36,4 +36,20 @@ float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
}
vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
return pointOnLine + lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) );
}
vec3 inputToLinear( in vec3 a ) {
#ifdef GAMMA_INPUT
return pow( a.rgb, vec3( float( GAMMA_FACTOR ) ) );
#else
return a;
#endif
}
vec3 linearToOutput( in vec3 a ) {
#ifdef GAMMA_OUTPUT
return pow( a.rgb, vec3( 1.0 / float( GAMMA_FACTOR ) ) );
#else
return a;
#endif
}
\ No newline at end of file
......@@ -43,11 +43,7 @@
vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );
#endif
#ifdef GAMMA_INPUT
envColor.xyz *= envColor.xyz;
#endif
envColor.xyz = inputToLinear( envColor.xyz );
#ifdef ENVMAP_BLENDING_MULTIPLY
......
#ifdef GAMMA_OUTPUT
gl_FragColor.xyz = sqrt( gl_FragColor.xyz );
#endif
\ No newline at end of file
gl_FragColor.xyz = linearToOutput( gl_FragColor.xyz );
......@@ -2,11 +2,7 @@
vec4 texelColor = texture2D( map, vUv );
#ifdef GAMMA_INPUT
texelColor.xyz *= texelColor.xyz;
#endif
texelColor.xyz = inputToLinear( texelColor.xyz );
gl_FragColor = gl_FragColor * texelColor;
......
......@@ -209,11 +209,8 @@
}
#ifdef GAMMA_OUTPUT
shadowColor *= shadowColor;
#endif
// NOTE: I am unsure if this is correct in linear space. -bhouston, Dec 29, 2014
shadowColor = inputToLinear( shadowColor );
gl_FragColor.xyz = gl_FragColor.xyz * shadowColor;
......
......@@ -749,35 +749,15 @@ THREE.ShaderLib = {
" if( enableDiffuse ) {",
" #ifdef GAMMA_INPUT",
" vec4 texelColor = texture2D( tDiffuse, vUv );",
" texelColor.xyz *= texelColor.xyz;",
" gl_FragColor = gl_FragColor * texelColor;",
" #else",
" gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );",
" #endif",
" vec4 texelColor = texture2D( tDiffuse, vUv );",
" texelColor.xyz = inputToLinear( texelColor.xyz );",
" gl_FragColor = gl_FragColor * texelColor;",
" }",
" if( enableAO ) {",
" #ifdef GAMMA_INPUT",
" vec4 aoColor = texture2D( tAO, vUv );",
" aoColor.xyz *= aoColor.xyz;",
" gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;",
" #else",
" gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;",
" #endif",
" gl_FragColor.xyz = gl_FragColor.xyz * inputToLinear( texture2D( tAO, vUv ).xyz );",
" }",
......@@ -1054,12 +1034,7 @@ THREE.ShaderLib = {
" #endif",
" vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
" #ifdef GAMMA_INPUT",
" cubeColor.xyz *= cubeColor.xyz;",
" #endif",
" cubeColor.xyz = inputToLinear( cubeColor.xyz );",
" gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * reflectivity );",
......
......@@ -135,6 +135,8 @@ THREE.WebGLProgram = ( function () {
}
var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
// console.log( "building new program " );
//
......@@ -165,7 +167,7 @@ THREE.WebGLProgram = ( function () {
_this.gammaInput ? "#define GAMMA_INPUT" : "",
_this.gammaOutput ? "#define GAMMA_OUTPUT" : "",
"#define GAMMA_FACTOR " + this.renderer.gammaFactor,
"#define GAMMA_FACTOR " + gammaFactorDefine,
"#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
"#define MAX_POINT_LIGHTS " + parameters.maxPointLights,
......@@ -280,7 +282,7 @@ THREE.WebGLProgram = ( function () {
_this.gammaInput ? "#define GAMMA_INPUT" : "",
_this.gammaOutput ? "#define GAMMA_OUTPUT" : "",
"#define GAMMA_FACTOR " + this.renderer.gammaFactor,
"#define GAMMA_FACTOR " + gammaFactorDefine,
( parameters.useFog && parameters.fog ) ? "#define USE_FOG" : "",
( parameters.useFog && parameters.fogExp ) ? "#define FOG_EXP2" : "",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册