103 lines
4.0 KiB
Plaintext
103 lines
4.0 KiB
Plaintext
// NOTE: Shader automatically converted from Godot Engine 4.5.stable.mono's StandardMaterial3D.
|
|
|
|
shader_type spatial;
|
|
render_mode blend_mix, depth_draw_opaque, cull_disabled, diffuse_burley, specular_schlick_ggx;
|
|
|
|
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc"
|
|
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Transform.gdshaderinc"
|
|
|
|
uniform vec4 albedo : source_color;
|
|
uniform sampler2D texture_albedo : source_color, filter_nearest_mipmap_anisotropic, repeat_enable;
|
|
uniform float alpha_scissor_threshold : hint_range(0.0, 1.0, 0.001);
|
|
uniform ivec2 albedo_texture_size;
|
|
uniform float point_size : hint_range(0.1, 128.0, 0.1);
|
|
|
|
uniform float roughness : hint_range(0.0, 1.0);
|
|
uniform sampler2D texture_metallic : hint_default_white, filter_nearest_mipmap_anisotropic, repeat_enable;
|
|
uniform vec4 metallic_texture_channel;
|
|
uniform sampler2D texture_roughness : hint_roughness_r, filter_nearest_mipmap_anisotropic, repeat_enable;
|
|
|
|
uniform float specular : hint_range(0.0, 1.0, 0.01);
|
|
uniform float metallic : hint_range(0.0, 1.0, 0.01);
|
|
|
|
uniform sampler2D texture_emission : source_color, hint_default_black, filter_nearest_mipmap_anisotropic, repeat_enable;
|
|
uniform vec4 emission : source_color;
|
|
uniform float emission_energy : hint_range(0.0, 100.0, 0.01);
|
|
|
|
uniform sampler2D texture_normal : hint_roughness_normal, filter_nearest_mipmap_anisotropic, repeat_enable;
|
|
uniform float normal_scale : hint_range(-16.0, 16.0);
|
|
|
|
uniform vec4 backlight : source_color;
|
|
uniform sampler2D texture_backlight : hint_default_black, filter_nearest_mipmap_anisotropic, repeat_enable;
|
|
|
|
uniform vec3 uv1_scale;
|
|
uniform vec3 uv1_offset;
|
|
|
|
|
|
group_uniforms snow;
|
|
uniform float maxSnowV = 0.8;
|
|
uniform float topSnowOpacity = 1;
|
|
uniform float bottomSnowOpacity = 0;
|
|
uniform float snowWaveFrequency = 2;
|
|
uniform float snowWaveFrequencySeedAmount = 7;
|
|
uniform float snowWaveAmount = 0;
|
|
uniform float snowWaveSeedStrength = 1;
|
|
uniform float snowUVFadeOut = 1.0;
|
|
uniform float snowUVFadeIn = 0.0;
|
|
varying float worldSeedXZ;
|
|
|
|
global uniform float globalSnowAmount;
|
|
|
|
varying vec2 snowUV;
|
|
|
|
void vertex()
|
|
{
|
|
UV = UV * uv1_scale.xy + uv1_offset.xy;
|
|
worldSeedXZ = fract( 123.94444 * fract( NODE_POSITION_WORLD.x * 42130.323 ) + 3.35 * fract( NODE_POSITION_WORLD.z * 13435.124 ) );
|
|
|
|
vec3 worldPosition = localToWorld( VERTEX, MODEL_MATRIX );
|
|
snowUV = vec2( UV.x, mapClamped( worldPosition.y, snowUVFadeIn, snowUVFadeOut, 0.0, 1.0 ) );
|
|
}
|
|
|
|
void fragment()
|
|
{
|
|
vec2 tSize = vec2( textureSize( texture_albedo, 0 ) );
|
|
|
|
vec2 quantizedUV = round( snowUV * tSize ) / tSize;
|
|
float snowV = mix( 0.0, maxSnowV, globalSnowAmount );
|
|
float vOffset = sin( quantizedUV.x * ( snowWaveFrequency + ( worldSeedXZ * 2.0 - 1.0 ) * snowWaveFrequencySeedAmount ) + worldSeedXZ * snowWaveSeedStrength ) * snowWaveAmount;
|
|
float inSnow = mapClamped( quantizedUV.y + vOffset, 0.0, snowV, 1.0, 0.0 );
|
|
float snowCoverage = mix( bottomSnowOpacity, topSnowOpacity, inSnow );
|
|
// snowCoverage = max( snowCoverage, worldNormalAmount );
|
|
snowCoverage *= mapClamped( globalSnowAmount, 0, 0.4, 0, 1.0 );
|
|
|
|
vec2 base_uv = UV;
|
|
|
|
vec4 albedo_tex = texture(texture_albedo, base_uv);
|
|
ALBEDO = albedo.rgb * albedo_tex.rgb;
|
|
ALBEDO = mix( ALBEDO, vec3( 1 ), snowCoverage );
|
|
|
|
float metallic_tex = dot(texture(texture_metallic, base_uv), metallic_texture_channel);
|
|
METALLIC = metallic_tex * metallic;
|
|
SPECULAR = specular;
|
|
|
|
vec4 roughness_texture_channel = vec4(1.0, 0.0, 0.0, 0.0);
|
|
float roughness_tex = dot(texture(texture_roughness, base_uv), roughness_texture_channel);
|
|
ROUGHNESS = roughness_tex * roughness;
|
|
|
|
// Normal Map: Enabled
|
|
NORMAL_MAP = texture(texture_normal, base_uv).rgb;
|
|
NORMAL_MAP_DEPTH = normal_scale;
|
|
|
|
// Emission: Enabled
|
|
vec3 emission_tex = texture(texture_emission, base_uv).rgb;
|
|
// Emission Operator: Add
|
|
EMISSION = (emission.rgb + emission_tex) * emission_energy;
|
|
ALPHA *= albedo.a * albedo_tex.a;
|
|
ALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold;
|
|
|
|
// Backlight: Enabled
|
|
vec3 backlight_tex = texture(texture_backlight, base_uv).rgb;
|
|
BACKLIGHT = (backlight.rgb + backlight_tex);
|
|
}
|