forked from LeenkxTeam/LNXSDK
Consolidate and update
This commit is contained in:
@ -3,12 +3,14 @@ import bpy
|
||||
import lnx.material.cycles as cycles
|
||||
import lnx.material.mat_state as mat_state
|
||||
import lnx.material.make_finalize as make_finalize
|
||||
import lnx.material.make_mesh as make_mesh
|
||||
import lnx.utils
|
||||
|
||||
if lnx.is_reload(__name__):
|
||||
cycles = lnx.reload_module(cycles)
|
||||
mat_state = lnx.reload_module(mat_state)
|
||||
make_finalize = lnx.reload_module(make_finalize)
|
||||
make_mesh = lnx.reload_module(make_mesh)
|
||||
lnx.utils = lnx.reload_module(lnx.utils)
|
||||
else:
|
||||
lnx.enable_reload(__name__)
|
||||
@ -64,14 +66,8 @@ def make(context_id):
|
||||
frag.write_attrib(' if (abs(mpos.z) > 1.0) discard;')
|
||||
frag.write_attrib(' vec2 texCoord = mpos.xy * 0.5 + 0.5;')
|
||||
|
||||
frag.write('vec3 basecol;')
|
||||
frag.write('float roughness;')
|
||||
frag.write('float metallic;')
|
||||
frag.write('float occlusion;')
|
||||
frag.write('float specular;')
|
||||
frag.write('float opacity;')
|
||||
frag.write('vec3 emissionCol;') # Declared to prevent compiler errors, but decals currently don't output any emission
|
||||
frag.write('float ior;')
|
||||
# Declared to prevent compiler errors, but decals currently don't output any emission
|
||||
make_mesh._write_material_attribs_default(frag, parse_opacity=True)
|
||||
cycles.parse(mat_state.nodes, con_decal, vert, frag, geom, tesc, tese)
|
||||
|
||||
frag.write('n /= (abs(n.x) + abs(n.y) + abs(n.z));')
|
||||
|
||||
@ -241,8 +241,7 @@ def make(context_id, rpasses, shadowmap=False, shadowmap_transparent=False):
|
||||
vert.add_out('vec4 wvpposition')
|
||||
vert.write('wvpposition = gl_Position;')
|
||||
frag.write('float depth = (wvpposition.z / wvpposition.w) * 0.5 + 0.5;')
|
||||
frag.write('vec3 color = basecol;')
|
||||
frag.write('color *= 1.0 - opacity;')
|
||||
frag.write('vec3 color = mix(vec3(1.0), basecol, opacity);')
|
||||
frag.write('fragColor = vec4(color, depth);')
|
||||
|
||||
if parse_opacity and not shadowmap_transparent:
|
||||
|
||||
@ -398,11 +398,14 @@ def make_forward_mobile(con_mesh):
|
||||
return
|
||||
|
||||
is_shadows = '_ShadowMap' in wrd.world_defs
|
||||
is_transparent_shadows = '_ShadowMapTransparent' in wrd.world_defs
|
||||
is_shadows_atlas = '_ShadowMapAtlas' in wrd.world_defs
|
||||
shadowmap_sun = 'shadowMap'
|
||||
shadowmap_sun_tr = 'shadowMapTransparent'
|
||||
if is_shadows_atlas:
|
||||
is_single_atlas = '_SingleAtlas' in wrd.world_defs
|
||||
shadowmap_sun = 'shadowMapAtlasSun' if not is_single_atlas else 'shadowMapAtlas'
|
||||
shadowmap_sun_tr = 'shadowMapAtlasSunTransparent' if not is_single_atlas else 'shadowMapAtlasTransparent'
|
||||
frag.add_uniform('vec2 smSizeUniform', '_shadowMapSize', included=True)
|
||||
frag.write('vec3 direct = vec3(0.0);')
|
||||
|
||||
@ -417,6 +420,8 @@ def make_forward_mobile(con_mesh):
|
||||
vert.write('lightPosition = LWVP * spos;')
|
||||
frag.add_uniform('bool receiveShadow')
|
||||
frag.add_uniform(f'sampler2DShadow {shadowmap_sun}')
|
||||
if is_transparent_shadows:
|
||||
frag.add_uniform(f'sampler2D {shadowmap_sun_tr}')
|
||||
frag.add_uniform('float shadowsBias', '_sunShadowsBias')
|
||||
|
||||
frag.write('if (receiveShadow) {')
|
||||
@ -427,14 +432,20 @@ def make_forward_mobile(con_mesh):
|
||||
if is_shadows_atlas:
|
||||
frag.add_uniform('vec4 tileBoundsSunArray[maxLights * shadowmapCascades]', '_tileBoundsSunArray', included=True)
|
||||
frag.write('tileBounds = tileBoundsSunArray[0];')
|
||||
frag.write(f'svisibility = shadowTestCascade({shadowmap_sun}, eye, wposition + n * shadowsBias * 10, shadowsBias, opacity != 1.0);')
|
||||
frag.write(f'svisibility = shadowTestCascade({shadowmap_sun},')
|
||||
if is_transparent_shadows:
|
||||
frag.write(f'{shadowmap_sun_tr},')
|
||||
frag.write('eye, wposition + n * shadowsBias * 10, shadowsBias')
|
||||
if is_transparent_shadows:
|
||||
frag.write(', opacity != 1.0')
|
||||
frag.write(');')
|
||||
else:
|
||||
frag.write('if (lightPosition.w > 0.0) {')
|
||||
frag.write(' vec3 lPos = lightPosition.xyz / lightPosition.w;')
|
||||
if '_Legacy' in wrd.world_defs:
|
||||
frag.write(f' svisibility = float(texture({shadowmap_sun}, vec2(lPos.xy)).r > lPos.z - shadowsBias, opacity != 1.0);')
|
||||
frag.write(f' svisibility = vec3(float(texture({shadowmap_sun}, vec2(lPos.xy)).r > lPos.z - shadowsBias));')
|
||||
else:
|
||||
frag.write(f' svisibility = texture({shadowmap_sun}, vec3(lPos.xy, lPos.z - shadowsBias), opacity != 1.0).r;')
|
||||
frag.write(f' svisibility = vec3(texture({shadowmap_sun}, vec3(lPos.xy, lPos.z - shadowsBias)).r);')
|
||||
frag.write('}')
|
||||
frag.write('}') # receiveShadow
|
||||
frag.write('direct += basecol * sdotNL * sunCol * svisibility;')
|
||||
|
||||
@ -80,9 +80,6 @@ def write(vert, particle_info=None, shadowmap=False):
|
||||
|
||||
vert.add_const('float', 'P_NORMAL_FACTOR', str(normal_factor))
|
||||
|
||||
if (shadowmap and normal_factor != 0.0):
|
||||
vert.add_out('vec3 N')
|
||||
|
||||
|
||||
if ramp_el_len != 0:
|
||||
vert.add_const('float', 'P_SIZE_OVER_TIME_FACTOR', str(size_over_time_factor))
|
||||
@ -156,6 +153,7 @@ def write(vert, particle_info=None, shadowmap=False):
|
||||
vert.write('p_velocity.z += (fhash(gl_InstanceID + pd_random + 2 * pd[0][3]) * 2.0 / pd_size - 1.0 / pd_size) * pd[1][3];')
|
||||
|
||||
if normal_factor != 0.0:
|
||||
vert.add_uniform('mat3 N', '_normalMatrix')
|
||||
vert.write('if (P_NORMAL_FACTOR != 0.0) {')
|
||||
vert.write(' vec3 local_normal_dir = normalize(ipos);')
|
||||
vert.write(' vec3 world_emitter_normal = normalize(N * local_normal_dir);')
|
||||
|
||||
Reference in New Issue
Block a user