winter-tales/GameObjects/Snow/Snow.gdshader

90 lines
3.3 KiB
Plaintext
Raw Permalink Normal View History

2025-12-10 14:18:09 +00:00
// NOTE: Shader automatically converted from Godot Engine 4.5.stable.mono's StandardMaterial3D.
shader_type spatial;
render_mode blend_mix, depth_draw_never, cull_disabled, diffuse_burley, specular_schlick_ggx, unshaded;
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Transform.gdshaderinc"
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc"
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Noise.gdshaderinc"
uniform vec4 albedo : source_color;
uniform sampler2D texture_albedo : source_color, filter_linear_mipmap_anisotropic, repeat_enable;
uniform float alpha_scissor_thresholdClose : hint_range(0.0, 1.0, 0.001);
uniform float alpha_scissor_thresholdFar : hint_range(0.0, 1.0, 0.001);
uniform float alpha_scissor_distance : hint_range(1.0, 100.0);
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_linear_mipmap_anisotropic, repeat_enable;
uniform vec4 metallic_texture_channel;
uniform sampler2D texture_roughness : hint_roughness_r, filter_linear_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 vec3 uv1_scale;
uniform vec3 uv1_offset;
uniform vec3 uv2_scale;
uniform vec3 uv2_offset;
varying float alphaTreshold;
global uniform float globalSnowAmount;
uniform float noiseScale = 1;
varying float noiseXZ;
void vertex()
{
vec3 worldVertex = localToWorld( VERTEX, MODEL_MATRIX );
vec2 noisePosition = vec2( worldVertex.x, worldVertex.z );
noiseXZ = mod( noisePosition.x * noiseScale, 1.0 ) ;
float cameraDistance = length( localToWorld( VERTEX, MODEL_MATRIX ) - CAMERA_POSITION_WORLD );
alphaTreshold = mapClamped( cameraDistance, 0, alpha_scissor_distance, alpha_scissor_thresholdClose, alpha_scissor_thresholdFar );
UV = UV * uv1_scale.xy + uv1_offset.xy;
// Billboard Mode: Enabled
MODELVIEW_MATRIX = VIEW_MATRIX * mat4(
MAIN_CAM_INV_VIEW_MATRIX[0],
MAIN_CAM_INV_VIEW_MATRIX[1],
MAIN_CAM_INV_VIEW_MATRIX[2],
MODEL_MATRIX[3]);
// Billboard Keep Scale: Enabled
MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(
vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0),
vec4(0.0, length(MODEL_MATRIX[1].xyz), 0.0, 0.0),
vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0),
vec4(0.0, 0.0, 0.0, 1.0));
MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX);
}
void fragment()
{
vec2 base_uv = UV;
vec4 albedo_tex = texture(texture_albedo, base_uv);
// Vertex Color Use as Albedo: Enabled
albedo_tex *= COLOR;
ALBEDO = albedo.rgb * albedo_tex.rgb;
// ALBEDO = mix( ALBEDO, vec3( 1, 0, 0 ), noiseXZ );
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;
ALPHA *= albedo.a * albedo_tex.a;
float fullAmount = mapClamped( globalSnowAmount, 0.2, 0.6, 0.0, 1.0 );
ALPHA *= mix( globalSnowAmount * noiseXZ * 2.0, 1.0, fullAmount ) ;
ALPHA_SCISSOR_THRESHOLD = alphaTreshold;
}