This commit is contained in:
Gorochu
2026-06-24 00:05:37 -07:00
parent 6db83e559b
commit 38151eb233
30 changed files with 1129 additions and 373 deletions

View File

@ -328,12 +328,13 @@ def parse_tex_sky(node: bpy.types.ShaderNodeTexSky, out_socket: bpy.types.NodeSo
state.world.world_defs += '_EnvSky'
if node.sky_type == 'PREETHAM' or node.sky_type == 'HOSEK_WILKIE':
if node.sky_type == 'PREETHAM':
log.info('Info: Preetham sky model is not supported, using Hosek Wilkie sky model instead')
return parse_sky_hosekwilkie(node, state)
elif node.sky_type == 'NISHITA':
return parse_sky_nishita(node, state)
elif node.sky_type == 'NISHITA' or node.sky_type == 'SINGLE_SCATTERING':
return parse_sky_single_scattering(node, state)
elif node.sky_type == 'MULTIPLE_SCATTERING':
return parse_sky_multiple_scattering(node, state)
else:
log.error(f'Unsupported sky model: {node.sky_type}!')
@ -397,18 +398,20 @@ def parse_sky_hosekwilkie(node: bpy.types.ShaderNodeTexSky, state: ParserState)
return 'Z * hosekWilkie(cos_theta, gamma_val, cos_gamma) * envmapStrength;'
def parse_sky_nishita(node: bpy.types.ShaderNodeTexSky, state: ParserState) -> vec3str:
def parse_sky_single_scattering(node: bpy.types.ShaderNodeTexSky, state: ParserState) -> vec3str:
curshader = state.curshader
curshader.add_include('std/sky.glsl')
curshader.add_uniform('vec3 sunDir', link='_sunDirection')
curshader.add_uniform('sampler2D nishitaLUT', link='_nishitaLUT', included=True,
curshader.add_uniform('sampler2D singleScatterLUT', link='_singleScatterLUT', included=True,
tex_addr_u='clamp', tex_addr_v='clamp')
curshader.add_uniform('vec2 nishitaDensity', link='_nishitaDensity', included=True)
curshader.add_uniform('vec2 skyDensity', link='_skyDensity', included=True)
planet_radius = 6360e3 # Earth radius used in Blender
ray_origin_z = planet_radius + node.altitude
state.world.lnx_nishita_density = [node.air_density, node.dust_density, node.ozone_density]
dust_density = node.aerosol_density if bpy.app.version >= (5, 0, 0) else node.dust_density
state.world.lnx_sky_density = [node.air_density, dust_density, node.ozone_density]
state.world.lnx_envtex_sun_direction = [node.sun_direction[0], node.sun_direction[1], node.sun_direction[2]]
sun = ''
if node.sun_disc:
@ -428,7 +431,29 @@ def parse_sky_nishita(node: bpy.types.ShaderNodeTexSky, state: ParserState) -> v
size = math.cos(theta)
sun = f'* sun_disk(pos, sunDir, {size}, {node.sun_intensity})'
return f'nishita_atmosphere(pos, vec3(0, 0, {ray_origin_z}), sunDir, {planet_radius}){sun}'
return f'single_scatter_atmosphere(pos, vec3(0, 0, {ray_origin_z}), sunDir, {planet_radius}){sun}'
def parse_sky_multiple_scattering(node: bpy.types.ShaderNodeTexSky, state: ParserState) -> vec3str:
curshader = state.curshader
curshader.add_include('std/sky.glsl')
curshader.add_uniform('vec3 sunDir', link='_sunDirection')
curshader.add_uniform('sampler2D multiScatterLUT', link='_multiScatterLUT', included=True, tex_addr_u='repeat', tex_addr_v='clamp')
curshader.add_uniform('vec4 multiScatterParams', link='_multiScatterParams', included=True)
curshader.add_uniform('vec4 multiScatterSunBottom', link='_multiScatterSunBottom', included=True)
curshader.add_uniform('vec3 multiScatterSunTop', link='_multiScatterSunTop', included=True)
dust_density = node.aerosol_density if bpy.app.version >= (5, 0, 0) else node.dust_density
state.world.lnx_sky_density = [node.air_density, dust_density, node.ozone_density]
state.world.lnx_sky_sun_elevation = node.sun_elevation
state.world.lnx_sky_sun_rotation = node.sun_rotation
state.world.lnx_sky_sun_size = node.sun_size
state.world.lnx_sky_sun_intensity = node.sun_intensity if node.sun_disc else 0.0
state.world.lnx_sky_altitude = node.altitude
state.world.lnx_sky_sun_disc = 1 if node.sun_disc else 0
state.world.lnx_envtex_sun_direction = [node.sun_direction[0], node.sun_direction[1], node.sun_direction[2]]
return f'multi_scatter_atmosphere(pos)'
def parse_tex_environment(node: bpy.types.ShaderNodeTexEnvironment, out_socket: bpy.types.NodeSocket, state: ParserState) -> vec3str: