Fix shadowmap handling
This commit is contained in:
parent
c669c44d09
commit
c6de00dc60
|
@ -23,18 +23,11 @@ class RenderPathCreator {
|
|||
|
||||
#if (rp_renderer == "Forward")
|
||||
static function init() {
|
||||
// #if rp_shadowmap // Auto-created
|
||||
// {
|
||||
// var size = getShadowmapSize();
|
||||
// var t = new RenderTargetRaw();
|
||||
// t.name = "shadowMap";
|
||||
// t.width = size;
|
||||
// t.height = size;
|
||||
// t.format = "DEPTH16";
|
||||
// path.createRenderTarget(t);
|
||||
// }
|
||||
// #end
|
||||
|
||||
#if kha_webgl
|
||||
initEmpty();
|
||||
#end
|
||||
|
||||
#if (rp_background == "World")
|
||||
{
|
||||
path.loadShader("shader_datas/world_pass/world_pass");
|
||||
|
@ -93,7 +86,7 @@ class RenderPathCreator {
|
|||
var faces = path.getLamp(path.currentLampIndex).data.raw.shadowmap_cube ? 6 : 1;
|
||||
for (i in 0...faces) {
|
||||
if (faces > 1) path.currentFace = i;
|
||||
path.setTarget("shadowMap");
|
||||
path.setTarget(getShadowMap());
|
||||
path.clearTarget(null, 1.0);
|
||||
path.drawMeshes("shadowmap");
|
||||
}
|
||||
|
@ -122,7 +115,7 @@ class RenderPathCreator {
|
|||
path.bindTarget(voxels, "voxels");
|
||||
#if rp_shadowmap
|
||||
{
|
||||
path.bindTarget("shadowMap", "shadowMap");
|
||||
bindShadowMap();
|
||||
}
|
||||
#end
|
||||
path.drawMeshes("voxel");
|
||||
|
@ -159,7 +152,7 @@ class RenderPathCreator {
|
|||
|
||||
#if rp_shadowmap
|
||||
{
|
||||
path.bindTarget("shadowMap", "shadowMap");
|
||||
bindShadowMap();
|
||||
}
|
||||
#end
|
||||
|
||||
|
@ -231,6 +224,11 @@ class RenderPathCreator {
|
|||
|
||||
#if (rp_renderer == "Deferred")
|
||||
static function init() {
|
||||
|
||||
#if kha_webgl
|
||||
initEmpty();
|
||||
#end
|
||||
|
||||
#if (rp_background == "World")
|
||||
{
|
||||
path.loadShader("shader_datas/world_pass/world_pass");
|
||||
|
@ -556,7 +554,7 @@ class RenderPathCreator {
|
|||
var faces = l.data.raw.shadowmap_cube ? 6 : 1;
|
||||
for (j in 0...faces) {
|
||||
if (faces > 1) path.currentFace = j;
|
||||
path.setTarget("shadowMap");
|
||||
path.setTarget(getShadowMap());
|
||||
path.clearTarget(null, 1.0);
|
||||
path.drawMeshes("shadowmap");
|
||||
}
|
||||
|
@ -566,7 +564,7 @@ class RenderPathCreator {
|
|||
#if rp_soft_shadows
|
||||
|
||||
path.setTarget("visa"); // Merge using min blend
|
||||
path.bindTarget("shadowMap", "shadowMap");
|
||||
bindShadowMap();
|
||||
path.drawShader("shader_datas/dilate_pass/dilate_pass_x");
|
||||
|
||||
path.setTarget("visb");
|
||||
|
@ -576,7 +574,7 @@ class RenderPathCreator {
|
|||
path.setTarget("visa", ["dist"]);
|
||||
//if (i == 0) path.clearTarget(0x00000000);
|
||||
path.bindTarget("visb", "dilate");
|
||||
path.bindTarget("shadowMap", "shadowMap");
|
||||
bindShadowMap();
|
||||
//path.bindTarget("_main", "gbufferD");
|
||||
path.bindTarget("gbuffer0", "gbuffer0");
|
||||
path.drawShader("shader_datas/visibility_pass/visibility_pass");
|
||||
|
@ -704,7 +702,7 @@ class RenderPathCreator {
|
|||
path.bindTarget(voxels, "voxels");
|
||||
#if ((rp_shadowmap) && (rp_gi == "Voxel GI"))
|
||||
{
|
||||
path.bindTarget("shadowMap", "shadowMap");
|
||||
bindShadowMap();
|
||||
}
|
||||
#end
|
||||
path.drawMeshes("voxel");
|
||||
|
@ -761,7 +759,7 @@ class RenderPathCreator {
|
|||
#if rp_soft_shadows
|
||||
path.bindTarget("visa", "svisibility");
|
||||
#else
|
||||
path.bindTarget("shadowMap", "shadowMap");
|
||||
bindShadowMap();
|
||||
#end
|
||||
}
|
||||
}
|
||||
|
@ -784,7 +782,7 @@ class RenderPathCreator {
|
|||
{
|
||||
path.setTarget("buf");
|
||||
path.bindTarget("_main", "gbufferD");
|
||||
path.bindTarget("shadowMap", "shadowMap");
|
||||
bindShadowMap();
|
||||
if (path.lampIsSun()) {
|
||||
path.drawShader("shader_datas/volumetric_light_quad/volumetric_light_quad");
|
||||
}
|
||||
|
@ -1056,9 +1054,6 @@ class RenderPathCreator {
|
|||
#end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// #if (rp_renderer == "Deferred Plus")
|
||||
// static function init() {
|
||||
|
||||
|
@ -1070,8 +1065,79 @@ class RenderPathCreator {
|
|||
// #end
|
||||
|
||||
|
||||
static function bindShadowMap() {
|
||||
var target = shadowMapName();
|
||||
if (target == "shadowMapCube") {
|
||||
#if kha_webgl
|
||||
// Bind empty map to non-cubemap sampler to keep webgl happy
|
||||
path.bindTarget("arm_empty", "shadowMap");
|
||||
#end
|
||||
path.bindTarget("shadowMapCube", "shadowMapCube");
|
||||
}
|
||||
else {
|
||||
#if kha_webgl
|
||||
// Bind empty map to cubemap sampler
|
||||
path.bindTarget("arm_empty_cube", "shadowMapCube");
|
||||
#end
|
||||
path.bindTarget("shadowMap", "shadowMap");
|
||||
}
|
||||
}
|
||||
|
||||
static function shadowMapName():String {
|
||||
return path.getLamp(path.currentLampIndex).data.raw.shadowmap_cube ? "shadowMapCube" : "shadowMap";
|
||||
}
|
||||
|
||||
static function getShadowMap():String {
|
||||
var target = shadowMapName();
|
||||
var rt = path.renderTargets.get(target);
|
||||
// Create shadowmap on the fly
|
||||
if (rt == null) {
|
||||
if (path.getLamp(path.currentLampIndex).data.raw.shadowmap_cube) {
|
||||
// Cubemap size
|
||||
var size = Std.int(path.getLamp(path.currentLampIndex).data.raw.shadowmap_size);
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = target;
|
||||
t.width = size;
|
||||
t.height = size;
|
||||
t.format = "DEPTH16";
|
||||
t.is_cubemap = true;
|
||||
rt = path.createRenderTarget(t);
|
||||
}
|
||||
else { // Non-cube sm
|
||||
var sizew = path.getLamp(path.currentLampIndex).data.raw.shadowmap_size;
|
||||
var sizeh = sizew;
|
||||
#if arm_csm // Cascades - atlas on x axis
|
||||
sizew = sizeh * iron.object.LampObject.cascadeCount;
|
||||
#end
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = target;
|
||||
t.width = sizew;
|
||||
t.height = sizeh;
|
||||
t.format = "DEPTH16";
|
||||
rt = path.createRenderTarget(t);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
#if kha_webgl
|
||||
static function initEmpty() {
|
||||
// Bind empty when requested target is not found
|
||||
var tempty = new RenderTargetRaw();
|
||||
tempty.name = "arm_empty";
|
||||
tempty.width = 1;
|
||||
tempty.height = 1;
|
||||
tempty.format = "DEPTH16";
|
||||
path.createRenderTarget(tempty);
|
||||
var temptyCube = new RenderTargetRaw();
|
||||
temptyCube.name = "arm_empty_cube";
|
||||
temptyCube.width = 1;
|
||||
temptyCube.height = 1;
|
||||
temptyCube.format = "DEPTH16";
|
||||
temptyCube.is_cubemap = true;
|
||||
path.createRenderTarget(temptyCube);
|
||||
}
|
||||
#end
|
||||
|
||||
#if (rp_translucency)
|
||||
static function initTranslucency() {
|
||||
|
@ -1110,7 +1176,7 @@ class RenderPathCreator {
|
|||
path.setTarget("accum", ["revealage"]);
|
||||
#if rp_shadowmap
|
||||
{
|
||||
path.bindTarget("shadowMap", "shadowMap");
|
||||
bindShadowMap();
|
||||
}
|
||||
#end
|
||||
path.drawMeshes("translucent");
|
||||
|
|
Loading…
Reference in a new issue