forked from LeenkxTeam/LNXSDK
Update leenkx/blender/lnx/material/make_mesh.py
This commit is contained in:
parent
b7bbe40348
commit
dab9a38424
@ -557,7 +557,7 @@ def make_forward(con_mesh):
|
||||
frag.write('fragColor[0] = vec4(direct + indirect, packFloat2(occlusion, specular));')
|
||||
frag.write('fragColor[1] = vec4(n.xy, roughness, metallic);')
|
||||
if rpdat.rp_ss_refraction or rpdat.lnx_voxelgi_refract:
|
||||
frag.write(f'fragColor[2] = vec4(1.0, 1.0, 0.0, 1.0);')
|
||||
frag.write(f'fragColor[2] = vec4(1.0, 1.0, 0.0, 0.0);')
|
||||
|
||||
else:
|
||||
frag.add_out('vec4 fragColor[1]')
|
||||
@ -609,11 +609,40 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
|
||||
frag.write_attrib('float dotNV = max(dot(n, vVec), 0.0);')
|
||||
|
||||
sh = tese if tese is not None else vert
|
||||
sh.add_uniform('mat4 W', '_worldMatrix')
|
||||
sh.write_attrib('vec3 wposition = vec4(W * spos).xyz;')
|
||||
sh.add_out('vec3 eyeDir')
|
||||
sh.add_uniform('vec3 eye', '_cameraPosition')
|
||||
sh.write('eyeDir = eye - wposition;')
|
||||
if '_VoxelGI' in wrd.world_defs or '_VoxelShadow' in wrd.world_defs:
|
||||
if '_gbuffer2' in wrd.world_defs:
|
||||
if '_Veloc' in wrd.world_defs:
|
||||
if tese is None:
|
||||
vert.add_uniform('mat4 prevWVP', link='_prevWorldViewProjectionMatrix')
|
||||
vert.add_out('vec4 wvpposition')
|
||||
vert.add_out('vec4 prevwvpposition')
|
||||
vert.write('wvpposition = gl_Position;')
|
||||
if is_displacement:
|
||||
vert.add_uniform('mat4 invW', link='_inverseWorldMatrix')
|
||||
vert.write('prevwvpposition = prevWVP * (invW * vec4(wposition, 1.0));')
|
||||
else:
|
||||
vert.write('prevwvpposition = prevWVP * spos;')
|
||||
else:
|
||||
tese.add_out('vec4 wvpposition')
|
||||
tese.add_out('vec4 prevwvpposition')
|
||||
tese.write('wvpposition = gl_Position;')
|
||||
if is_displacement:
|
||||
tese.add_uniform('mat4 invW', link='_inverseWorldMatrix')
|
||||
tese.add_uniform('mat4 prevWVP', '_prevWorldViewProjectionMatrix')
|
||||
tese.write('prevwvpposition = prevWVP * (invW * vec4(wposition, 1.0));')
|
||||
else:
|
||||
vert.add_uniform('mat4 prevW', link='_prevWorldMatrix')
|
||||
vert.add_out('vec3 prevwposition')
|
||||
vert.write('prevwposition = vec4(prevW * spos).xyz;')
|
||||
tese.add_uniform('mat4 prevVP', '_prevViewProjectionMatrix')
|
||||
make_tess.interpolate(tese, 'prevwposition', 3)
|
||||
tese.write('prevwvpposition = prevVP * vec4(prevwposition, 1.0);')
|
||||
frag.write('vec2 posa = (wvpposition.xy / wvpposition.w) * 0.5 + 0.5;')
|
||||
frag.write('vec2 posb = (prevwvpposition.xy / prevwvpposition.w) * 0.5 + 0.5;')
|
||||
frag.write('vec2 velocity = -vec2(posa - posb);')
|
||||
|
||||
frag.add_include('std/light.glsl')
|
||||
is_shadows = '_ShadowMap' in wrd.world_defs
|
||||
@ -632,6 +661,7 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
|
||||
if '_Brdf' in wrd.world_defs:
|
||||
frag.add_uniform('sampler2D senvmapBrdf', link='$brdf.png')
|
||||
frag.write('vec2 envBRDF = texelFetch(senvmapBrdf, ivec2(vec2(dotNV, 1.0 - roughness) * 256.0), 0).xy;')
|
||||
frag.write('vec3 F = f0 * envBRDF.x + envBRDF.y;')
|
||||
|
||||
if '_Irr' in wrd.world_defs:
|
||||
frag.add_include('std/shirr.glsl')
|
||||
@ -657,12 +687,12 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
|
||||
frag.write('envl *= albedo;')
|
||||
|
||||
if '_Brdf' in wrd.world_defs:
|
||||
frag.write('envl.rgb *= 1.0 - (f0 * envBRDF.x + envBRDF.y);')
|
||||
frag.write('envl.rgb *= 1.0 - F;')
|
||||
if '_Rad' in wrd.world_defs:
|
||||
frag.write('envl += prefilteredColor * (f0 * envBRDF.x + envBRDF.y);')
|
||||
frag.write('envl += prefilteredColor * F;')
|
||||
elif '_EnvCol' in wrd.world_defs:
|
||||
frag.add_uniform('vec3 backgroundCol', link='_backgroundCol')
|
||||
frag.write('envl += backgroundCol * (f0 * envBRDF.x + envBRDF.y);')
|
||||
frag.write('envl += backgroundCol * F;')
|
||||
|
||||
frag.add_uniform('float envmapStrength', link='_envmapStrength')
|
||||
frag.write('envl *= envmapStrength * occlusion;')
|
||||
@ -671,22 +701,10 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
|
||||
frag.add_include('std/conetrace.glsl')
|
||||
frag.add_uniform('sampler3D voxels')
|
||||
frag.add_uniform('sampler3D voxelsSDF')
|
||||
frag.add_uniform('vec3 eye', '_cameraPosition')
|
||||
frag.add_uniform('float clipmaps[10 * voxelgiClipmapCount]', '_clipmaps')
|
||||
vert.add_out('vec4 wvpposition')
|
||||
vert.write('wvpposition = gl_Position;')
|
||||
frag.write('vec2 texCoord = (wvpposition.xy / wvpposition.w) * 0.5 + 0.5;')
|
||||
|
||||
if '_VoxelGI' in wrd.world_defs or '_VoxelShadow' in wrd.world_defs or '_VoxelRefract' in wrd.world_defs:
|
||||
frag.add_uniform('sampler2D gbuffer2', included=True)
|
||||
frag.write('vec2 velocity = -textureLod(gbuffer2, gl_FragCoord.xy, 0.0).rg;')
|
||||
|
||||
if '_VoxelAOvar' in wrd.world_defs:
|
||||
if parse_opacity:
|
||||
frag.write('envl *= 1.0 - traceAO(wposition, n, voxels, clipmaps);')
|
||||
else:
|
||||
frag.add_uniform("sampler2D voxels_ao");
|
||||
frag.write('envl *= textureLod(voxels_ao, texCoord, 0.0).rrr;')
|
||||
frag.write('envl *= (1.0 - traceAO(wposition, n, voxels, clipmaps));')
|
||||
|
||||
if '_VoxelGI' in wrd.world_defs:
|
||||
frag.write('vec3 indirect = vec3(0.0);')
|
||||
@ -694,18 +712,11 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
|
||||
frag.write('vec3 indirect = envl;')
|
||||
|
||||
if '_VoxelGI' in wrd.world_defs:
|
||||
if parse_opacity:
|
||||
frag.write('vec4 indirect_diffuse = traceDiffuse(wposition, n, voxels, clipmaps);')
|
||||
frag.write('indirect = (indirect_diffuse.rgb * albedo + envl.rgb * (1.0 - indirect_diffuse.a)) * voxelgiDiff;')
|
||||
frag.write('if (roughness < 1.0 && specular > 0.0) {')
|
||||
frag.write(' indirect += traceSpecular(wposition, n, voxels, voxelsSDF, vVec, roughness * roughness, clipmaps, gl_FragCoord.xy, velocity).rgb * specular * voxelgiRefl; }')
|
||||
else:
|
||||
frag.add_uniform("sampler2D voxels_diffuse")
|
||||
frag.add_uniform("sampler2D voxels_specular")
|
||||
frag.write("indirect = textureLod(voxels_diffuse, texCoord, 0.0).rgb * albedo * voxelgiDiff;")
|
||||
frag.write("if (roughness < 1.0 && specular > 0.0)")
|
||||
frag.write(" indirect += textureLod(voxels_specular, texCoord, 0.0).rgb * specular * voxelgiRefl;")
|
||||
|
||||
frag.write('vec4 diffuse_indirect = traceDiffuse(wposition, n, voxels, clipmaps);')
|
||||
frag.write('indirect = (diffuse_indirect.rgb * albedo * (1.0 - F) + envl * (1.0 - diffuse_indirect.a)) * voxelgiDiff;')
|
||||
frag.write('if (roughness < 1.0 && specular > 0.0) {')
|
||||
frag.write(' indirect += traceSpecular(wposition, n, voxels, voxelsSDF, vVec, roughness * roughness, clipmaps, gl_FragCoord.xy, velocity).rgb * F * voxelgiRefl;')
|
||||
frag.write('}')
|
||||
frag.write('vec3 direct = vec3(0.0);')
|
||||
|
||||
if '_Sun' in wrd.world_defs:
|
||||
@ -730,7 +741,6 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
|
||||
frag.write(f'svisibility = shadowTestCascade({shadowmap_sun}, {shadowmap_sun_tr}, eye, wposition + n * shadowsBias * 10, shadowsBias, true);')
|
||||
else:
|
||||
frag.write(f'svisibility = shadowTestCascade({shadowmap_sun}, {shadowmap_sun_tr}, eye, wposition + n * shadowsBias * 10, shadowsBias, false);')
|
||||
|
||||
else:
|
||||
if tese is not None:
|
||||
tese.add_out('vec4 lightPosition')
|
||||
@ -744,7 +754,7 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
|
||||
else:
|
||||
vert.add_out('vec4 lightPosition')
|
||||
vert.add_uniform('mat4 LWVP', '_biasLightWorldViewProjectionMatrixSun')
|
||||
vert.write('lightPosition = LWVP * lightPosition;')
|
||||
vert.write('lightPosition = LWVP * pos;')
|
||||
frag.write('vec3 lPos = lightPosition.xyz / lightPosition.w;')
|
||||
frag.write('const vec2 smSize = shadowmapSize;')
|
||||
if parse_opacity:
|
||||
@ -786,14 +796,13 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
|
||||
if '_Spot' in wrd.world_defs:
|
||||
frag.write(', true, spotData.x, spotData.y, spotDir, spotData.zw, spotRight')
|
||||
if '_VoxelShadow' in wrd.world_defs:
|
||||
frag.write(', voxels, voxelsSDF, clipmaps')
|
||||
frag.write(', voxels, voxelsSDF, clipmaps, velocity')
|
||||
if '_MicroShadowing' in wrd.world_defs:
|
||||
frag.write(', occlusion')
|
||||
if '_SSRS' in wrd.world_defs:
|
||||
frag.add_uniform('sampler2D gbufferD', top=True)
|
||||
frag.add_uniform('mat4 invVP', '_inverseViewProjectionMatrix')
|
||||
frag.add_uniform('vec3 eye', '_cameraPosition')
|
||||
frag.write(', gbufferD, invVP, eye')
|
||||
frag.write(', wposition.z, invVP, eye')
|
||||
frag.write(');')
|
||||
|
||||
if '_Clusters' in wrd.world_defs:
|
||||
@ -806,7 +815,7 @@ def make_forward_base(con_mesh, parse_opacity=False, transluc_pass=False):
|
||||
|
||||
if '_VoxelRefract' in wrd.world_defs and parse_opacity:
|
||||
frag.write('if (opacity < 1.0) {')
|
||||
frag.write(' vec3 refraction = traceRefraction(wposition, n, voxels, voxelsSDF, vVec, ior, roughness, clipmaps, gl_FragCoord.xy, velocity, opacity).rgb * voxelgiRefr;')
|
||||
frag.write(' vec3 refraction = traceRefraction(wposition, n, voxels, voxelsSDF, vVec, ior, roughness * roughness, clipmaps, gl_FragCoord.xy, velocity, opacity).rgb * (1.0 - F) * voxelgiRefr;')
|
||||
frag.write(' indirect = mix(refraction, indirect, opacity);')
|
||||
frag.write(' direct = mix(refraction, direct, opacity);')
|
||||
frag.write('}')
|
||||
@ -822,4 +831,4 @@ def _write_material_attribs_default(frag: shader.Shader, parse_opacity: bool):
|
||||
frag.write('vec3 emissionCol;')
|
||||
if parse_opacity:
|
||||
frag.write('float opacity;')
|
||||
frag.write('float ior;')
|
||||
frag.write('float ior = 1.45;')
|
||||
|
Loading…
x
Reference in New Issue
Block a user