diff --git a/game/graphics/sky/sky.cpp b/game/graphics/sky/sky.cpp index 6e5a48a92..fec4c7e58 100644 --- a/game/graphics/sky/sky.cpp +++ b/game/graphics/sky/sky.cpp @@ -246,7 +246,7 @@ void Sky::updateLight(const int64_t now) { Vec3 direct; direct = Vec3(1.0f) * DirectSunLux; - ambient = groundAlbedo * DirectSunLux * aDirect * sunOcclude * 0.05f;// * scale; + ambient = groundAlbedo * DirectSunLux * aDirect * sunOcclude * 0.03f;// * scale; sun.setColor(direct*sunMul); ambient = ambient*ambMul; diff --git a/shader/common.glsl b/shader/common.glsl index 342b35c7c..c3b14ec22 100644 --- a/shader/common.glsl +++ b/shader/common.glsl @@ -20,7 +20,8 @@ const float Fd_LambertInv = (M_PI); /* Color value is multiplied to achive adequate albedo and correctness in GI. * Need to scale it back, when material receives direct light. */ -const float GColorScale = (1.0/M_PI); +const float GColorScaleInv = (6); +const float GColorScale = (1.0/GColorScaleInv); float linearDepth(float d, vec3 clipInfo) { // z_n * z_f, z_n - z_f, z_f diff --git a/shader/lighting/ambient_light.frag b/shader/lighting/ambient_light.frag index fec9754f2..d206363e4 100644 --- a/shader/lighting/ambient_light.frag +++ b/shader/lighting/ambient_light.frag @@ -83,4 +83,5 @@ void main() { outColor = vec4(color, 1); // outColor = vec4(vec3(1-ao), 0); + // outColor = vec4(linear, 0); } diff --git a/shader/lighting/irradiance.comp b/shader/lighting/irradiance.comp index 18c271799..ba5643251 100644 --- a/shader/lighting/irradiance.comp +++ b/shader/lighting/irradiance.comp @@ -27,7 +27,7 @@ void storeSample(vec3 dir, vec3 val) { vec3 resolveMiss(const vec3 rayOrigin, const vec3 rayDirection) { // PERF: need to preload sky lut early in shader - return textureSkyLUT(skyLUT, vec3(0,RPlanet,0), rayDirection, scene.sunDir) * scene.GSunIntensity; + return textureSkyLUT(skyLUT, vec3(0,RPlanet,0), rayDirection, scene.sunDir) * scene.GSunIntensity * GColorScale; } void gather() { diff --git a/shader/lighting/light.frag b/shader/lighting/light.frag index df4a6fa64..ba8e23c7b 100644 --- a/shader/lighting/light.frag +++ b/shader/lighting/light.frag @@ -87,7 +87,7 @@ void main(void) { const vec3 d = texelFetch(gbufDiffuse, ivec2(gl_FragCoord.xy), 0).xyz; const vec3 linear = textureLinear(d.rgb); - vec3 color = linear*color*Fd_Lambert*light*0.2; + vec3 color = linear*color*light*Fd_Lambert*GColorScale*0.5; //color *= scene.exposure; outColor = vec4(color,0.0); diff --git a/shader/lighting/rt/probe_lighting.comp b/shader/lighting/rt/probe_lighting.comp index 3e48fbeae..fac1756b6 100644 --- a/shader/lighting/rt/probe_lighting.comp +++ b/shader/lighting/rt/probe_lighting.comp @@ -17,7 +17,7 @@ const uint samplesTotal = gl_WorkGroupSize.x*samplesCount; shared vec4 samples[gl_WorkGroupSize.x][3][2]; // 6 Kb shared uint shProbeId; -layout(binding = 0, std140) readonly buffer UboScene { +layout(binding = 0, std140) readonly buffer UboScene { // ubo is broken on NVidia? SceneDesc scene; }; layout(binding = 1) uniform writeonly image2D probesLighting; @@ -68,7 +68,9 @@ void storeSample(vec3 dir, vec4 val) { } } -vec3 resolveHit(const vec3 rayOrigin, const vec3 rayDirection, float rayT, vec3 albedo, vec3 normal, bool opaque, float shMap) { +vec3 resolveHit(const vec3 rayOrigin, const vec3 rayDirection, float rayT, vec3 normal, bool opaque, float shMap) { + // return 1.0 * scene.ambient; + float dt = dot(normal, scene.sunDir); if(!opaque) { // atificial lit on vegetation, as RT can't capture small bright light leaks from the trees @@ -78,9 +80,9 @@ vec3 resolveHit(const vec3 rayOrigin, const vec3 rayDirection, float rayT, vec3 const float lambert = max(0, dt); //max(opaque ? 0 : 0.2, dt); const float shadow = max(0, shMap); - const vec3 lcolor = scene.sunColor * Fd_Lambert * lambert * shadow; + const vec3 lcolor = scene.sunColor * Fd_Lambert * lambert * shadow * GColorScale; - return albedo*lcolor; + return lcolor; //return scene.sunColor * scene.ambient; } @@ -90,7 +92,7 @@ vec3 resolveMiss(const vec3 rayOrigin, const vec3 rayDirection) { } vec3 resolveSecondBounce(vec3 pos, vec3 norm, uint selfProbeId) { - return 4.0 * scene.ambient * Fd_LambertInv; + return scene.ambient; // doesn't look coherent yet - need to keep offscreen data for long term const ivec3 gridPos = ivec3(round(pos/(probeGridStep*1))); @@ -140,20 +142,24 @@ vec4 processSample(const vec3 rayOrigin, const vec3 rayDirection, uint probeId, const bool opaque = (bits & 0x1)!=0; const bool semiSky = (bits & 0x8)!=0; - const vec3 albedo = textureLinear(diff.rgb) * Fd_Lambert; + const vec3 albedo = textureLinear(diff.rgb); const vec3 norm = normalize(nr.xyz*2.0-vec3(1)); const float rayT = rt * probeRayDistance; const vec3 pos = rayOrigin + rayT*rayDirection; - const vec3 bounce2 = resolveSecondBounce(pos, -rayDirection, probeId); - // TODO: rt-shadow lighting ? vec4 shCoord = scene.viewShadow[1]*vec4(pos,1); float shadow = shadowFactor(shCoord); - vec3 hit = resolveHit(rayOrigin, rayDirection, rayT, albedo, norm, opaque, shadow); - hit += albedo*bounce2; + vec3 hit = vec3(0); + hit += albedo * resolveHit(rayOrigin, rayDirection, rayT, norm, opaque, shadow); + hit += albedo * resolveSecondBounce(pos, -rayDirection, probeId); + // hit += albedo * resolveHit(rayOrigin, rayDirection, rayT, norm, opaque, shadow); + // hit += albedo * resolveSecondBounce(pos, -rayDirection, probeId) / max(1.0 - albedo, 0.1); + + // hit = resolveSecondBounce(pos, -rayDirection, probeId); + if(semiSky) { // avoid pitch-black lighting in forrest hit = (hit*0.25 + resolveMiss(rayOrigin, rayDirection)*0.75); diff --git a/shader/lighting/sky_exposure.comp b/shader/lighting/sky_exposure.comp index db32a2e9c..019cacbf3 100644 --- a/shader/lighting/sky_exposure.comp +++ b/shader/lighting/sky_exposure.comp @@ -111,7 +111,7 @@ void main() { const vec3 sunColor = scene.sunColor * tr * clouds; const vec3 ambient = scene.ambient * tr;// * clouds; - vec3 light = sunColor*GColorScale*1.5 + ambient + skyIrradiance(); + vec3 light = sunColor*Fd_Lambert*1.5 + ambient + skyIrradiance(); float lum = (vmax+vmin) * 0.5 * scene.GSunIntensity; //lum = dot(light, vec3(1.0/3.0)); lum = dot(light, vec3(0.2125, 0.7154, 0.0721))*0.6 + lum*0.4; diff --git a/shader/lighting/tonemapping.frag b/shader/lighting/tonemapping.frag index aa85ad9e1..46a07f6bd 100644 --- a/shader/lighting/tonemapping.frag +++ b/shader/lighting/tonemapping.frag @@ -113,7 +113,7 @@ void main() { vec3 color = textureLod(textureD, uv, 0).rgb; { - // outColor = vec4(color, 1.0); + // outColor = vec4(srgbEncode(color), 1); // return; } diff --git a/shader/lighting/tonemapping.glsl b/shader/lighting/tonemapping.glsl index a06f4b853..8c6644d89 100644 --- a/shader/lighting/tonemapping.glsl +++ b/shader/lighting/tonemapping.glsl @@ -46,7 +46,7 @@ vec3 textureLinear(vec3 rgb) { // return vec3(0.33, 0.34, 0.18); // leaves // return vec3(0.9); // return acesTonemapInv(linear*0.8); - return acesTonemapInv(linear*0.78+0.001)*Fd_LambertInv; // adjusted to have 'realistic' albedo values + return acesTonemapInv(linear*0.78+0.001)*GColorScaleInv; // adjusted to have 'realistic' albedo values #endif }