Uniform fixes

This commit is contained in:
luboslenco 2018-12-15 19:03:11 +01:00
parent 7dcb443060
commit 9c9fd0881e
8 changed files with 151 additions and 97 deletions

View file

@ -105,8 +105,18 @@ uniform vec2 cameraPlane;
#endif
#ifdef _ShadowMap
#ifdef _SinglePoint
#ifdef _Spot
//!uniform sampler2DShadow shadowMapSpot[1];
//!uniform mat4 LWVPSpot0;
#else
//!uniform samplerCubeShadow shadowMapPoint[1];
//!uniform vec2 lightProj;
#endif
#endif
#ifdef _Clusters
//!uniform samplerCubeShadow shadowMapPoint[4];
//!uniform vec2 lightProj;
#ifdef _Spot
//!uniform sampler2DShadow shadowMapSpot[4];
//!uniform mat4 LWVPSpot0;
@ -115,6 +125,7 @@ uniform vec2 cameraPlane;
//!uniform mat4 LWVPSpot3;
#endif
#endif
#endif
#ifdef _Sun
uniform vec3 sunDir;

View file

@ -44,8 +44,18 @@ uniform vec2 cameraPlane;
#endif
#ifdef _ShadowMap
#ifdef _SinglePoint
#ifdef _Spot
//!uniform sampler2DShadow shadowMapSpot[1];
//!uniform mat4 LWVPSpot0;
#else
//!uniform samplerCubeShadow shadowMapPoint[1];
//!uniform vec2 lightProj;
#endif
#endif
#ifdef _Clusters
//!uniform samplerCubeShadow shadowMapPoint[4];
//!uniform vec2 lightProj;
#ifdef _Spot
//!uniform sampler2DShadow shadowMapSpot[4];
//!uniform mat4 LWVPSpot0;
@ -54,6 +64,7 @@ uniform vec2 cameraPlane;
//!uniform mat4 LWVPSpot3;
#endif
#endif
#endif
#ifdef _Sun
uniform vec3 sunDir;

View file

@ -10,20 +10,26 @@
#ifdef _ShadowMap
#ifdef _SinglePoint
const int shadowMapCount = 1;
#else
const int shadowMapCount = 4;
#endif
uniform vec2 lightProj;
uniform samplerCubeShadow shadowMapPoint[shadowMapCount];
#ifdef _Spot
uniform sampler2DShadow shadowMapSpot[shadowMapCount];
uniform sampler2DShadow shadowMapSpot[1];
uniform mat4 LWVPSpot0;
#else
uniform samplerCubeShadow shadowMapPoint[1];
uniform vec2 lightProj;
#endif
#endif
#ifdef _Clusters
uniform samplerCubeShadow shadowMapPoint[4];
uniform vec2 lightProj;
#ifdef _Spot
uniform sampler2DShadow shadowMapSpot[4];
uniform mat4 LWVPSpot0;
uniform mat4 LWVPSpot1;
uniform mat4 LWVPSpot2;
uniform mat4 LWVPSpot3;
#endif
#endif
#endif
vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, const vec3 lp, const vec3 lightCol,
const vec3 albedo, const float rough, const float spec, const vec3 f0
@ -55,27 +61,28 @@ vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, co
direct *= smoothstep(spotB, spotA, spotEffect);
}
#ifdef _ShadowMap
#ifdef _SinglePoint
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias, shadowmapSize);
#else
if (index == 0) {
#ifdef _SinglePoint
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 1) {
vec4 lPos = LWVPSpot1 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[1], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 2) {
vec4 lPos = LWVPSpot2 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[2], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 3) {
vec4 lPos = LWVPSpot3 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[3], lPos.xyz / lPos.w, bias, shadowmapSize);
}
#endif
#endif
#ifdef _Clusters
if (index == 0) {
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 1) {
vec4 lPos = LWVPSpot1 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[1], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 2) {
vec4 lPos = LWVPSpot2 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[2], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 3) {
vec4 lPos = LWVPSpot3 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[3], lPos.xyz / lPos.w, bias, shadowmapSize);
}
#endif
#endif
return direct;
}
@ -104,14 +111,15 @@ vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, co
// #endif
#ifdef _ShadowMap
#ifdef _SinglePoint
direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
#else
if (index == 0) direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
else if (index == 1) direct *= PCFCube(shadowMapPoint[1], ld, -l, bias, lightProj, n);
else if (index == 2) direct *= PCFCube(shadowMapPoint[2], ld, -l, bias, lightProj, n);
else if (index == 3) direct *= PCFCube(shadowMapPoint[3], ld, -l, bias, lightProj, n);
#endif
#ifdef _SinglePoint
direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
#endif
#ifdef _Clusters
if (index == 0) direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
else if (index == 1) direct *= PCFCube(shadowMapPoint[1], ld, -l, bias, lightProj, n);
else if (index == 2) direct *= PCFCube(shadowMapPoint[2], ld, -l, bias, lightProj, n);
else if (index == 3) direct *= PCFCube(shadowMapPoint[3], ld, -l, bias, lightProj, n);
#endif
#endif
return direct;

