Refactor Moonlight lighting system in shaders

Replaces direct variable declarations and code blocks related to 'MoonsLight' with a new 'MoonlightGlobalVariables' macro included from Variables.hlsl. Adds OutLoopSetup macro for loop setup, updates all relevant shaders to use the new macros, and renames comments and identifiers from 'MoonsLight' to 'Moonlight' for consistency. Removes the obsolete MoonsLight.cingc include and its meta file.
This commit is contained in:
DeMuenu
2025-09-25 16:09:24 +02:00
parent 07730827f4
commit 0f049de062
7 changed files with 64 additions and 195 deletions

View File

@@ -6,10 +6,10 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
_Color ("Color", Color) = (1,1,1,1)
//MoonsLight
//Moonlight
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
//MoonsLight END
//Moonlight END
@@ -35,6 +35,7 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
#include "Includes/LightStrength.hlsl"
#include "Includes/Lambert.hlsl"
#include "Includes/DefaultSetup.hlsl"
#include "Includes/Variables.hlsl"
@@ -53,13 +54,13 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
//MoonsLight
//Moonlight
float3 worldPos : TEXCOORD2;
float4 color : COLOR;
float3 worldNormal: TEXCOORD3;
//MoonsLight END
//Moonlight END
};
sampler2D _MainTex;
@@ -75,16 +76,7 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
float _EmmissiveStrength;
//MoonsLight
float _InverseSqareMultiplier;
float _LightCutoffDistance;
float4 _LightPositions[MAX_LIGHTS]; // xyz = position
float4 _LightColors[MAX_LIGHTS]; // xyz = position
float4 _LightDirections[MAX_LIGHTS]; // xyz = direction, w = cos(halfAngle)
float _LightType[MAX_LIGHTS]; // 0 = sphere, 1 = cone
float _PlayerCount; // set via SetFloat
//MoonsLight END
MoonlightGlobalVariables
v2f vert (appdata v)
@@ -94,12 +86,12 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
//MoonsLight
//Moonlight
float4 wp = mul(unity_ObjectToWorld, v.vertex);
o.worldPos = wp.xyz;
o.color = v.color;
o.worldNormal = UnityObjectToWorldNormal(v.normal);
//MoonsLight END
//Moonlight END
return o;
@@ -111,13 +103,11 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
fixed4 col = tex2D(_MainTex, i.uv);
//MoonsLight
int count = (int)_PlayerCount;
//Moonlight
float3 N = normalize(i.worldNormal); /*for lambertian diffuse*/
float3 N = normalize(i.worldNormal); //for lambertian diffuse
// Example: compute distance to nearest player
float4 dmax = float4(0,0,0,1);
float dIntensity = 0;
OutLoopSetup(i, _PlayerCount) //defines count, N, dmax, dIntensity
[loop]
for (int LightCounter = 0; LightCounter < MAX_LIGHTS; LightCounter++)
{
@@ -128,24 +118,14 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
LightTypeCalculations(_LightColors, LightCounter, i, NdotL, dIntensity, _LightPositions[LightCounter].a, _LightPositions[LightCounter].xyz);
dmax = dmax + contrib * float4(LightColor, 1) * NdotL; // accumulate light contributions
}
//dmax.xyz = min(dmax * dIntensity, 1.0);
dmax.w = 1.0;
dmax = dmax;
//MoonsLight END
//Moonlight END
return col * _Color * min(dmax, 1.0) * i.color;