Shadows for translucent context.
This commit is contained in:
parent
d4d6158a26
commit
2c64c4dc05
|
@ -350,6 +350,16 @@
|
|||
"name": "P",
|
||||
"link": "_projectionMatrix"
|
||||
},
|
||||
{
|
||||
"name": "LWVP",
|
||||
"link": "_lampWorldViewProjectionMatrix",
|
||||
"ifndef": "_NoShadows"
|
||||
},
|
||||
{
|
||||
"name": "shadowsBias",
|
||||
"link": "_lampShadowsBias",
|
||||
"ifndef": "_NoShadows"
|
||||
},
|
||||
{
|
||||
"name": "lightPos",
|
||||
"link": "_lampPosition"
|
||||
|
|
|
@ -12,10 +12,29 @@ precision mediump float;
|
|||
#include "../std/shirr.glsl"
|
||||
// shIrradiance()
|
||||
//!uniform float shirr[27];
|
||||
#ifndef _NoShadows
|
||||
#ifdef _PCSS
|
||||
#include "../std/shadows_pcss.glsl"
|
||||
// PCSS()
|
||||
#else
|
||||
#include "../std/shadows.glsl"
|
||||
// PCF()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _BaseTex
|
||||
uniform sampler2D sbase;
|
||||
#endif
|
||||
#ifndef _NoShadows
|
||||
//!uniform sampler2D shadowMap;
|
||||
#ifdef _PCSS
|
||||
//!uniform sampler2D snoise;
|
||||
//!uniform float lampSizeUV;
|
||||
//!uniform float lampNear;
|
||||
#endif
|
||||
uniform float shadowsBias;
|
||||
// uniform bool receiveShadow; // TODO: pass uniform from exporter
|
||||
#endif
|
||||
|
||||
#ifdef _Rad
|
||||
uniform sampler2D senvmapRadiance;
|
||||
|
@ -63,6 +82,9 @@ in vec3 position;
|
|||
#ifdef _Tex
|
||||
in vec2 texCoord;
|
||||
#endif
|
||||
#ifndef _NoShadows
|
||||
in vec4 lampPos;
|
||||
#endif
|
||||
in vec4 matColor;
|
||||
in vec3 eyeDir;
|
||||
#ifdef _NorTex
|
||||
|
@ -72,6 +94,21 @@ in vec3 eyeDir;
|
|||
#endif
|
||||
out vec4[2] fragColor;
|
||||
|
||||
#ifndef _NoShadows
|
||||
float shadowTest(vec4 lPos) {
|
||||
lPos.xyz /= lPos.w;
|
||||
lPos.xy = lPos.xy * 0.5 + 0.5;
|
||||
#ifdef _PCSS
|
||||
return PCSS(lPos.xy, lPos.z - shadowsBias);
|
||||
#else
|
||||
return PCF(lPos.xy, lPos.z - shadowsBias);
|
||||
#endif
|
||||
// return VSM(lPos.xy, lPos.z);
|
||||
// float distanceFromLight = texture(shadowMap, lPos.xy).r * 2.0 - 1.0;
|
||||
// return float(distanceFromLight > lPos.z - shadowsBias);
|
||||
}
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
|
||||
#ifdef _NorTex
|
||||
|
@ -94,6 +131,15 @@ void main() {
|
|||
}
|
||||
float dotNL = max(dot(n, l), 0.0);
|
||||
|
||||
float visibility = 1.0;
|
||||
#ifndef _NoShadows
|
||||
// if (receiveShadow) {
|
||||
if (lampPos.w > 0.0) {
|
||||
visibility = shadowTest(lampPos);
|
||||
}
|
||||
// }
|
||||
#endif
|
||||
|
||||
vec3 baseColor = matColor.rgb;
|
||||
#ifdef _BaseTex
|
||||
vec4 texel = texture(sbase, texCoord);
|
||||
|
@ -170,7 +216,7 @@ void main() {
|
|||
indirect = indirect * envmapStrength;// * lightColor * lightStrength;
|
||||
|
||||
|
||||
vec4 premultipliedReflect = vec4(vec3(direct + indirect * occlusion), matColor.a);
|
||||
vec4 premultipliedReflect = vec4(vec3(direct * visibility + indirect * occlusion), matColor.a);
|
||||
#ifdef _BaseTex
|
||||
premultipliedReflect.a *= texel.a; // Base color alpha
|
||||
#endif
|
||||
|
|
|
@ -33,6 +33,9 @@ uniform mat4 W;
|
|||
uniform mat4 N;
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
#ifndef _NoShadows
|
||||
uniform mat4 LWVP;
|
||||
#endif
|
||||
uniform vec4 baseCol;
|
||||
uniform vec3 eye;
|
||||
#ifdef _Skinning
|
||||
|
@ -44,6 +47,9 @@ out vec3 position;
|
|||
#ifdef _Tex
|
||||
out vec2 texCoord;
|
||||
#endif
|
||||
#ifndef _NoShadows
|
||||
out vec4 lampPos;
|
||||
#endif
|
||||
out vec4 matColor;
|
||||
out vec3 eyeDir;
|
||||
#ifdef _NorTex
|
||||
|
@ -70,6 +76,10 @@ void main() {
|
|||
sPos.xyz += off;
|
||||
#endif
|
||||
|
||||
#ifndef _NoShadows
|
||||
lampPos = LWVP * sPos;
|
||||
#endif
|
||||
|
||||
mat4 WV = V * W;
|
||||
|
||||
#ifdef _Billboard
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
},
|
||||
{
|
||||
"name": "LWVP",
|
||||
"link": "_lampWorldViewProjectionMatrix"
|
||||
"link": "_lampWorldViewProjectionMatrix",
|
||||
"ifndef": "_NoShadows"
|
||||
},
|
||||
{
|
||||
"name": "lightPos",
|
||||
|
|
|
@ -102,7 +102,9 @@ in vec3 position;
|
|||
#ifdef _Tex1
|
||||
in vec2 texCoord1;
|
||||
#endif
|
||||
in vec4 lampPos;
|
||||
#ifndef _NoShadows
|
||||
in vec4 lampPos;
|
||||
#endif
|
||||
in vec4 matColor;
|
||||
in vec3 eyeDir;
|
||||
#ifdef _NorTex
|
||||
|
|
|
@ -44,7 +44,9 @@ uniform mat4 N;
|
|||
#endif
|
||||
uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform mat4 LWVP;
|
||||
#ifndef _NoShadows
|
||||
uniform mat4 LWVP;
|
||||
#endif
|
||||
uniform vec4 baseCol;
|
||||
uniform vec3 eye;
|
||||
#ifdef _Skinning
|
||||
|
@ -62,7 +64,9 @@ out vec3 position;
|
|||
#ifdef _Tex1
|
||||
out vec2 texCoord1;
|
||||
#endif
|
||||
out vec4 lampPos;
|
||||
#ifndef _NoShadows
|
||||
out vec4 lampPos;
|
||||
#endif
|
||||
out vec4 matColor;
|
||||
out vec3 eyeDir;
|
||||
#ifdef _NorTex
|
||||
|
@ -89,7 +93,9 @@ void main() {
|
|||
sPos.xyz += off;
|
||||
#endif
|
||||
|
||||
#ifndef _NoShadows
|
||||
lampPos = LWVP * sPos;
|
||||
#endif
|
||||
|
||||
mat4 WV = V * W;
|
||||
|
||||
|
|
|
@ -4,8 +4,26 @@
|
|||
precision mediump float;
|
||||
#endif
|
||||
|
||||
#ifdef _Translucent
|
||||
in vec2 texCoord;
|
||||
#endif
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
#ifdef _Translucent
|
||||
// #ifdef _BaseTex
|
||||
uniform sampler2D sbase;
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
|
||||
#ifdef _Translucent
|
||||
float a = texture(sbase, texCoord).a;
|
||||
if (a < 0.5) {
|
||||
discard;
|
||||
}
|
||||
#endif
|
||||
|
||||
fragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
|
|
@ -31,12 +31,15 @@ in vec3 nor;
|
|||
|
||||
uniform mat4 LWVP;
|
||||
#ifdef _Billboard
|
||||
uniform mat4 WV;
|
||||
uniform mat4 P;
|
||||
uniform mat4 WV;
|
||||
uniform mat4 P;
|
||||
#endif
|
||||
#ifdef _Skinning
|
||||
//!uniform float skinBones[skinMaxBones * 8];
|
||||
#endif
|
||||
#ifdef _Translucent
|
||||
out vec2 texCoord;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec4 sPos = vec4(pos, 1.0);
|
||||
|
@ -53,6 +56,10 @@ void main() {
|
|||
sPos.xyz += off;
|
||||
#endif
|
||||
|
||||
#ifdef _Translucent
|
||||
texCoord = tex;
|
||||
#endif
|
||||
|
||||
#ifdef _Billboard
|
||||
mat4 constrWV = WV;
|
||||
// Spherical
|
||||
|
|
|
@ -2720,10 +2720,6 @@ class ArmoryExporter:
|
|||
# Override context
|
||||
if material.override_shader_context:
|
||||
c['name'] = material.override_shader_context_name
|
||||
# If material has transparency switch to translucent context
|
||||
elif '_Translucent' in defs:
|
||||
defs.remove('_Translucent')
|
||||
c['name'] = ArmoryExporter.translucent_context
|
||||
# If material has height map switch to tessellation displacement context
|
||||
elif '_HeightTex' in defs:
|
||||
c['name'] = ArmoryExporter.mesh_context + 'height'
|
||||
|
@ -2773,6 +2769,16 @@ class ArmoryExporter:
|
|||
if wrd.generate_shadows == True:
|
||||
c2 = {}
|
||||
c2['name'] = ArmoryExporter.shadows_context
|
||||
|
||||
# Opacity for shadowmap in Translucent context
|
||||
if '_Translucent' in defs:
|
||||
for bt in c['bind_textures']:
|
||||
if bt['name'] == 'sbase':
|
||||
c2['bind_textures'] = [bt]
|
||||
break
|
||||
# Switch main context to translucent
|
||||
c['name'] = ArmoryExporter.translucent_context
|
||||
|
||||
o['contexts'].append(c2)
|
||||
|
||||
# VGI Voxels enabled, append context
|
||||
|
|
Loading…
Reference in a new issue