View file

@ -8,8 +8,18 @@
#endif
#ifdef _ShadowMap
#ifdef _SinglePoint
#ifdef _Spot
uniform sampler2DShadow shadowMapSpot[1];
uniform mat4 LWVPSpot0;
#else
uniform samplerCubeShadow shadowMapPoint[1];
uniform vec2 lightProj;
#endif
#endif
#ifdef _Clusters
uniform samplerCubeShadow shadowMapPoint[4];
uniform vec2 lightProj;
#ifdef _Spot
uniform sampler2DShadow shadowMapSpot[4];
uniform mat4 LWVPSpot0;
@ -18,6 +28,7 @@
uniform mat4 LWVPSpot3;
#endif
#endif
#endif
vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, const vec3 lp, const vec3 lightCol,
const vec3 albedo, const float rough, const float spec, const vec3 f0
@ -49,32 +60,43 @@ vec3 sampleLight(const vec3 p, const vec3 n, const vec3 v, const float dotNV, co
direct *= smoothstep(spotB, spotA, spotEffect);
}
#ifdef _ShadowMap
if (index == 0) {
#ifdef _SinglePoint
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 1) {
vec4 lPos = LWVPSpot1 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[1], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 2) {
vec4 lPos = LWVPSpot2 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[2], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 3) {
vec4 lPos = LWVPSpot3 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[3], lPos.xyz / lPos.w, bias, shadowmapSize);
}
#endif
#ifdef _Clusters
if (index == 0) {
vec4 lPos = LWVPSpot0 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[0], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 1) {
vec4 lPos = LWVPSpot1 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[1], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 2) {
vec4 lPos = LWVPSpot2 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[2], lPos.xyz / lPos.w, bias, shadowmapSize);
}
else if (index == 3) {
vec4 lPos = LWVPSpot3 * vec4(p + n * bias * 10, 1.0);
direct *= shadowTest(shadowMapSpot[3], lPos.xyz / lPos.w, bias, shadowmapSize);
}
#endif
#endif
return direct;
}
#endif
#ifdef _ShadowMap
if (index == 0) direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
else if (index == 1) direct *= PCFCube(shadowMapPoint[1], ld, -l, bias, lightProj, n);
else if (index == 2) direct *= PCFCube(shadowMapPoint[2], ld, -l, bias, lightProj, n);
else if (index == 3) direct *= PCFCube(shadowMapPoint[3], ld, -l, bias, lightProj, n);
#ifdef _SinglePoint
direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
#endif
#ifdef _Clusters
if (index == 0) direct *= PCFCube(shadowMapPoint[0], ld, -l, bias, lightProj, n);
else if (index == 1) direct *= PCFCube(shadowMapPoint[1], ld, -l, bias, lightProj, n);
else if (index == 2) direct *= PCFCube(shadowMapPoint[2], ld, -l, bias, lightProj, n);
else if (index == 3) direct *= PCFCube(shadowMapPoint[3], ld, -l, bias, lightProj, n);
#endif
#endif
return direct;

View file

