275 lines
12 KiB
Plaintext
275 lines
12 KiB
Plaintext
|
|
|
|
shader_type spatial;
|
|
|
|
// Rokojori Shader @alb.382-fad.255-geo.20-met.376-nor.278-occ.376-rou.390-sha.391-spa.20-spa.24-spe.376-tra.402-tra.402-uvm.19:
|
|
/*
|
|
[ Rokojori.TransparencyModule ] { "alphaScissorTreshold":0.009999999776482582, "blendMode":{"__class__": "Godot.BaseMaterial3D+BlendModeEnum","value__": 0}, "cullMode":{"__class__": "Godot.BaseMaterial3D+CullModeEnum","value__": 0}, "depthDraw":{"__class__": "Godot.BaseMaterial3D+DepthDrawModeEnum","value__": 0}, "noDepthTest":false, "transparency":{"__class__": "Godot.BaseMaterial3D+TransparencyEnum","value__": 0} }
|
|
[ Rokojori.ShadingModule ] { "diffuseMode":{"__class__": "Godot.BaseMaterial3D+DiffuseModeEnum","value__": 0}, "disableAmbientLight":false, "disableFog":false, "disableReceivingShadows":false, "shadingMode":{"__class__": "Godot.BaseMaterial3D+ShadingModeEnum","value__": 1}, "shadowToOpacity":false, "specularMode":{"__class__": "Godot.BaseMaterial3D+SpecularModeEnum","value__": 0}, "wireFrameMode":false }
|
|
[ Rokojori.UVModule ] { "channels":[] }
|
|
[ Rokojori.GeometryModule ] { "modifiers":[] }
|
|
[ Rokojori.SpatialVarying ] { "variables":[] }
|
|
[ Rokojori.SpatialMasksModule ] { "maskVariables":[] }
|
|
[ Rokojori.AlbedoModule ] { "assignmentType":{"__class__": "Rokojori.TextureModule+AssignmentType","value__": 0}, "filter":{"__class__": "Rokojori.TextureModule+TextureFilter","value__": 2}, "overlayLayers":[], "repeat":true, "srgb":true, "textureDefault":{"__class__": "Rokojori.TextureModule+TextureDefault","value__": 0}, "tintVarying":"", "useTint":true, "uvChannel":"UV", "writeAlpha":false }
|
|
[ Rokojori.TransparencyModule ] { "alphaScissorTreshold":0.009999999776482582, "blendMode":{"__class__": "Godot.BaseMaterial3D+BlendModeEnum","value__": 0}, "cullMode":{"__class__": "Godot.BaseMaterial3D+CullModeEnum","value__": 0}, "depthDraw":{"__class__": "Godot.BaseMaterial3D+DepthDrawModeEnum","value__": 0}, "noDepthTest":false, "transparency":{"__class__": "Godot.BaseMaterial3D+TransparencyEnum","value__": 0} }
|
|
[ Rokojori.FadingModule ] { "alphaFadeMode":{"__class__": "Rokojori.AlphaFadeMode","value__": 2}, "fadingModifiers":[{ "__class__": "Rokojori.LineFading", "mode": 1, "alphaFadeMode": 0, "createUniformGroup": false, "sortableCode": true, "uniformGroup": null}] }
|
|
[ Rokojori.NormalMapModule ] { "allowNegativeStrength":false, "filter":{"__class__": "Rokojori.TextureModule+TextureFilter","value__": 5}, "maximumStrength":5, "repeat":true, "textureDefault":{"__class__": "Rokojori.TextureModule+TextureDefault","value__": 0}, "useStrength":true, "uvChannel":"UV" }
|
|
[ Rokojori.OcclusionModule ] { "assignmentType":{"__class__": "Rokojori.TextureModule+AssignmentType","value__": 0}, "domainMode":{"__class__": "Rokojori.TextureModule+DomainMode","value__": 3}, "filter":{"__class__": "Rokojori.TextureModule+TextureFilter","value__": 5}, "repeat":true, "textureDefault":{"__class__": "Rokojori.TextureModule+TextureDefault","value__": 0}, "uvChannel":"UV" }
|
|
[ Rokojori.RoughnessModule ] { "assignmentType":{"__class__": "Rokojori.TextureModule+AssignmentType","value__": 0}, "clamp":true, "domainMode":{"__class__": "Rokojori.TextureModule+DomainMode","value__": 3}, "filter":{"__class__": "Rokojori.TextureModule+TextureFilter","value__": 5}, "repeat":true, "textureDefault":{"__class__": "Rokojori.TextureModule+TextureDefault","value__": 0}, "uvChannel":"UV" }
|
|
[ Rokojori.MetallicModule ] { "assignmentType":{"__class__": "Rokojori.TextureModule+AssignmentType","value__": 0}, "domainMode":{"__class__": "Rokojori.TextureModule+DomainMode","value__": 3}, "filter":{"__class__": "Rokojori.TextureModule+TextureFilter","value__": 5}, "repeat":true, "textureDefault":{"__class__": "Rokojori.TextureModule+TextureDefault","value__": 0}, "uvChannel":"UV" }
|
|
[ Rokojori.SpecularModule ] { "assignmentType":{"__class__": "Rokojori.TextureModule+AssignmentType","value__": 0}, "domainMode":{"__class__": "Rokojori.TextureModule+DomainMode","value__": 0}, "filter":{"__class__": "Rokojori.TextureModule+TextureFilter","value__": 5}, "repeat":true, "textureDefault":{"__class__": "Rokojori.TextureModule+TextureDefault","value__": 0}, "uvChannel":"UV" }
|
|
*/
|
|
|
|
render_mode blend_mix, cull_back, depth_draw_opaque, diffuse_burley, specular_schlick_ggx;
|
|
|
|
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Noise.gdshaderinc"
|
|
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Transform.gdshaderinc"
|
|
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Line3.gdshaderinc"
|
|
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/SDF.gdshaderinc"
|
|
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc"
|
|
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Colors.gdshaderinc"
|
|
#include "res://addons/rokojori_action_library/Runtime/Shading/Library/Wind.gdshaderinc"
|
|
|
|
// [ A L B E D O ]
|
|
group_uniforms albedo;
|
|
|
|
uniform vec4 albedo:source_color = vec4( 1.0, 1.0, 1.0, 1.0);
|
|
uniform sampler2D albedoTexture:source_color, hint_default_white, repeat_enable, filter_nearest_mipmap_anisotropic;
|
|
uniform vec3 hslVariance = vec3( 0, 0, 0 );
|
|
uniform vec3 hslOffset = vec3( 0, 0, 0 );
|
|
uniform vec2 localYMapping = vec2( 0, 0 );
|
|
varying float localYMappingAmount;
|
|
uniform vec3 localYHSLOffset = vec3( 0, 0, 0 );
|
|
uniform float localYOcclusionAmount:hint_range( 0.0, 1.0 ) = 0;
|
|
uniform float localYOcclusionPower:hint_range( -3.0, 3.0 ) = 0;
|
|
uniform vec2 localYOcclusionValues = vec2( 0, 1 );
|
|
|
|
uniform sampler2D noise: hint_default_white, repeat_enable, filter_linear_mipmap_anisotropic;
|
|
uniform float noiseScale = 1;
|
|
uniform vec2 noiseOffset = vec2( 0, 0 );
|
|
|
|
// [ PLAYER DEFROM ]
|
|
group_uniforms playerDeform;
|
|
|
|
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;
|
|
|
|
// [ WIND ]
|
|
group_uniforms wind;
|
|
|
|
// Texture for close wind: grass/foliage
|
|
global uniform sampler2D rj_GlobalWindNoiseTextureClose;
|
|
|
|
// Texture for far wind: trees
|
|
global uniform sampler2D rj_GlobalWindNoiseTextureFar;
|
|
|
|
// Windposition close
|
|
global uniform vec2 rj_GlobalWindPositionClose;
|
|
|
|
// Windposition far
|
|
global uniform vec2 rj_GlobalWindPositionFar;
|
|
|
|
// Wind direction for both
|
|
global uniform vec2 rj_GlobalWindDirection;
|
|
|
|
// Wind speed for both
|
|
global uniform float rj_GlobalWindSpeed;
|
|
|
|
// Weights for x: close and y: far
|
|
uniform vec2 windWeights = vec2( 0.5, 0.5 );
|
|
|
|
// Scales the world-vertex based variance
|
|
uniform float windSeedSize = 1.0;
|
|
|
|
// Max xz bending
|
|
uniform float windMaxStrength = 0.2;
|
|
|
|
// Max yaw rotation
|
|
uniform float windMaxRotation = 0.1;
|
|
|
|
// Linear/Inv-Quadratic mapping for the strength
|
|
uniform float windStrengthCurve:hint_range( 0.0, 1.0 );
|
|
|
|
// Influence start in local Y
|
|
uniform float windStart = 0.1;
|
|
|
|
// Influence max in local Y
|
|
uniform float windEnd = 2.0;
|
|
|
|
// Influence mapping over local Y
|
|
uniform float windWeightCurve:hint_range( 0.0,1.0 ) = 0.5;
|
|
|
|
// Ducking in y for amount, strong wind => vertices lower
|
|
uniform float windHeightCompensation;
|
|
|
|
// Normal incluence
|
|
uniform float windNormalBending;
|
|
|
|
// AO influence
|
|
uniform float windOcclusionAmount;
|
|
varying float vertexWindAO;
|
|
|
|
// [ F A D I N G ]
|
|
group_uniforms Fading;
|
|
|
|
global uniform vec3 playerPosition = vec3( 0.0, 0.0, 0.0);
|
|
varying vec3 worldCameraLineDistanceFadeViewPosition;
|
|
uniform float worldCameraLineDistanceFadeInnerRadius = 0.10000000149011612;
|
|
uniform float worldCameraLineDistanceFadeOuterRadius = 0.15000000596046448;
|
|
uniform float worldLineFadeMin = 0.0;
|
|
|
|
|
|
|
|
|
|
|
|
// // [ N O R M A L ]
|
|
// group_uniforms normal;
|
|
|
|
// uniform float normalStrength:hint_range( 0.0, 5.0) = 1.0;
|
|
// uniform sampler2D normalTexture:hint_normal, repeat_enable, filter_linear_mipmap_anisotropic;
|
|
|
|
|
|
|
|
// [ R O U G H N E S S ]
|
|
group_uniforms roughness;
|
|
uniform float roughness:hint_range( 0.0, 1.0 ) = 1.0;
|
|
uniform vec3 albedoToRoughness = vec3( 0, 0, 0 );
|
|
|
|
// [ S P E C U L A R ]
|
|
group_uniforms specular;
|
|
uniform float specular:hint_range( 0.0, 1.0) = 0.5;
|
|
|
|
varying vec4 noiseValue;
|
|
|
|
|
|
// [ S N O W ]
|
|
group_uniforms snow;
|
|
global uniform float globalSnowAmount;
|
|
uniform float snowFadeLocalYStart = 0.5;
|
|
uniform float snowFadeLocalYEnd = 1.5;
|
|
uniform float snowFadeNoise = 0.3;
|
|
uniform float snowFadePower = 1;
|
|
uniform float snowOpacity = 0.8;
|
|
uniform float snowAlbedo = 1.3;
|
|
uniform float snowRoughness = 0.1;
|
|
uniform float snowSpecular = 1.0;
|
|
uniform float snowLightMix = 0.5;
|
|
|
|
varying float snowAmount;
|
|
|
|
|
|
void vertex()
|
|
{
|
|
|
|
vec3 worldVertex = localToWorld( VERTEX, MODEL_MATRIX );
|
|
vec2 worldUV = ( worldVertex.xz ) / ( 1000.0 * noiseScale ) + noiseOffset;
|
|
noiseValue = textureLod( noise, worldUV, 0 );
|
|
worldCameraLineDistanceFadeViewPosition = worldToView( playerPosition, VIEW_MATRIX );
|
|
|
|
float maxSnowAmount = mapClamped( VERTEX.y, snowFadeLocalYStart + snowFadeNoise * noiseValue.r, snowFadeLocalYEnd + snowFadeNoise * noiseValue.r, 0.0, snowOpacity );
|
|
maxSnowAmount = clamp01( pow( maxSnowAmount, snowFadePower ) );
|
|
snowAmount = maxSnowAmount * globalSnowAmount;
|
|
|
|
localYMappingAmount = map( VERTEX.y, localYMapping.x, localYMapping.y, 0.0, 1.0 );
|
|
|
|
// PLAYER DEFORM
|
|
|
|
vec3 localPlayerPosition = worldToLocal( playerPosition, MODEL_MATRIX ) - VERTEX;
|
|
localPlayerPosition.y = 0.0;
|
|
|
|
float length = length( localPlayerPosition );
|
|
|
|
if ( length == 0.0 )
|
|
{
|
|
localPlayerPosition = vec3( 0.0001, 0, 0 );
|
|
}
|
|
|
|
vec3 dir = normalize( localPlayerPosition );
|
|
|
|
float amount = mapClamped( length, 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;
|
|
|
|
// WIND
|
|
|
|
float windAO = 0.0;
|
|
applyGlobalWind(
|
|
MODEL_MATRIX,
|
|
VERTEX,
|
|
NORMAL,
|
|
windAO,
|
|
windOcclusionAmount,
|
|
rj_GlobalWindNoiseTextureClose,
|
|
rj_GlobalWindNoiseTextureFar,
|
|
rj_GlobalWindPositionClose,
|
|
rj_GlobalWindPositionFar,
|
|
rj_GlobalWindDirection,
|
|
rj_GlobalWindSpeed,
|
|
windWeights,
|
|
windSeedSize,
|
|
windMaxStrength,
|
|
windMaxRotation,
|
|
windStrengthCurve,
|
|
windStart,
|
|
windEnd,
|
|
windWeightCurve,
|
|
windHeightCompensation,
|
|
windNormalBending
|
|
);
|
|
|
|
vertexWindAO = windAO;
|
|
|
|
}
|
|
|
|
void fragment()
|
|
{
|
|
|
|
float worldLineDistanceFadeDistance =
|
|
sdRoundCone( VERTEX, vec3( 0.0, 0.0, 0.0),
|
|
worldCameraLineDistanceFadeViewPosition, 0,
|
|
worldCameraLineDistanceFadeInnerRadius
|
|
);
|
|
|
|
|
|
float worldRadius = worldCameraLineDistanceFadeOuterRadius - worldCameraLineDistanceFadeInnerRadius;
|
|
float worldLineDistanceFadeAmount = smoothstep( 0, worldRadius, worldLineDistanceFadeDistance );
|
|
worldLineDistanceFadeAmount = clamp( worldLineDistanceFadeAmount, worldLineFadeMin, 1.0 );
|
|
|
|
vec3 objectNormal = normalize( worldCameraLineDistanceFadeViewPosition - VERTEX );
|
|
vec3 cameraNormal = NORMAL;
|
|
float worldLineDistanceDot = dot( cameraNormal, objectNormal );
|
|
worldLineDistanceDot = max( 0, sign( worldLineDistanceDot ) );
|
|
|
|
if ( worldLineDistanceDot == 0.0 && ditherDiscard( worldLineDistanceFadeAmount, FRAGCOORD ) )
|
|
{
|
|
discard;
|
|
}
|
|
|
|
vec4 sampledAlbedo = texture( albedoTexture, UV );
|
|
ALBEDO = sampledAlbedo.rgb * albedo.rgb;
|
|
|
|
vec3 hslAmount = ( noiseValue.rgb - 0.5 ) * 2.0;
|
|
vec3 localYHSL = localYMappingAmount * localYHSLOffset;
|
|
ALBEDO = adjustHSL( ALBEDO, hslAmount * hslVariance + hslOffset + localYHSL );
|
|
|
|
ALBEDO = mix( ALBEDO, vec3( snowAlbedo ), snowAmount );
|
|
|
|
float localYocclusion = pow( max( 0.0, localYMappingAmount ), pow( 2.0, localYOcclusionPower ) );
|
|
AO = mix( 1.0, mix( localYOcclusionValues.x, localYOcclusionValues.y, localYocclusion ), localYOcclusionAmount );
|
|
AO *= vertexWindAO;
|
|
|
|
vec3 albedoRoughnessRGB = sampledAlbedo.rgb * albedoToRoughness;
|
|
float albedoRoughness = albedoRoughnessRGB.r + albedoRoughnessRGB.g + albedoRoughnessRGB.b;
|
|
ROUGHNESS = roughness + albedoRoughness;
|
|
SPECULAR = specular;
|
|
|
|
ROUGHNESS = mix( ROUGHNESS, snowRoughness, snowLightMix * snowAmount );
|
|
SPECULAR = mix( SPECULAR, snowSpecular, snowLightMix * snowAmount );
|
|
|
|
|
|
}
|