Fix sun area light
This commit is contained in:
parent
79e5e9f880
commit
f3a637fb99
@ -49,7 +49,7 @@ void main(void)
|
||||
vec3 sampleDirection = reflect(-eyedir, normal);
|
||||
sampleDirection = (InverseViewMatrix * vec4(sampleDirection, 0.)).xyz;
|
||||
|
||||
float specval = pow(texture(ntex, uv).z, 2.);
|
||||
float specval = texture(ntex, uv).z;
|
||||
// From http://graphics.cs.williams.edu/papers/EnvMipReport2013/
|
||||
int texSize = textureSize(tex, 0).x;
|
||||
float lodval = clamp(log2(texSize * sqrt(3.)) - .5 * log2(specval + 1.), 0., 10.);
|
||||
|
@ -19,5 +19,5 @@ void main(void)
|
||||
float glossmap = texture(glosstex, uv).x;
|
||||
#endif
|
||||
EncodedNormal.xy = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
|
||||
EncodedNormal.z = exp2(10. * glossmap + 1.);
|
||||
EncodedNormal.z = exp2(20. * glossmap + 1.);
|
||||
}
|
||||
|
@ -24,6 +24,6 @@ void main() {
|
||||
if (col.a < 0.5)
|
||||
discard;
|
||||
EncodedNormal.xy = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
|
||||
EncodedNormal.z = exp2(10. * glossmap + 1.);
|
||||
EncodedNormal.z = exp2(20. * glossmap + 1.);
|
||||
}
|
||||
|
||||
|
@ -19,5 +19,5 @@ void main(void)
|
||||
{
|
||||
float glossmap = texture(tex, uv).x;
|
||||
EncodedNormal.xy = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
|
||||
EncodedNormal.z = exp2(10. * glossmap + 1.);
|
||||
EncodedNormal.z = exp2(20. * glossmap + 1.);
|
||||
}
|
||||
|
@ -24,6 +24,6 @@ void main() {
|
||||
discard;
|
||||
float glossmap = texture(glosstex, uv).x;
|
||||
EncodedNormal.xy = 0.5 * EncodeNormal(normalize(nor)) + 0.5;
|
||||
EncodedNormal.z = exp2(10. * glossmap + 1.);
|
||||
EncodedNormal.z = exp2(20. * glossmap + 1.);
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,16 @@ vec3 DecodeNormal(vec2 n);
|
||||
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
|
||||
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
|
||||
|
||||
vec3 getMostRepresentativePoint(vec3 direction, vec3 R, float angularRadius)
|
||||
{
|
||||
vec3 D = direction;
|
||||
float d = cos(angularRadius);
|
||||
float r = sin(angularRadius);
|
||||
float DdotR = dot(D, R);
|
||||
vec3 S = R - DdotR * D;
|
||||
return (DdotR < d) ? normalize(d * D + normalize (S) * r) : R;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 uv = gl_FragCoord.xy / screen;
|
||||
float z = texture(dtex, uv).x;
|
||||
@ -38,16 +48,11 @@ void main() {
|
||||
|
||||
float NdotL = max(0., dot(norm, L));
|
||||
|
||||
vec3 D = direction;
|
||||
vec3 R = reflect(eyedir, norm);
|
||||
float angle = 3.14 * sunangle / 180;
|
||||
float d = cos(angle);
|
||||
float r = sin(angle);
|
||||
float DdotR = dot (D, R);
|
||||
vec3 S = R - DdotR * D;
|
||||
vec3 Lightdir = DdotR < d ? normalize (d * D + normalize (S) * r) : R;
|
||||
float angle = 3.14 * sunangle / 180.;
|
||||
vec3 R = reflect(-eyedir, norm);
|
||||
vec3 Lightdir = getMostRepresentativePoint(direction, R, angle);
|
||||
|
||||
vec3 Specular = getSpecular(norm, eyedir, L, col, roughness) * dot(Lightdir, norm);
|
||||
vec3 Specular = getSpecular(norm, eyedir, Lightdir, col, roughness) * NdotL;
|
||||
|
||||
vec3 outcol = NdotL * col;
|
||||
|
||||
|
@ -19,6 +19,16 @@ vec3 DecodeNormal(vec2 n);
|
||||
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
|
||||
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
|
||||
|
||||
vec3 getMostRepresentativePoint(vec3 direction, vec3 R, float angularRadius)
|
||||
{
|
||||
vec3 D = direction;
|
||||
float d = cos(angularRadius);
|
||||
float r = sin(angularRadius);
|
||||
float DdotR = dot(D, R);
|
||||
vec3 S = R - DdotR * D;
|
||||
return (DdotR < d) ? normalize(d * D + normalize (S) * r) : R;
|
||||
}
|
||||
|
||||
float getShadowFactor(vec3 pos, float bias, int index)
|
||||
{
|
||||
|
||||
@ -52,16 +62,11 @@ void main() {
|
||||
|
||||
float NdotL = max(0., dot(norm, L));
|
||||
|
||||
vec3 D = direction;
|
||||
vec3 R = reflect(eyedir, norm);
|
||||
float angle = 3.14 * sunangle / 180;
|
||||
float d = cos(angle);
|
||||
float r = sin(angle);
|
||||
float DdotR = dot (D, R);
|
||||
vec3 S = R - DdotR * D;
|
||||
vec3 Lightdir = DdotR < d ? normalize (d * D + normalize (S) * r) : R;
|
||||
float angle = 3.14 * sunangle / 180.;
|
||||
vec3 R = reflect(-eyedir, norm);
|
||||
vec3 Lightdir = getMostRepresentativePoint(direction, R, angle);
|
||||
|
||||
vec3 Specular = getSpecular(norm, eyedir, Lightdir, col, roughness) * dot(norm, Lightdir);
|
||||
vec3 Specular = getSpecular(norm, eyedir, Lightdir, col, roughness) * NdotL;
|
||||
|
||||
|
||||
vec3 outcol = NdotL * col;
|
||||
|
Loading…
Reference in New Issue
Block a user