@ -152,12 +152,13 @@ def build():
if rpdat.rp_renderer == 'Deferred' and not rpdat.rp_compositornodes:
assets.add_shader_pass('copy_pass')
if rpdat.rp_renderer == 'Forward' and not rpdat.rp_compositornodes:
assets.add_shader_pass('copy_pass')
if rpdat.rp_render_to_texture:
assets.add_khafile_def('rp_render_to_texture')
if rpdat.rp_renderer == 'Forward' and not rpdat.rp_compositornodes:
assets.add_shader_pass('copy_pass')
if rpdat.rp_compositornodes:
assets.add_khafile_def('rp_compositornodes')
compo_depth = False
@ -225,6 +226,30 @@ def build():
if rpdat.rp_supersampling == '4':
assets.add_shader_pass('supersample_resolve')
assets.add_khafile_def('rp_ssgi={0}'.format(rpdat.rp_ssgi))
if rpdat.rp_ssgi != 'Off':
wrd.world_defs += '_SSAO'
if rpdat.rp_ssgi == 'SSAO':
assets.add_shader_pass('ssao_pass')
assets.add_shader_pass('blur_edge_pass')
else:
assets.add_shader_pass('ssgi_pass')
assets.add_shader_pass('blur_edge_pass')
if rpdat.arm_ssgi_half_res:
assets.add_khafile_def('rp_ssgi_half')
if rpdat.rp_bloom:
assets.add_khafile_def('rp_bloom')
assets.add_shader_pass('bloom_pass')
assets.add_shader_pass('blur_gaus_pass')
if rpdat.rp_ssr:
assets.add_khafile_def('rp_ssr')
assets.add_shader_pass('ssr_pass')
assets.add_shader_pass('blur_adaptive_pass')
if rpdat.arm_ssr_half_res:
assets.add_khafile_def('rp_ssr_half')
if rpdat.rp_overlays:
assets.add_khafile_def('rp_overlays')
@ -257,18 +282,6 @@ def build():
if rpdat.arm_rp_resolution == 'Custom':
assets.add_khafile_def('rp_resolution_filter={0}'.format(rpdat.arm_rp_resolution_filter))
assets.add_khafile_def('rp_ssgi={0}'.format(rpdat.rp_ssgi))
if rpdat.rp_ssgi != 'Off':
wrd.world_defs += '_SSAO'
if rpdat.rp_ssgi == 'SSAO':
assets.add_shader_pass('ssao_pass')
assets.add_shader_pass('blur_edge_pass')
else:
assets.add_shader_pass('ssgi_pass')
assets.add_shader_pass('blur_edge_pass')
if rpdat.arm_ssgi_half_res:
assets.add_khafile_def('rp_ssgi_half')
if rpdat.rp_renderer == 'Deferred':
if rpdat.arm_material_model == 'Full':
assets.add_shader_pass('deferred_light')
@ -302,23 +315,11 @@ def build():
if rpdat.rp_blending:
assets.add_khafile_def('rp_blending')
if rpdat.rp_bloom:
assets.add_khafile_def('rp_bloom')
assets.add_shader_pass('bloom_pass')
assets.add_shader_pass('blur_gaus_pass')
if rpdat.rp_sss:
assets.add_khafile_def('rp_sss')
wrd.world_defs += '_SSS'
assets.add_shader_pass('sss_pass')
if rpdat.rp_ssr:
assets.add_khafile_def('rp_ssr')
assets.add_shader_pass('ssr_pass')
assets.add_shader_pass('blur_adaptive_pass')
if rpdat.arm_ssr_half_res:
assets.add_khafile_def('rp_ssr_half')
if (rpdat.rp_ssr and rpdat.arm_ssr_half_res) or (rpdat.rp_ssgi != 'Off' and rpdat.arm_ssgi_half_res):
assets.add_shader_pass('downsample_depth')

View file

@ -348,10 +348,16 @@ def make_forward_mobile(con_mesh):
vert.write('lightPosition = LWVP * spos;')
frag.add_uniform('sampler2DShadow shadowMap')
frag.add_uniform('float shadowsBias', '_sunShadowsBias')
frag.write('if (lightPosition.w > 0.0) {')
frag.write(' vec3 lPos = lightPosition.xyz / lightPosition.w;')
frag.write(' svisibility = texture(shadowMap, vec3(lPos.xy, lPos.z - shadowsBias)).r;')
frag.write('}')
if '_CSM' in wrd.world_defs:
frag.add_include('std/shadows.glsl')
frag.add_uniform('vec4 casData[shadowmapCascades * 4 + 4]', '_cascadeData', included=True)
frag.add_uniform('vec3 eye', '_cameraPosition')
frag.write('svisibility = shadowTestCascade(shadowMap, eye, wposition + n * shadowsBias * 10, shadowsBias, shadowmapSize * vec2(shadowmapCascades, 1.0));')
else:
frag.write('if (lightPosition.w > 0.0) {')
frag.write(' vec3 lPos = lightPosition.xyz / lightPosition.w;')
frag.write(' svisibility = texture(shadowMap, vec3(lPos.xy, lPos.z - shadowsBias)).r;')
frag.write('}')
frag.write('direct += basecol * sdotNL * sunCol * svisibility;')
if '_SinglePoint' in wrd.world_defs:
@ -545,16 +551,10 @@ def make_forward_base(con_mesh, parse_opacity=False):
frag.add_uniform('float shadowsBias', '_sunShadowsBias')
frag.write('if (receiveShadow) {')
if '_CSM' in wrd.world_defs:
frag.add_include('std/shadows.glsl')
frag.add_uniform('vec4 casData[shadowmapCascades * 4 + 4]', '_cascadeData', included=True)
frag.add_uniform('vec3 eye', '_cameraPosition')
frag.write('vec2 smSize;')
frag.write('vec3 lPos;')
frag.write('int casi;')
frag.write('int casindex;')
frag.write('mat4 LWVP = getCascadeMat(distance(eye, wposition), casi, casindex);')
frag.write('vec4 lightPosition = LWVP * vec4(wposition, 1.0);')
frag.write('lPos = lightPosition.xyz / lightPosition.w;')
frag.write('smSize = shadowmapSize * vec2(shadowmapCascades, 1.0);')
frag.write('svisibility = shadowTestCascade(shadowMap, eye, wposition + n * shadowsBias * 10, shadowsBias, shadowmapSize * vec2(shadowmapCascades, 1.0));')
else:
if tese != None:
tese.add_out('vec4 lightPosition')
@ -571,7 +571,7 @@ def make_forward_base(con_mesh, parse_opacity=False):
vert.write('lightPosition = LWVP * spos;')
frag.write('vec3 lPos = lightPosition.xyz / lightPosition.w;')
frag.write('const vec2 smSize = shadowmapSize;')
frag.write('svisibility = PCF(shadowMap, lPos.xy, lPos.z - shadowsBias, smSize);')
frag.write('svisibility = PCF(shadowMap, lPos.xy, lPos.z - shadowsBias, smSize);')
frag.write('}') # receiveShadow
# is_shadows
frag.write('direct += (lambertDiffuseBRDF(albedo, sdotNL) + specularBRDF(f0, roughness, sdotNL, sdotNH, dotNV, sdotVH) * specular) * sunCol * svisibility;')

