| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  | shader_type spatial; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_burley, specular_schlick_ggx, alpha_to_coverage_and_one; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Math.gdshaderinc" | 
					
						
							|  |  |  | #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Transform.gdshaderinc" | 
					
						
							|  |  |  | #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Noise.gdshaderinc" | 
					
						
							|  |  |  | #include "res://addons/rokojori_action_library/Runtime/Shading/Library/Light.gdshaderinc" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | uniform float size = 1; | 
					
						
							| 
									
										
										
										
											2025-03-25 06:58:53 +00:00
										 |  |  | uniform float sizeMin = 1; | 
					
						
							|  |  |  | uniform float sizeMax = 1; | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  | uniform float randomPosition; | 
					
						
							|  |  |  | uniform vec4 albedo : source_color; | 
					
						
							|  |  |  | uniform float rotation : hint_range(0,6.28) = 0; | 
					
						
							|  |  |  | uniform float rotationNoiseAmount = 0; | 
					
						
							|  |  |  | uniform float rotationNoiseScale = 0; | 
					
						
							|  |  |  | uniform sampler2D texture_albedo : source_color, filter_linear_mipmap, repeat_disable; | 
					
						
							|  |  |  | uniform sampler2D texture_normals : hint_roughness_normal, filter_linear_mipmap, repeat_disable; | 
					
						
							|  |  |  | uniform float normalBlendAmount: hint_range(0,1) = 0.5; | 
					
						
							|  |  |  | uniform vec3 normalBlendDirection = vec3( 0, 1, 0 ); | 
					
						
							|  |  |  | uniform float roughness: hint_range(0,1) = 1; | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  | uniform float metalness: hint_range(0,1) = 1; | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  | uniform float specular: hint_range(0,1) = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | uniform float alpha_scissor_threshold : hint_range(0.0, 1.0, 0.001); | 
					
						
							|  |  |  | uniform float alpha_antialiasing_edge : hint_range(0.0, 1.0, 0.01); | 
					
						
							|  |  |  | uniform ivec2 albedo_texture_size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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 float yMapStart; | 
					
						
							|  |  |  | uniform float yMapEnd; | 
					
						
							|  |  |  | uniform float yMapNoiseAmount; | 
					
						
							|  |  |  | uniform float yMapNoiseScale; | 
					
						
							|  |  |  | varying float yMapValue; | 
					
						
							|  |  |  | uniform sampler2D texture_yMapGradient : source_color, filter_linear_mipmap, repeat_disable; | 
					
						
							|  |  |  | varying float uvRotation; | 
					
						
							|  |  |  | uniform float discardNoiseScale = 1; | 
					
						
							|  |  |  | uniform float discardThreshold : hint_range(0,1) = 1; | 
					
						
							|  |  |  | varying float discardValue; | 
					
						
							|  |  |  | uniform float fresnelNormalSource  : hint_range(0,1) = 0.5; | 
					
						
							|  |  |  | uniform vec4 fresnelColor : source_color; | 
					
						
							|  |  |  | uniform float fresnelSharpness : hint_range(0.001,10) = 1; | 
					
						
							|  |  |  | uniform float fresnelScale = 1; | 
					
						
							|  |  |  | varying float fresnelAmount; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | varying vec3 originalNormal; | 
					
						
							|  |  |  | uniform float windAmount = 1; | 
					
						
							|  |  |  | uniform vec2 windSpeed = vec2( 0.1, 0.1 ); | 
					
						
							|  |  |  | uniform float windNoiseScale = 1; | 
					
						
							|  |  |  | uniform float windStart = 0; | 
					
						
							|  |  |  | uniform float windEnd = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void vertex() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   vec4 worldVertex = MODEL_MATRIX *vec4( VERTEX, 1.0 ); | 
					
						
							|  |  |  |   float windAngle = perlinPolar( TIME * windSpeed + windNoiseScale * vec2( worldVertex.x, worldVertex.z ) ); | 
					
						
							|  |  |  |   float windStrength = perlinPolar( TIME * windSpeed + windNoiseScale * vec2( worldVertex.x, worldVertex.z ) + vec2( 1023.9, 334.90 ) ); | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   vec2 windDirection = onCircle( windAngle * 6.28 ) * windStrength; | 
					
						
							|  |  |  |   float yWindAmount = normalizeToRange01( worldVertex.y, windStart, windEnd ) * windAmount; | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   float nrx  = perlinPolar( NORMAL.yz + worldVertex.yz ); | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  |   float nry  = perlinPolar( NORMAL.xz + worldVertex.xz ); | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   float nrz  = perlinPolar( NORMAL.xy + worldVertex.xy ); | 
					
						
							|  |  |  |   float px   = perlinPolar( NORMAL.yz ); | 
					
						
							|  |  |  |   float pz   = perlinPolar( NORMAL.xy ); | 
					
						
							|  |  |  |   float filter = perlin( vec2( px, pz ) * discardNoiseScale ); | 
					
						
							| 
									
										
										
										
											2025-03-25 06:58:53 +00:00
										 |  |  |      | 
					
						
							|  |  |  |   float scaleMix = perlin3D( vec3( nrx, nry, nrz ) ) ; | 
					
						
							|  |  |  |   float randomScale = mix( sizeMin, sizeMax, scaleMix ); | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   discardValue = filter; | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   vec3 worldOffset = billboardWorldOffset( UV, INV_VIEW_MATRIX, MODEL_MATRIX ); | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   vec3 originalVertex = VERTEX; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-25 06:58:53 +00:00
										 |  |  |   VERTEX = VERTEX + worldOffset * size * randomScale + vec3( nrx, nry, nrz ) * randomPosition; | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   VERTEX = VERTEX + yWindAmount * vec3( windDirection.x, 0, windDirection.y ); | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   vec3 vertexNormal = originalVertex; vertexNormal.y = 0.0; vertexNormal = normalize( vertexNormal ); | 
					
						
							|  |  |  |   vec3 normal = mix( NORMAL, vertexNormal, fresnelNormalSource ); | 
					
						
							|  |  |  |   vec3 worldNormal = normalize( MODEL_NORMAL_MATRIX * normal ); | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  |   vec3 camDir = normalize( CAMERA_DIRECTION_WORLD ); | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   fresnelAmount =  fresnel( camDir, worldNormal, fresnelSharpness ) * fresnelScale; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  |   originalNormal = normalize( (vec4( localToWorldDirection( NORMAL, MODEL_MATRIX ), 1.0 ) * INV_VIEW_MATRIX ).xyz); | 
					
						
							|  |  |  |   NORMAL = normalize( mix( NORMAL, normalBlendDirection, normalBlendAmount ) ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   float random = perlinPolar( vec2( worldVertex.x, worldVertex.z ) * yMapNoiseScale ); | 
					
						
							|  |  |  |   uvRotation = rotation + rotationNoiseAmount * perlinPolar( vec2( worldVertex.x + worldVertex.y, worldVertex.z - worldVertex.y) * rotationNoiseScale ); | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  |   uvRotation = mod( uvRotation, 6.28); | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   float y = worldVertex.y + yMapNoiseAmount * random; | 
					
						
							|  |  |  |   yMapValue = normalizeToRange01( y, yMapEnd, yMapStart ); | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   // rotatedUV = rotateAround_v2( UV, mod( rotation + random2 * rotationNoiseAmount, PI * 2.0 ), vec2( 0.5, 0.5 ) ); | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void fragment() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   if ( discardValue > discardThreshold ) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     discard; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   vec2 uv = rotateAround_v2( UV, uvRotation, vec2( 0.5, 0.5 ) ); | 
					
						
							|  |  |  |   vec4 albedo_tex = texture( texture_albedo, uv ); | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  |   vec4 normalColor = texture( texture_normals, uv ); | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   vec4 yGradient = texture( texture_yMapGradient, vec2( 0, yMapValue ) ); | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  | 	ALBEDO = albedo.rgb * albedo_tex.rgb * yGradient.rgb + fresnelColor.rgb * fresnelAmount; | 
					
						
							| 
									
										
										
										
											2025-01-08 18:46:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-03 12:09:23 +00:00
										 |  |  |   NORMAL_MAP = normalColor.rgb; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ALPHA *= albedo.a * albedo_tex.a; | 
					
						
							|  |  |  | 	ALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold; | 
					
						
							|  |  |  | 	ALPHA_ANTIALIASING_EDGE = alpha_antialiasing_edge; | 
					
						
							|  |  |  | 	ALPHA_TEXTURE_COORDINATE = UV * vec2( albedo_texture_size ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   METALLIC = metalness; | 
					
						
							|  |  |  |   ROUGHNESS = roughness; | 
					
						
							|  |  |  |   SPECULAR = specular; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   AO = dot(texture( texture_ambient_occlusion, UV ), ao_texture_channel ); | 
					
						
							|  |  |  | 	AO_LIGHT_AFFECT = ao_light_affect; | 
					
						
							|  |  |  | } |