Files
jelito/Assets/Jbl_Shaders/Jbl_Water2.0.shadergraph
2025-10-08 20:28:22 +02:00

164 lines
6.0 KiB
Plaintext

Shader "Custom/UniversalLiquidSurface_URP"
{
Properties
{
_MainColor ("Main Color", Color) = (0.0, 0.5, 1.0, 1.0)
_EmissionColor ("Emission Color", Color) = (1.0, 0.4, 0.0, 1.0)
_SurfaceType ("Surface Type", Range(0,3)) = 0 // 0: Water, 1: Lava, 2: Ice, 3: River
_Speed ("Animation Speed", Float) = 1.0
_DistortionStrength ("Distortion Strength", Float) = 0.1
_ReflectionStrength ("Reflection Strength", Float) = 0.5
_MainTex ("Main Texture", 2D) = "white" {}
_NormalMap ("Normal Map", 2D) = "bump" {}
_BubbleMask ("Bubble Mask (for Lava)", 2D) = "black" {}
_BubbleSpeed ("Bubble Rising Speed", Float) = 0.2
_FoamTex ("Foam Texture (for Water/River)", 2D) = "white" {}
_FoamStrength ("Foam Strength", Float) = 0.5
}
SubShader
{
Tags { "RenderPipeline"="UniversalRenderPipeline" "RenderType"="Opaque" }
LOD 300
Pass
{
Name "ForwardLit"
Tags { "LightMode"="UniversalForward" }
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _ADDITIONAL_LIGHTS
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
#pragma multi_compile _ _SHADOWS_SOFT
#pragma multi_compile_fog
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
struct Attributes
{
float4 positionOS : POSITION;
float2 uv : TEXCOORD0;
float3 normalOS : NORMAL;
};
struct Varyings
{
float4 positionHCS : SV_POSITION;
float2 uv : TEXCOORD0;
float3 worldPos : TEXCOORD1;
float3 normalWS : TEXCOORD2;
float3 viewDirWS : TEXCOORD3;
};
sampler2D _MainTex;
sampler2D _NormalMap;
sampler2D _BubbleMask;
sampler2D _FoamTex;
float4 _MainColor;
float4 _EmissionColor;
float _SurfaceType;
float _Speed;
float _DistortionStrength;
float _ReflectionStrength;
float _BubbleSpeed;
float _FoamStrength;
Varyings vert (Attributes IN)
{
Varyings OUT;
OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
OUT.uv = IN.uv;
OUT.worldPos = TransformObjectToWorld(IN.positionOS.xyz);
OUT.normalWS = TransformObjectToWorldNormal(IN.normalOS);
OUT.viewDirWS = GetWorldSpaceViewDir(OUT.worldPos);
return OUT;
}
half4 frag (Varyings IN) : SV_Target
{
// Animacja UV
float2 animatedUV = IN.uv + float2(_Time.y * _Speed, _Time.y * _Speed);
// Tekstury
half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, animatedUV);
half3 normalTS = UnpackNormal(SAMPLE_TEXTURE2D(_NormalMap, sampler_NormalMap, animatedUV));
float2 distortedUV = animatedUV + normalTS.xy * _DistortionStrength;
// Kolor bazowy
half3 baseColor = lerp(tex.rgb, _MainColor.rgb, 0.5);
// Fresnel
float3 N = normalize(IN.normalWS);
float3 V = normalize(IN.viewDirWS);
float fresnel = pow(1.0 - saturate(dot(N, V)), 3.0);
half3 finalColor = baseColor;
half3 emission = 0;
half smoothness = 0.5;
// Typ powierzchni
if (_SurfaceType == 0) // 🌊 Woda
{
smoothness = 0.8;
emission += fresnel * _ReflectionStrength;
half4 foam = SAMPLE_TEXTURE2D(_FoamTex, sampler_FoamTex, IN.uv * 2.0 + float2(0, _Time.y * _Speed));
emission += foam.r * _FoamStrength;
}
else if (_SurfaceType == 1) // 🔥 Lawa
{
finalColor = _MainColor.rgb;
smoothness = 0.3;
emission = _EmissionColor.rgb;
float2 bubbleUV = IN.uv + float2(0, _Time.y * _BubbleSpeed);
half4 bubbleTex = SAMPLE_TEXTURE2D(_BubbleMask, sampler_BubbleMask, bubbleUV);
emission += bubbleTex.r * _EmissionColor.rgb * 2.0;
}
else if (_SurfaceType == 2) // ❄️ Lód
{
finalColor = _MainColor.rgb;
smoothness = 1.0;
emission = fresnel * _ReflectionStrength * 0.8;
}
else if (_SurfaceType == 3) // 🌿 Rzeka
{
finalColor = tex.rgb * _MainColor.rgb;
smoothness = 0.6;
half4 foam = SAMPLE_TEXTURE2D(_FoamTex, sampler_FoamTex, IN.uv * 3.0 + float2(_Time.y * _Speed, 0));
emission = foam.r * _FoamStrength;
}
// Oświetlenie URP
InputData lightingInput = (InputData)0;
lightingInput.positionWS = IN.worldPos;
lightingInput.normalWS = N;
lightingInput.viewDirectionWS = V;
lightingInput.shadowCoord = TransformWorldToShadowCoord(IN.worldPos);
SurfaceData surfaceData;
surfaceData.albedo = finalColor;
surfaceData.alpha = 1;
surfaceData.metallic = 0;
surfaceData.specular = 0;
surfaceData.smoothness = smoothness;
surfaceData.normalTS = normalTS;
surfaceData.emission = emission;
return UniversalFragmentPBR(lightingInput, surfaceData);
}
ENDHLSL
}
}
}