View file

@ -121,7 +121,7 @@ def init_properties():
bpy.types.World.arm_sound_quality = FloatProperty(name="Sound Quality", default=0.9, min=0.0, max=1.0, subtype='FACTOR', update=invalidate_compiler_cache)
bpy.types.World.arm_minimize = BoolProperty(name="Minimize Data", description="Export scene data in binary", default=True, update=assets.invalidate_compiled_data)
bpy.types.World.arm_minify_js = BoolProperty(name="Minify JS", description="Minimize JavaScript output when publishing", default=True)
bpy.types.World.arm_optimize_mesh = BoolProperty(name="Optimize Meshes", description="Export more efficient geometry indices, can prolong build times", default=False, update=assets.invalidate_mesh_data)
bpy.types.World.arm_optimize_data = BoolProperty(name="Optimize Data", description="Export more efficient geometry and shader data, prolongs build times", default=True, update=assets.invalidate_compiled_data)
bpy.types.World.arm_deinterleaved_buffers = BoolProperty(name="Deinterleaved Buffers", description="Use deinterleaved vertex buffers", default=False, update=invalidate_compiler_cache)
bpy.types.World.arm_export_tangents = BoolProperty(name="Export Tangents", description="Precompute tangents for normal mapping, otherwise computed in shader", default=True, update=assets.invalidate_compiled_data)
bpy.types.World.arm_batch_meshes = BoolProperty(name="Batch Meshes", description="Group meshes by materials to speed up rendering", default=False, update=invalidate_compiler_cache)

View file

@ -337,6 +337,10 @@ class ArmoryExporterPanel(bpy.types.Panel):
col.prop(wrd, 'arm_project_version')
col.prop(wrd, 'arm_project_bundle')
col.prop(wrd, 'arm_project_icon')
col.prop(wrd, 'arm_dce')
col.prop(wrd, 'arm_compiler_inline')
col.prop(wrd, 'arm_minify_js')
col.prop(wrd, 'arm_optimize_data')
class ArmoryProjectPanel(bpy.types.Panel):
bl_label = "Armory Project"
@ -359,21 +363,18 @@ class ArmoryProjectPanel(bpy.types.Panel):
row = box.row()
col = row.column()
col.prop(wrd, 'arm_debug_console')
col.prop(wrd, 'arm_dce')
col = row.column()
col.prop(wrd, 'arm_cache_build')
col.prop(wrd, 'arm_minify_js')
col.prop(wrd, 'arm_cache_build')
row = box.row()
col = row.column()
col.prop(wrd, 'arm_stream_scene')
col.prop(wrd, 'arm_batch_meshes')
col.prop(wrd, 'arm_batch_materials')
col.prop(wrd, 'arm_compiler_inline')
col.prop(wrd, 'arm_write_config')
col = row.column()
col.prop(wrd, 'arm_minimize')
col.prop(wrd, 'arm_optimize_mesh')
col.prop(wrd, 'arm_deinterleaved_buffers')
col.prop(wrd, 'arm_export_tangents')
col.prop(wrd, 'arm_loadscreen')