vxgi shadowmap defines
This commit is contained in:
parent
7ac97b638e
commit
15c5a06584
|
@ -112,7 +112,7 @@ vec4 traceDiffuse(const vec3 origin, const vec3 normal, sampler3D voxels) {
|
|||
}
|
||||
|
||||
float traceShadow(sampler3D voxels, const vec3 origin, const vec3 dir, const float aperture, const float targetDistance, const vec3 normal) {
|
||||
return traceCone(voxels, origin, dir, aperture, targetDistance, normal).a;
|
||||
return traceCone(voxels, origin + normal * 0.04 * voxelgiOffset, dir, aperture, targetDistance, normal).a;
|
||||
}
|
||||
|
||||
vec3 traceSpecular(sampler3D voxels, const vec3 pos, const vec3 normal, const vec3 viewDir, const float roughness) {
|
||||
|
|
|
@ -13,18 +13,22 @@ uniform vec3 lightPos;
|
|||
uniform vec3 lightColor;
|
||||
uniform int lightType;
|
||||
uniform vec3 lightDir;
|
||||
uniform vec2 spotData;
|
||||
#ifndef _NoShadows
|
||||
uniform int lightShadow;
|
||||
uniform vec2 lightProj;
|
||||
uniform float shadowsBias;
|
||||
uniform mat4 LVP;
|
||||
uniform vec2 spotData;
|
||||
#endif
|
||||
|
||||
uniform layout(binding = 0, rgba8) readonly image3D voxelsOpac;
|
||||
uniform layout(binding = 1, r32ui) readonly uimage3D voxelsNor;
|
||||
// uniform layout(binding = 2, rgba8) writeonly image3D voxels;
|
||||
uniform layout(binding = 2, r32ui) uimage3D voxels;
|
||||
#ifndef _NoShadows
|
||||
uniform layout(binding = 3) sampler2D shadowMap;
|
||||
uniform layout(binding = 4) samplerCube shadowMapCube;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
|
||||
|
@ -48,14 +52,16 @@ void main() {
|
|||
float dotNL = max(dot(wnormal, l), 0.0);
|
||||
if (dotNL == 0.0) return;
|
||||
|
||||
vec4 lampPos = LVP * vec4(wposition, 1.0);
|
||||
|
||||
if (lightShadow == 1 && lampPos.w > 0.0) {
|
||||
#ifndef _NoShadows
|
||||
if (lightShadow == 1) {
|
||||
vec4 lampPos = LVP * vec4(wposition, 1.0);
|
||||
vec3 lPos = lampPos.xyz / lampPos.w;
|
||||
// if (lampPos.w > 0.0)
|
||||
if (texture(shadowMap, lPos.xy).r < lPos.z - shadowsBias) visibility = 0.0;
|
||||
// visibility = shadowTest(shadowMap, lPos, shadowsBias, shadowmapSize);
|
||||
}
|
||||
else if (lightShadow == 2) visibility *= float(texture(shadowMapCube, -l).r + shadowsBias > lpToDepth(lp, lightProj));
|
||||
#endif
|
||||
|
||||
if (lightType == 2) {
|
||||
float spotEffect = dot(lightDir, l);
|
||||
|
|
|
@ -297,11 +297,13 @@ class Inc {
|
|||
voxel_cb = voxel_sh.getConstantLocation("lightColor");
|
||||
voxel_cc = voxel_sh.getConstantLocation("lightType");
|
||||
voxel_cd = voxel_sh.getConstantLocation("lightDir");
|
||||
voxel_ci = voxel_sh.getConstantLocation("spotData");
|
||||
#if (rp_shadowmap)
|
||||
voxel_ce = voxel_sh.getConstantLocation("lightShadow");
|
||||
voxel_cf = voxel_sh.getConstantLocation("lightProj");
|
||||
voxel_cg = voxel_sh.getConstantLocation("LVP");
|
||||
voxel_ch = voxel_sh.getConstantLocation("shadowsBias");
|
||||
voxel_ci = voxel_sh.getConstantLocation("spotData");
|
||||
#end
|
||||
}
|
||||
|
||||
var rts = path.renderTargets;
|
||||
|
@ -315,7 +317,7 @@ class Inc {
|
|||
if (!l.visible) continue;
|
||||
path.currentLampIndex = i;
|
||||
|
||||
#if ((rp_shadowmap))
|
||||
#if (rp_shadowmap)
|
||||
{
|
||||
// TODO: merge with direct, drawing shadowmaps twice!
|
||||
if (path.lampCastShadow()) {
|
||||
|
@ -338,18 +340,6 @@ class Inc {
|
|||
// shadowMap
|
||||
kha.compute.Compute.setSampledTexture(voxel_td, rts.get("shadowMap").image);
|
||||
}
|
||||
#end
|
||||
|
||||
// lightPos
|
||||
kha.compute.Compute.setFloat3(voxel_ca, l.transform.worldx(), l.transform.worldy(), l.transform.worldz());
|
||||
// lightCol
|
||||
var f = l.data.raw.strength;
|
||||
kha.compute.Compute.setFloat3(voxel_cb, l.data.raw.color[0] * f, l.data.raw.color[1] * f, l.data.raw.color[2] * f);
|
||||
// lightType
|
||||
kha.compute.Compute.setInt(voxel_cc, iron.data.LampData.typeToInt(l.data.raw.type));
|
||||
// lightDir
|
||||
var v = l.look();
|
||||
kha.compute.Compute.setFloat3(voxel_cd, v.x, v.y, v.z);
|
||||
// lightShadow
|
||||
var i = l.data.raw.shadowmap_cube ? 2 : 1;
|
||||
kha.compute.Compute.setInt(voxel_ce, i);
|
||||
|
@ -368,6 +358,18 @@ class Inc {
|
|||
kha.compute.Compute.setMatrix(voxel_cg, m.self);
|
||||
// shadowsBias
|
||||
kha.compute.Compute.setFloat(voxel_ch, l.data.raw.shadows_bias);
|
||||
#end
|
||||
|
||||
// lightPos
|
||||
kha.compute.Compute.setFloat3(voxel_ca, l.transform.worldx(), l.transform.worldy(), l.transform.worldz());
|
||||
// lightCol
|
||||
var f = l.data.raw.strength;
|
||||
kha.compute.Compute.setFloat3(voxel_cb, l.data.raw.color[0] * f, l.data.raw.color[1] * f, l.data.raw.color[2] * f);
|
||||
// lightType
|
||||
kha.compute.Compute.setInt(voxel_cc, iron.data.LampData.typeToInt(l.data.raw.type));
|
||||
// lightDir
|
||||
var v = l.look();
|
||||
kha.compute.Compute.setFloat3(voxel_cd, v.x, v.y, v.z);
|
||||
// spotData
|
||||
if (l.data.raw.type == "spot") {
|
||||
var vx = l.data.raw.spot_size;
|
||||
|
|
Loading…
Reference in a new issue