Update shadowmap props
This commit is contained in:
parent
25ae41f9c3
commit
023668221e
|
@ -439,7 +439,7 @@ void main() {
|
|||
#ifdef _SMSizeUniform
|
||||
visibility *= shadowTest(shadowMap0, lPos.xyz / lPos.w, bias, smSizeUniform);
|
||||
#else
|
||||
visibility *= shadowTest(shadowMap0, lPos.xyz / lPos.w, bias, shadowmapSize);
|
||||
visibility *= shadowTest(shadowMap0, lPos.xyz / lPos.w, bias, shadowmapSizeCube);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -36,7 +36,8 @@ typedef TConfig = {
|
|||
@:optional var window_msaa:Null<Int>;
|
||||
@:optional var window_scale:Null<Float>;
|
||||
@:optional var rp_supersample:Null<Float>;
|
||||
@:optional var rp_shadowmap:Null<Int>; // size
|
||||
@:optional var rp_shadowmap_cube:Null<Int>; // size
|
||||
@:optional var rp_shadowmap_cascade:Null<Int>; // size for single cascade
|
||||
@:optional var rp_ssgi:Null<Bool>;
|
||||
@:optional var rp_ssr:Null<Bool>;
|
||||
@:optional var rp_bloom:Null<Bool>;
|
||||
|
|
|
@ -37,7 +37,11 @@ class Inc {
|
|||
|
||||
#if arm_config
|
||||
var config = armory.data.Config.raw;
|
||||
for (l in iron.Scene.active.lights) l.data.raw.shadowmap_size = config.rp_shadowmap;
|
||||
for (l in iron.Scene.active.lights) {
|
||||
l.data.raw.shadowmap_size = l.data.raw.type == "sun" ?
|
||||
config.rp_shadowmap_cascade :
|
||||
config.rp_shadowmap_cube;
|
||||
}
|
||||
superSample = config.rp_supersample;
|
||||
#end
|
||||
}
|
||||
|
@ -92,7 +96,7 @@ class Inc {
|
|||
var sizew = path.light.data.raw.shadowmap_size;
|
||||
var sizeh = sizew;
|
||||
#if arm_csm // Cascades - atlas on x axis
|
||||
sizew = sizeh * iron.object.LightObject.cascadeCount;
|
||||
sizew = sizew * iron.object.LightObject.cascadeCount;
|
||||
#end
|
||||
var t = new RenderTargetRaw();
|
||||
t.name = target;
|
||||
|
@ -164,13 +168,15 @@ class Inc {
|
|||
var config = armory.data.Config.raw;
|
||||
// Resize shadow map
|
||||
var l = path.light;
|
||||
if (l.data.raw.shadowmap_size != config.rp_shadowmap) {
|
||||
if (l.data.raw.type == "sun" && l.data.raw.shadowmap_size != config.rp_shadowmap_cascade) {
|
||||
l.data.raw.shadowmap_size = config.rp_shadowmap;
|
||||
var rt = path.renderTargets.get("shadowMap");
|
||||
if (rt != null) {
|
||||
rt.unload();
|
||||
path.renderTargets.remove("shadowMap");
|
||||
}
|
||||
}
|
||||
else if (l.data.raw.shadowmap_size != config.rp_shadowmap_cube) {
|
||||
rt = path.renderTargets.get("shadowMapCube");
|
||||
if (rt != null) {
|
||||
rt.unload();
|
||||
|
@ -286,19 +292,33 @@ class Inc {
|
|||
}
|
||||
#end
|
||||
|
||||
public static inline function getShadowmapSize():Int {
|
||||
#if (rp_shadowmap_size == 512)
|
||||
public static inline function getCubeSize():Int {
|
||||
#if (rp_shadowmap_cube == 256)
|
||||
return 256;
|
||||
#elseif (rp_shadowmap_cube == 512)
|
||||
return 512;
|
||||
#elseif (rp_shadowmap_size == 1024)
|
||||
#elseif (rp_shadowmap_cube == 1024)
|
||||
return 1024;
|
||||
#elseif (rp_shadowmap_size == 2048)
|
||||
#elseif (rp_shadowmap_cube == 2048)
|
||||
return 2048;
|
||||
#elseif (rp_shadowmap_size == 4096)
|
||||
#elseif (rp_shadowmap_cube == 4096)
|
||||
return 4096;
|
||||
#else
|
||||
return 0;
|
||||
#end
|
||||
}
|
||||
|
||||
public static inline function getCascadeSize():Int {
|
||||
#if (rp_shadowmap_cascade == 256)
|
||||
return 256;
|
||||
#elseif (rp_shadowmap_cascade == 512)
|
||||
return 512;
|
||||
#elseif (rp_shadowmap_cascade == 1024)
|
||||
return 1024;
|
||||
#elseif (rp_shadowmap_cascade == 2048)
|
||||
return 2048;
|
||||
#elseif (rp_shadowmap_cascade == 4096)
|
||||
return 4096;
|
||||
#elseif (rp_shadowmap_size == 8192)
|
||||
return 8192;
|
||||
#elseif (rp_shadowmap_size == 16384)
|
||||
return 16384;
|
||||
#else
|
||||
return 0;
|
||||
#end
|
||||
|
|
|
@ -1750,10 +1750,10 @@ class ArmoryExporter:
|
|||
o['fov'] = objref.arm_fov
|
||||
o['shadows_bias'] = objref.arm_shadows_bias * 0.0001
|
||||
rpdat = arm.utils.get_rp()
|
||||
if rpdat.rp_shadowmap == 'Off':
|
||||
o['shadowmap_size'] = 0
|
||||
if rpdat.rp_shadows:
|
||||
o['shadowmap_size'] = int(rpdat.rp_shadowmap_cube) if objtype == 'POINT' else int(rpdat.rp_shadowmap_cascade)
|
||||
else:
|
||||
o['shadowmap_size'] = int(rpdat.rp_shadowmap)
|
||||
o['shadowmap_size'] = 0
|
||||
if o['type'] == 'sun': # Scale bias for ortho light matrix
|
||||
o['shadows_bias'] *= 25.0
|
||||
if o['shadowmap_size'] > 1024:
|
||||
|
|
|
@ -44,7 +44,7 @@ def add_world_defs():
|
|||
elif rpdat.rp_gi == 'Voxel AO':
|
||||
voxelao = True
|
||||
# Shadows
|
||||
if rpdat.rp_shadowmap != 'Off':
|
||||
if rpdat.rp_shadows:
|
||||
wrd.world_defs += '_ShadowMap'
|
||||
if rpdat.rp_shadowmap_cascades != '1':
|
||||
if voxelgi:
|
||||
|
@ -133,9 +133,10 @@ def build():
|
|||
if rpdat.rp_depthprepass:
|
||||
assets.add_khafile_def('rp_depthprepass')
|
||||
|
||||
if rpdat.rp_shadowmap != 'Off':
|
||||
if rpdat.rp_shadows:
|
||||
assets.add_khafile_def('rp_shadowmap')
|
||||
assets.add_khafile_def('rp_shadowmap_size={0}'.format(rpdat.rp_shadowmap))
|
||||
assets.add_khafile_def('rp_shadowmap_cascade={0}'.format(rpdat.rp_shadowmap_cascade))
|
||||
assets.add_khafile_def('rp_shadowmap_cube={0}'.format(rpdat.rp_shadowmap_cube))
|
||||
|
||||
assets.add_khafile_def('rp_background={0}'.format(rpdat.rp_background))
|
||||
if rpdat.rp_background == 'World':
|
||||
|
|
|
@ -522,7 +522,7 @@ def make_forward_mobile(con_mesh):
|
|||
frag.add_uniform('float shadowsBias', '_lightShadowsBias')
|
||||
frag.write('if (lightPosition.w > 0.0) {')
|
||||
frag.write(' vec3 lPos = lightPosition.xyz / lightPosition.w;')
|
||||
frag.write(' const float texelSize = 1.0 / shadowmapSize.x;')
|
||||
frag.write(' const float texelSize = 1.0 / shadowmapSizeCube.x;')
|
||||
frag.write(' visibility = 0.0;')
|
||||
frag.write(' visibility += float(texture(shadowMap0, lPos.xy).r + shadowsBias > lPos.z);')
|
||||
frag.write(' visibility += float(texture(shadowMap0, lPos.xy + vec2(texelSize, 0.0)).r + shadowsBias > lPos.z) * 0.5;')
|
||||
|
|
|
@ -43,11 +43,7 @@ def get_rpasses(material):
|
|||
if rpdat.rp_renderer == 'Forward' and rpdat.rp_depthprepass and not material.arm_blending and not material.arm_particle_flag:
|
||||
ar.append('depth')
|
||||
|
||||
shadows_enabled = False
|
||||
if rpdat.rp_shadowmap != 'Off':
|
||||
shadows_enabled = True
|
||||
|
||||
if material.arm_cast_shadow and shadows_enabled and ('mesh' in ar or 'translucent' in ar):
|
||||
if material.arm_cast_shadow and rpdat.rp_shadows and ('mesh' in ar or 'translucent' in ar):
|
||||
ar.append('shadowmap')
|
||||
|
||||
return ar
|
||||
|
|
|
@ -11,7 +11,9 @@ def update_preset(self, context):
|
|||
if self.rp_preset == 'Desktop':
|
||||
rpdat.rp_renderer = 'Deferred'
|
||||
rpdat.arm_material_model = 'Full'
|
||||
rpdat.rp_shadowmap = '1024'
|
||||
rpdat.rp_shadows = True
|
||||
rpdat.rp_shadowmap_cube = '512'
|
||||
rpdat.rp_shadowmap_cascade = '1024'
|
||||
rpdat.rp_shadowmap_cascades = '4'
|
||||
rpdat.rp_translucency_state = 'Auto'
|
||||
rpdat.rp_overlays_state = 'Auto'
|
||||
|
@ -44,7 +46,9 @@ def update_preset(self, context):
|
|||
rpdat.rp_renderer = 'Forward'
|
||||
rpdat.rp_depthprepass = False
|
||||
rpdat.arm_material_model = 'Mobile'
|
||||
rpdat.rp_shadowmap = '1024'
|
||||
rpdat.rp_shadows = True
|
||||
rpdat.rp_shadowmap_cube = '256'
|
||||
rpdat.rp_shadowmap_cascade = '1024'
|
||||
rpdat.rp_shadowmap_cascades = '1'
|
||||
rpdat.rp_translucency_state = 'Off'
|
||||
rpdat.rp_overlays_state = 'Off'
|
||||
|
@ -77,7 +81,9 @@ def update_preset(self, context):
|
|||
rpdat.rp_renderer = 'Forward'
|
||||
rpdat.rp_depthprepass = False
|
||||
rpdat.arm_material_model = 'Mobile'
|
||||
rpdat.rp_shadowmap = '1024'
|
||||
rpdat.rp_shadows = True
|
||||
rpdat.rp_shadowmap_cube = '256'
|
||||
rpdat.rp_shadowmap_cascade = '1024'
|
||||
rpdat.rp_shadowmap_cascades = '1'
|
||||
rpdat.rp_translucency_state = 'Off'
|
||||
rpdat.rp_overlays_state = 'Off'
|
||||
|
@ -108,7 +114,9 @@ def update_preset(self, context):
|
|||
rpdat.arm_shadows_cubemap = False
|
||||
elif self.rp_preset == 'Max':
|
||||
rpdat.rp_renderer = 'Deferred'
|
||||
rpdat.rp_shadowmap = '8192'
|
||||
rpdat.rp_shadows = True
|
||||
rpdat.rp_shadowmap_cube = '2048'
|
||||
rpdat.rp_shadowmap_cascade = '4096'
|
||||
rpdat.rp_shadowmap_cascades = '4'
|
||||
rpdat.rp_translucency_state = 'Auto'
|
||||
rpdat.rp_overlays_state = 'Auto'
|
||||
|
@ -147,7 +155,9 @@ def update_preset(self, context):
|
|||
rpdat.rp_renderer = 'Forward'
|
||||
rpdat.rp_depthprepass = False
|
||||
rpdat.arm_material_model = 'Solid'
|
||||
rpdat.rp_shadowmap = 'Off'
|
||||
rpdat.rp_shadows = False
|
||||
rpdat.rp_shadowmap_cube = '512'
|
||||
rpdat.rp_shadowmap_cascade = '1024'
|
||||
rpdat.rp_shadowmap_cascades = '1'
|
||||
rpdat.rp_translucency_state = 'Off'
|
||||
rpdat.rp_overlays_state = 'Off'
|
||||
|
@ -270,19 +280,24 @@ class ArmRPListItem(bpy.types.PropertyGroup):
|
|||
arm_radiance_sky = BoolProperty(name="Sky Radiance", default=True, update=assets.invalidate_shader_cache)
|
||||
rp_autoexposure = BoolProperty(name="Auto Exposure", description="Adjust exposure based on luminance", default=False, update=update_renderpath)
|
||||
rp_compositornodes = BoolProperty(name="Compositor", description="Draw compositor nodes", default=True, update=update_renderpath)
|
||||
rp_shadowmap = EnumProperty(
|
||||
items=[('Off', 'Off', 'Off'),
|
||||
rp_shadows = BoolProperty(name="Shadows", description="Enable shadow casting", default=True, update=update_renderpath)
|
||||
rp_shadowmap_cube = EnumProperty(
|
||||
items=[('256', '256', '256'),
|
||||
('512', '512', '512'),
|
||||
('1024', '1024', '1024'),
|
||||
('2048', '2048', '2048'),
|
||||
('4096', '4096', '4096'),
|
||||
('8192', '8192', '8192'),
|
||||
('16384', '16384', '16384'),],
|
||||
name="Shadow Map", description="Shadow map resolution", default='1024', update=update_renderpath)
|
||||
('4096', '4096', '4096'),],
|
||||
name="Cube Size", description="Cube map resolution", default='512', update=update_renderpath)
|
||||
rp_shadowmap_cascade = EnumProperty(
|
||||
items=[('256', '256', '256'),
|
||||
('512', '512', '512'),
|
||||
('1024', '1024', '1024'),
|
||||
('2048', '2048', '2048'),
|
||||
('4096', '4096', '4096'),],
|
||||
name="Cascade Size", description="Shadow map resolution", default='1024', update=update_renderpath)
|
||||
rp_shadowmap_cascades = EnumProperty(
|
||||
items=[('1', '1', '1'),
|
||||
('2', '2', '2'),
|
||||
# ('3', '3', '3'),
|
||||
('4', '4', '4')],
|
||||
name="Cascades", description="Shadow map cascades", default='4', update=udpate_shadowmap_cascades)
|
||||
arm_pcfsize = FloatProperty(name="PCF Size", description="Filter size", default=1.0)
|
||||
|
|
|
@ -783,11 +783,13 @@ class ArmRenderPathPanel(bpy.types.Panel):
|
|||
self.prop(row, rpdat, 'arm_culling')
|
||||
|
||||
|
||||
self.label(layout, text='Shadows')
|
||||
box = self.box(layout)
|
||||
self.prop(box, rpdat, 'rp_shadowmap')
|
||||
col = self.column(box, enabled=(rpdat.rp_shadowmap != 'Off'))
|
||||
self.prop(col, rpdat, 'rp_shadowmap_cascades')
|
||||
layout.separator()
|
||||
self.prop(layout, rpdat, "rp_shadows")
|
||||
box = self.box(layout, enabled=(rpdat.rp_shadows))
|
||||
self.prop(box, rpdat, 'rp_shadowmap_cube')
|
||||
self.prop(box, rpdat, 'rp_shadowmap_cascade')
|
||||
self.prop(box, rpdat, 'rp_shadowmap_cascades')
|
||||
col = box.column()
|
||||
col2 = self.column(col, enabled=(rpdat.rp_shadowmap_cascades != '1'))
|
||||
self.prop(col2, rpdat, 'arm_shadowmap_split')
|
||||
self.prop(col, rpdat, 'arm_shadowmap_bounds')
|
||||
|
|
|
@ -319,8 +319,10 @@ def write_config(resx, resy):
|
|||
output['window_msaa'] = int(rpdat.arm_samples_per_pixel)
|
||||
output['window_scale'] = 1.0
|
||||
output['rp_supersample'] = float(rpdat.rp_supersampling)
|
||||
rp_shadowmap = 0 if rpdat.rp_shadowmap == 'Off' else int(rpdat.rp_shadowmap)
|
||||
output['rp_shadowmap'] = rp_shadowmap
|
||||
rp_shadowmap_cube = int(rpdat.rp_shadowmap_cube) if rpdat.rp_shadows else 0
|
||||
output['rp_shadowmap_cube'] = rp_shadowmap_cube
|
||||
rp_shadowmap_cascade = int(rpdat.rp_shadowmap_cascade) if rpdat.rp_shadows else 0
|
||||
output['rp_shadowmap_cascade'] = rp_shadowmap_cascade
|
||||
output['rp_ssgi'] = rpdat.rp_ssgi != 'Off'
|
||||
output['rp_ssr'] = rpdat.rp_ssr != 'Off'
|
||||
output['rp_bloom'] = rpdat.rp_bloom != 'Off'
|
||||
|
@ -442,9 +444,8 @@ def write_indexhtml(w, h, is_publish):
|
|||
add_compiledglsl = ''
|
||||
def write_compiledglsl(defs):
|
||||
rpdat = arm.utils.get_rp()
|
||||
shadowmap_size = 0
|
||||
if rpdat.rp_shadowmap != 'Off':
|
||||
shadowmap_size = int(rpdat.rp_shadowmap)
|
||||
shadowmap_size = int(rpdat.rp_shadowmap_cascade) if rpdat.rp_shadows else 0
|
||||
shadowmap_size_cube = int(rpdat.rp_shadowmap_cube) if rpdat.rp_shadows else 0
|
||||
with open(arm.utils.build_dir() + '/compiled/Shaders/compiled.inc', 'w') as f:
|
||||
f.write(
|
||||
"""#ifndef _COMPILED_GLSL_
|
||||
|
@ -457,6 +458,7 @@ def write_compiledglsl(defs):
|
|||
f.write("""const float PI = 3.1415926535;
|
||||
const float PI2 = PI * 2.0;
|
||||
const vec2 shadowmapSize = vec2(""" + str(shadowmap_size) + """, """ + str(shadowmap_size) + """);
|
||||
const vec2 shadowmapSizeCube = vec2(""" + str(shadowmap_size_cube) + """, """ + str(shadowmap_size_cube) + """);
|
||||
const float shadowmapCubePcfSize = """ + str((round(rpdat.arm_pcfsize * 100) / 100) / 1000) + """;
|
||||
const int shadowmapCascades = """ + str(rpdat.rp_shadowmap_cascades) + """;
|
||||
""")
|
||||
|
|
Loading…
Reference in a new issue