170 lines
6.2 KiB
Plaintext
170 lines
6.2 KiB
Plaintext
|
|
shader_type spatial;
|
|
render_mode blend_mix, depth_draw_opaque, cull_disabled, diffuse_burley, specular_schlick_ggx, sss_mode_skin;
|
|
|
|
|
|
#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_ambient_occlusion : hint_default_white, filter_nearest_mipmap_anisotropic, repeat_enable;
|
|
uniform vec4 ao_texture_channel;
|
|
uniform float ao_light_affect : hint_range(0.0, 1.0, 0.01);
|
|
|
|
uniform float subsurface_scattering_strength : hint_range(0.0, 1.0, 0.01);
|
|
uniform sampler2D texture_subsurface_scattering : hint_default_white, filter_nearest_mipmap_anisotropic, repeat_enable;
|
|
|
|
uniform vec4 transmittance_color : source_color;
|
|
uniform float transmittance_depth : hint_range(0.001, 8.0, 0.001);
|
|
uniform sampler2D texture_subsurface_transmittance : hint_default_white, filter_nearest_mipmap_anisotropic, repeat_enable;
|
|
uniform float transmittance_boost : hint_range(0.0, 1.0, 0.01);
|
|
|
|
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;
|
|
|
|
// [ SNOW ]
|
|
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;
|
|
global uniform float globalSnowAmount;
|
|
|
|
// [ VARIANCE ]
|
|
group_uniforms variance;
|
|
varying float worldSeedXZ;
|
|
|
|
uniform float rotationZ = 0;
|
|
uniform float rotationZSeed = 0;
|
|
varying float combinedRotationZ;
|
|
|
|
|
|
|
|
// [ PLAYER DEFROM ]
|
|
group_uniforms playerDeform;
|
|
|
|
global uniform vec3 playerPosition;
|
|
uniform float playerDeformRange = 2.0;
|
|
uniform float playerDeformAmount = 0.5;
|
|
uniform float playerDeformPower:hint_range( 0.25, 4 ) = 1;
|
|
uniform float playerDeformYStart = 0.2;
|
|
uniform float playerDeformYMax = 1;
|
|
|
|
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 ) );
|
|
|
|
// PLAYER DEFORM
|
|
vec3 localPlayerPosition = worldToLocal( playerPosition, MODEL_MATRIX );
|
|
localPlayerPosition.y = 0.0;
|
|
|
|
float positionLength = length( localPlayerPosition );
|
|
|
|
if ( positionLength == 0.0 )
|
|
{
|
|
localPlayerPosition = vec3( 0.0001, 0, 0 );
|
|
}
|
|
|
|
vec3 dir = normalize( localPlayerPosition );
|
|
|
|
float amount = mapClamped( positionLength, 0.0, playerDeformRange, playerDeformAmount, 0 );
|
|
amount = clamp01( pow( amount, playerDeformPower ) );
|
|
float yAmount = mapClamped( VERTEX.y, playerDeformYStart, playerDeformYMax, 0.0, 1.0 );
|
|
VERTEX += dir * - amount * yAmount;
|
|
|
|
|
|
|
|
// 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)
|
|
);
|
|
|
|
combinedRotationZ = rotationZ + ( worldSeedXZ * 2.0 - 1.0 ) * rotationZSeed;
|
|
combinedRotationZ = combinedRotationZ / 180.0 * PI;
|
|
MODELVIEW_MATRIX = MODELVIEW_MATRIX * rotationZ_m4( combinedRotationZ );
|
|
MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX);
|
|
}
|
|
|
|
void fragment()
|
|
{
|
|
vec2 tSize = vec2( textureSize( texture_albedo, 0 ) );
|
|
vec2 quantizedUV = round( rotateAround_v2( UV, -combinedRotationZ, vec2( 0.5, 0.5 ) ) * tSize ) / tSize;
|
|
float snowV = mix( 0.0, maxSnowV, globalSnowAmount );
|
|
//float vOffset = sin( quantizedUV.x * snowWaveFrequency + worldSeedXZ * snowWaveSeedStrength ) * snowWaveAmount;
|
|
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 = clamp01( snowCoverage );
|
|
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.0 ), 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;
|
|
ALPHA *= albedo.a * albedo_tex.a;
|
|
ALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold;
|
|
|
|
// Ambient Occlusion: Enabled
|
|
AO = dot(texture(texture_ambient_occlusion, base_uv), ao_texture_channel);
|
|
AO_LIGHT_AFFECT = ao_light_affect;
|
|
|
|
// Subsurface Scattering: Enabled
|
|
float sss_tex = texture(texture_subsurface_scattering, base_uv).r;
|
|
SSS_STRENGTH = subsurface_scattering_strength * sss_tex;
|
|
|
|
// Subsurface Scattering Transmittance: Enabled
|
|
vec4 trans_color_tex = texture(texture_subsurface_transmittance, base_uv);
|
|
SSS_TRANSMITTANCE_COLOR = transmittance_color * trans_color_tex;
|
|
SSS_TRANSMITTANCE_DEPTH = transmittance_depth;
|
|
SSS_TRANSMITTANCE_BOOST = transmittance_boost;
|
|
|
|
// Backlight: Enabled
|
|
vec3 backlight_tex = texture(texture_backlight, base_uv).rgb;
|
|
BACKLIGHT = (backlight.rgb + backlight_tex);
|
|
}
|