winter-tales/GameObjects/Ground/Ground.gdshader

111 lines
3.8 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_back, diffuse_burley, specular_schlick_ggx;
#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/Normals.gdshaderinc"
uniform vec4 albedo : source_color;
uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_enable;
uniform ivec2 albedo_texture_size;
uniform float roughness : hint_range(0.0, 1.0);
uniform float roughnessSnow : hint_range(0.0, 1.0);
uniform sampler2D texture_metallic : hint_default_white, filter_linear_mipmap, repeat_enable;
uniform vec4 metallic_texture_channel;
uniform sampler2D texture_roughness : hint_roughness_r, filter_linear_mipmap, 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_normal : hint_roughness_normal, filter_linear_mipmap, repeat_enable;
uniform float normal_scale : hint_range(-16.0, 16.0);
uniform sampler2D texture_ambient_occlusion : hint_default_white, filter_linear_mipmap, repeat_enable;
uniform vec4 ao_texture_channel;
uniform float ao_light_affect : hint_range(0.0, 1.0, 0.01);
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
global uniform float globalSnowAmount;
uniform float snowFadeIn = 0;
uniform float snowMax = 0.5;
uniform float snowTestOffset = 0;
uniform float snowLayerMax = 0.2;
uniform float snowLayerMin = -0.1;
uniform float snowLayerUVScale = 1.0;
uniform float snowOcclusionAmount = 1.0;
uniform float snowNormalSize = 1.0;
uniform float snowNormalStrength = 1.0;
uniform float snowNormalAmount:hint_range( 0.0, 1.0 ) = 1.0;
varying vec3 snowNormal;
varying float snowOcclusion;
uniform sampler2D noiseTexture;
uniform float noiseScale;
uniform vec2 noiseOffset;
uniform float noiseAmount;
varying vec2 noiseUV;
void vertex()
{
UV = UV * uv1_scale.xy + uv1_offset.xy;
vec3 worldVertex = localToWorld( VERTEX, MODEL_MATRIX );
noiseUV = worldVertex.xz / noiseScale + noiseOffset;
vec2 snowLayerUV = worldVertex.xz / snowLayerUVScale;
float snowLayerNoise = textureLod( noiseTexture, snowLayerUV, 0 ).r;
VERTEX.y += mix( snowLayerMin, snowLayerMax, snowLayerNoise ) * globalSnowAmount;
snowNormal = computeNormalFromHeightMap( noiseTexture, snowLayerUV, snowNormalSize, snowNormalStrength );
snowOcclusion = clamp01( mix( 1.0, snowLayerNoise, snowOcclusionAmount * globalSnowAmount ) );
}
void fragment()
{
vec2 base_uv = UV;
float snowCoverage = mapClamped( globalSnowAmount + snowTestOffset, snowFadeIn, snowMax, 0.0, 1.0 );
vec4 noise = texture( noiseTexture, noiseUV );
vec4 albedo_tex = texture(texture_albedo, base_uv);
ALBEDO = albedo.rgb * albedo_tex.rgb;
float nAmount = noiseAmount * mapClamped( globalSnowAmount, 0.0, 0.2, 0.0, 1.0 ) ;
ALBEDO = mix( ALBEDO, vec3( 1.0 ), clamp01( snowCoverage + noise.r * nAmount ) );
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);
float ro = mix( roughness, roughnessSnow, clamp01( globalSnowAmount ) );
ROUGHNESS = roughness_tex * ro;
// Normal Map: Enabled
NORMAL_MAP = mix( texture(texture_normal, base_uv).rgb, snowNormal, snowNormalAmount );
NORMAL_MAP_DEPTH = normal_scale;
// Ambient Occlusion: Enabled
AO = dot(texture(texture_ambient_occlusion, base_uv), ao_texture_channel);
AO *= snowOcclusion;
AO_LIGHT_AFFECT = ao_light_affect;
}