From dc939d0ef6ea42992fa1310a8b7ed4331940adb5 Mon Sep 17 00:00:00 2001 From: DeMuenu <96650288+DeMuenu@users.noreply.github.com> Date: Fri, 26 Sep 2025 20:11:49 +0200 Subject: [PATCH] Add WaterParticle shader and minor water shader tweaks Introduced a new WaterParticle shader for rendering water particles with alpha blending. Made minor formatting and calculation adjustments in Water.shader and DefaultSetup.hlsl, and updated Variables.hlsl. Added corresponding .meta files for new shader assets. --- Shader/Includes/DefaultSetup.hlsl | 11 ++--- Shader/Includes/Variables.hlsl | 1 + Shader/Includes/Variables.hlsl.meta | 7 ++++ Shader/Water.shader | 6 +-- Shader/WaterParticle.shader | 62 +++++++++++++++++++++++++++++ Shader/WaterParticle.shader.meta | 9 +++++ 6 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 Shader/Includes/Variables.hlsl.meta create mode 100644 Shader/WaterParticle.shader create mode 100644 Shader/WaterParticle.shader.meta diff --git a/Shader/Includes/DefaultSetup.hlsl b/Shader/Includes/DefaultSetup.hlsl index 9ee1e01..7879d1a 100644 --- a/Shader/Includes/DefaultSetup.hlsl +++ b/Shader/Includes/DefaultSetup.hlsl @@ -4,10 +4,9 @@ \ float distanceFromLight = length(i.worldPos - _LightPositions[LightCounter].xyz); \ if (distanceFromLight > _LightCutoffDistance) continue; \ - \ - float contrib = 0.0; \ - - + \ + float contrib = 0.0; + #endif #ifndef OutLoopSetup @@ -15,5 +14,7 @@ int count = (int)_PlayerCount; \ \ float4 dmax = float4(0,0,0,1); \ - float dIntensity = 0; \ + float dIntensity = 0; + + #endif \ No newline at end of file diff --git a/Shader/Includes/Variables.hlsl b/Shader/Includes/Variables.hlsl index c994e75..bbdf1e2 100644 --- a/Shader/Includes/Variables.hlsl +++ b/Shader/Includes/Variables.hlsl @@ -10,4 +10,5 @@ float _LightType[MAX_LIGHTS]; /* 0 = sphere, 1 = cone */ \ float _PlayerCount; /* set via SetFloat */ \ \ + #endif \ No newline at end of file diff --git a/Shader/Includes/Variables.hlsl.meta b/Shader/Includes/Variables.hlsl.meta new file mode 100644 index 0000000..d5c5ed0 --- /dev/null +++ b/Shader/Includes/Variables.hlsl.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c46c91c88f0f9954b9d65378c73103a5 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Shader/Water.shader b/Shader/Water.shader index 5c318b6..36e9e83 100644 --- a/Shader/Water.shader +++ b/Shader/Water.shader @@ -146,7 +146,7 @@ Shader "DeMuenu/World/Hoppou/Water" //Moonlight float3 N = normalize(i.worldNormal + NormalOffset1 * _NormalMapStrength1 + NormalOffset2 * _NormalMapStrength2 + Wave * _WaveScale); //for lambertian diffuse - + //Waterspecific float3 V = normalize(_WorldSpaceCameraPos - i.worldPos); @@ -162,7 +162,7 @@ Shader "DeMuenu/World/Hoppou/Water" Lambert(_LightPositions[LightCounter].xyz ,i, N); - LightTypeCalculations(_LightColors, LightCounter, i, NdotL, dIntensity, _LightPositions[LightCounter].a, _LightPositions[LightCounter].xyz); + LightTypeCalculations(_LightColors, LightCounter, i, 1, dIntensity, _LightPositions[LightCounter].a, _LightPositions[LightCounter].xyz); @@ -185,7 +185,7 @@ Shader "DeMuenu/World/Hoppou/Water" float fres = SchlickFresnel(NoV, _F0, _FresnelPower); dmax.w = 1.0; - dmax.a = dmax.a * _ReflectionStrength * fres; + dmax.a = dmax.a * _ReflectionStrength * fres; //Moonlight END diff --git a/Shader/WaterParticle.shader b/Shader/WaterParticle.shader new file mode 100644 index 0000000..097aba7 --- /dev/null +++ b/Shader/WaterParticle.shader @@ -0,0 +1,62 @@ +Shader "DeMuenu/World/Hoppou/WaterParticle" +{ + Properties + { + _MainTex ("Texture", 2D) = "white" {} + _AlphaMap ("Alpha Map", 2D) = "white" {} + _Color ("Tint", Color) = (1,1,1,1) + } + SubShader + { + Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" } + Blend SrcAlpha OneMinusSrcAlpha // normal alpha blend (not additive) + ZWrite Off + Lighting Off + Cull Off + LOD 100 + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #include "UnityCG.cginc" + + struct appdata + { + float4 vertex : POSITION; + float2 uv : TEXCOORD0; + float4 color : COLOR; + }; + + struct v2f + { + float2 uv : TEXCOORD0; + float4 vertex : SV_POSITION; + float4 color : COLOR; + }; + + sampler2D _MainTex; + float4 _MainTex_ST; + sampler2D _AlphaMap; + fixed4 _Color; + + v2f vert (appdata v) + { + v2f o; + o.vertex = UnityObjectToClipPos(v.vertex); + o.uv = TRANSFORM_TEX(v.uv, _MainTex); + o.color = v.color; + return o; + } + + fixed4 frag (v2f i) : SV_Target + { + fixed4 col = tex2D(_MainTex, i.uv) * _Color; + float alpha = tex2D(_AlphaMap, i.uv).r; + return col * alpha * i.color; // col.a drives the blend + } + ENDCG + } + } +} diff --git a/Shader/WaterParticle.shader.meta b/Shader/WaterParticle.shader.meta new file mode 100644 index 0000000..55d9267 --- /dev/null +++ b/Shader/WaterParticle.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 257e74905e73c3a40bcd4a4b35d3d647 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: