Rotate irradiance

This commit is contained in:
Lubos Lenco
2020-06-02 10:41:28 +02:00
parent e6db3c27b0
commit 3d3ee0b6e2
7 changed files with 20 additions and 26 deletions
Binary file not shown.
Binary file not shown.
+4 -5
View File
@@ -44,8 +44,7 @@ uniform float voxelBlend;
uniform vec3 eyeSnap;
#endif
uniform float envmapStrength;
uniform float envmapAngle;
uniform vec4 envmapData; // angle, sin(angle), cos(angle), strength
#ifdef _Irr
uniform vec4 shirr[7];
#endif
@@ -206,7 +205,7 @@ void main() {
// Envmap
#ifdef _Irr
vec3 envl = shIrradiance(n, shirr);
vec3 envl = shIrradiance(vec3(n.x * envmapData.z - n.y * envmapData.y, n.x * envmapData.y + n.y * envmapData.z, n.z), shirr);
#ifdef _EnvTex
envl /= PI;
#endif
@@ -217,7 +216,7 @@ void main() {
#ifdef _Rad
vec3 reflectionWorld = reflect(-v, n);
float lod = getMipFromRoughness(roughness, envmapNumMipmaps);
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld, envmapAngle), lod).rgb;
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld, envmapData.x), lod).rgb;
#endif
#ifdef _EnvLDR
@@ -237,7 +236,7 @@ void main() {
#endif
#endif
envl.rgb *= envmapStrength * occ;
envl.rgb *= envmapData.w * occ;
#ifdef _VoxelAOvar
@@ -45,8 +45,7 @@ uniform float voxelBlend;
uniform vec3 eyeSnap;
#endif
uniform float envmapStrength;
uniform float envmapAngle;
uniform vec4 envmapData;
#ifdef _Irr
uniform vec4 shirr[7];
#endif
@@ -207,7 +206,7 @@ void main() {
// Envmap
#ifdef _Irr
vec3 envl = shIrradiance(n, shirr);
vec3 envl = shIrradiance(vec3(n.x * envmapData.z - n.y * envmapData.y, n.x * envmapData.y + n.y * envmapData.z, n.z), shirr);
#ifdef _EnvTex
envl /= PI;
#endif
@@ -218,7 +217,7 @@ void main() {
#ifdef _Rad
vec3 reflectionWorld = reflect(-v, n);
float lod = getMipFromRoughness(roughness, envmapNumMipmaps);
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld, envmapAngle), lod).rgb;
vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(reflectionWorld, envmapData.x), lod).rgb;
#endif
#ifdef _EnvLDR
@@ -238,7 +237,7 @@ void main() {
#endif
#endif
envl.rgb *= envmapStrength * occ;
envl.rgb *= envmapData.w * occ;
#ifdef _VoxelAOvar
+4 -8
View File
@@ -1,6 +1,5 @@
#version 450
#define _EnvStr
#define _EnvTex
#ifdef _EnvTex
@@ -37,10 +36,7 @@
uniform sampler2D envmap;
#endif
#ifdef _EnvStr
uniform float envmapStrength;
#endif
uniform float envmapAngle;
uniform vec4 envmapData; // angle, sin(angle), cos(angle), strength
in vec3 normal;
out vec4 fragColor;
@@ -138,7 +134,7 @@ void main() {
#ifndef _EnvSky // Prevent case when sky radiance is enabled
#ifdef _EnvTex
vec3 n = normalize(normal);
fragColor.rgb = texture(envmap, envMapEquirect(n, envmapAngle)).rgb * envmapStrength;
fragColor.rgb = texture(envmap, envMapEquirect(n, envmapData.x)).rgb * envmapData.w;
#ifdef _EnvLDR
fragColor.rgb = pow(fragColor.rgb, vec3(2.2));
#endif
@@ -148,7 +144,7 @@ void main() {
#ifdef _EnvImg // Static background
// Will have to get rid of gl_FragCoord, pass tc from VS
vec2 texco = gl_FragCoord.xy / screenSize;
fragColor.rgb = texture(envmap, vec2(texco.x, 1.0 - texco.y)).rgb * envmapStrength;
fragColor.rgb = texture(envmap, vec2(texco.x, 1.0 - texco.y)).rgb * envmapData.w;
#endif
#ifdef _EnvSky
@@ -160,7 +156,7 @@ void main() {
float cos_gamma = dot(n, hosekSunDirection);
float gamma_val = acos(cos_gamma);
fragColor.rgb = Z * hosekWilkie(cos_theta, gamma_val, cos_gamma) * envmapStrength;
fragColor.rgb = Z * hosekWilkie(cos_theta, gamma_val, cos_gamma) * envmapData.w;
#endif
#ifdef _EnvClouds
+4 -5
View File
@@ -349,11 +349,11 @@ class MakeMesh {
frag.write('vec2 envBRDF = texture(senvmapBrdf, vec2(roughness, 1.0 - dotNV)).xy;');
frag.add_uniform('sampler2D senvmapRadiance', '_envmapRadiance');
frag.add_uniform('int envmapNumMipmaps', '_envmapNumMipmaps');
frag.add_uniform('float envmapAngle', '_envmapAngle');
frag.add_uniform('vec4 envmapData', '_envmapData'); // angle, sin(angle), cos(angle), strength
frag.write('vec3 wreflect = reflect(-vVec, wn);');
frag.write('float envlod = roughness * float(envmapNumMipmaps);');
frag.add_function(MaterialFunctions.str_envMapEquirect);
frag.write('vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(wreflect, envmapAngle), envlod).rgb;');
frag.write('vec3 prefilteredColor = textureLod(senvmapRadiance, envMapEquirect(wreflect, envmapData.x), envlod).rgb;');
frag.add_uniform('vec3 lightArea0', '_lightArea0');
frag.add_uniform('vec3 lightArea1', '_lightArea1');
@@ -382,12 +382,11 @@ class MakeMesh {
frag.write('vec3 direct = albedo * ltcdiff + ltcspec * 0.05;');
frag.write('direct *= lightColor * (1.0 / (ldist * ldist));');
frag.add_uniform('float envmapStrength', '_envmapStrength');
frag.add_uniform('vec4 shirr[7]', '_envmapIrradiance');
frag.add_function(MaterialFunctions.str_shIrradiance);
frag.write('vec3 indirect = albedo * (shIrradiance(wn, shirr) / 3.14159265);');
frag.write('vec3 indirect = albedo * (shIrradiance(vec3(wn.x * envmapData.z - wn.y * envmapData.y, wn.x * envmapData.y + wn.y * envmapData.z, wn.z), shirr) / 3.14159265);');
frag.write('indirect += prefilteredColor * (f0 * envBRDF.x + envBRDF.y) * 1.5;');
frag.write('indirect *= envmapStrength * occlusion;');
frag.write('indirect *= envmapData.w * occlusion;');
frag.write('fragColor[1] = vec4(direct + indirect, 1.0);');
}
else { // Deferred, Pathtraced
+4 -3
View File
@@ -77,9 +77,6 @@ class Uniforms {
if (link == "_objectId") {
return Project.paintObjects.indexOf(Context.paintObject);
}
if (link == "_envmapAngle") {
return Context.envmapAngle;
}
#end
#if arm_world
if (link == "_voxelgiHalfExtentsUni") {
@@ -321,6 +318,10 @@ class Uniforms {
if (Context.paint2d) vec.x -= 1.0;
return vec;
}
if (link == "_envmapData") {
vec.set(Context.envmapAngle, Math.sin(-Context.envmapAngle), Math.cos(-Context.envmapAngle), Scene.active.world.probe.raw.strength);
return vec;
}
#end
return null;
}