mirror of
https://github.com/DeMuenu/MoonlightVRC.git
synced 2025-12-12 19:13:56 +00:00
7
README.md.meta
Normal file
7
README.md.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93fa212d3a1466d4aa137657d2a1a25e
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -12,10 +12,10 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
||||
_EmmissiveStrength ("Emmissive Strength", Range(0,10)) = 0
|
||||
|
||||
|
||||
//MoonsLight
|
||||
//Moonlight
|
||||
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
||||
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
||||
//MoonsLight END
|
||||
//Moonlight END
|
||||
|
||||
|
||||
|
||||
@@ -32,10 +32,14 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Includes/LightStrength.hlsl"
|
||||
#include "Includes/Lambert.hlsl"
|
||||
#include "Includes/DefaultSetup.hlsl"
|
||||
#include "Includes/Variables.hlsl"
|
||||
|
||||
//MoonsLight Defines
|
||||
//Moonlight Defines
|
||||
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
||||
//MoonsLight Defines END
|
||||
//Moonlight Defines END
|
||||
|
||||
struct appdata
|
||||
{
|
||||
@@ -52,11 +56,11 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
||||
//UNITY_FOG_COORDS(1)
|
||||
float4 vertex : SV_POSITION;
|
||||
|
||||
//MoonsLight
|
||||
//Moonlight
|
||||
float3 worldPos : TEXCOORD2;
|
||||
float3 worldNormal: TEXCOORD3;
|
||||
|
||||
//MoonsLight END
|
||||
//Moonlight END
|
||||
|
||||
|
||||
};
|
||||
@@ -75,16 +79,7 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
||||
float _EmmissiveStrength;
|
||||
|
||||
|
||||
//MoonsLight variables
|
||||
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 variables END
|
||||
MoonlightGlobalVariables
|
||||
|
||||
|
||||
v2f vert (appdata v)
|
||||
@@ -96,11 +91,11 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
||||
o.uvEmmis = TRANSFORM_TEX(v.uv, _EmmisiveText);
|
||||
|
||||
|
||||
//MoonsLight Vertex
|
||||
//Moonlight Vertex
|
||||
float4 wp = mul(unity_ObjectToWorld, v.vertex);
|
||||
o.worldPos = wp.xyz;
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
//MoonsLight Vertex END
|
||||
//Moonlight Vertex END
|
||||
|
||||
return o;
|
||||
}
|
||||
@@ -114,71 +109,30 @@ Shader "DeMuenu/World/Hoppou/RevealStandart"
|
||||
fixed4 emmis = tex2D(_EmmisiveText, i.uvEmmis);
|
||||
|
||||
|
||||
//MoonsLight
|
||||
int count = (int)_PlayerCount;
|
||||
//Moonlight
|
||||
float3 N = normalize(i.worldNormal); /*for lambertian diffuse*/
|
||||
|
||||
OutLoopSetup(i, _PlayerCount) //defines count, N, dmax, dIntensity
|
||||
|
||||
float3 N = normalize(i.worldNormal); //for lambertian diffuse
|
||||
// Example: compute distance to nearest player
|
||||
float4 dmax = float4(0,0,0,1);
|
||||
float dIntensity = 0;
|
||||
[loop]
|
||||
for (int idx = 0; idx < MAX_LIGHTS; idx++)
|
||||
for (int LightCounter = 0; LightCounter < MAX_LIGHTS; LightCounter++)
|
||||
{
|
||||
if (idx >= count) break;
|
||||
float radius = _LightPositions[idx].a;
|
||||
float3 q = _LightPositions[idx].xyz;
|
||||
|
||||
float distanceFromLight = length(i.worldPos - q);
|
||||
if (distanceFromLight > _LightCutoffDistance) continue;
|
||||
|
||||
float sd = 0.0;
|
||||
float contrib = 0.0;
|
||||
|
||||
|
||||
float invSqMul = max(1e-4, _InverseSqareMultiplier);
|
||||
InLoopSetup(_LightPositions, LightCounter, count, i); //defines distanceFromLight, contrib
|
||||
|
||||
|
||||
//Lambertian diffuse
|
||||
float3 L = normalize(q - i.worldPos); // q = light position
|
||||
float NdotL = saturate(dot(N, L) * 0.5 + 0.5); // one-sided Lambert
|
||||
if (NdotL <= 0) continue;
|
||||
|
||||
if(_LightType[idx] == 0)
|
||||
{
|
||||
float invSq = _LightColors[idx].a / max(1e-4, max(0, max(1, distanceFromLight - radius) * invSqMul) * max(0, max(1, distanceFromLight - radius) * invSqMul));
|
||||
contrib = invSq;
|
||||
//contrib = contrib * step(-distance(i.worldPos, q), -1 + radius * 1); // 0 if outside sphere
|
||||
dIntensity += contrib * NdotL;
|
||||
}
|
||||
else if (_LightType[idx] == 1)
|
||||
{
|
||||
float invSq = _LightColors[idx].a / max(1e-4, (distanceFromLight * invSqMul) * (distanceFromLight * invSqMul));
|
||||
float threshold = (-1 + _LightDirections[idx].w / 180);
|
||||
|
||||
contrib = min(dot(normalize(i.worldPos - q), -normalize(_LightDirections[idx].xyz)), 0);
|
||||
contrib= 1 - step(threshold, contrib);
|
||||
|
||||
contrib = contrib * invSq;
|
||||
dIntensity += contrib * NdotL;
|
||||
}
|
||||
float3 LightColor = _LightColors[idx].xyz; // * NormalDirMult;
|
||||
|
||||
Lambert(_LightPositions[LightCounter].xyz ,i, N); //defines NdotL
|
||||
|
||||
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 * dmax + emmis * _EmmissiveStrength * _EmmissiveColor;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76476ee372212af4e9094c2e42bc3cc5
|
||||
guid: d8ef6797851b2e446a3f1febe3a82d75
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
20
Shader/Includes/DefaultSetup.hlsl
Normal file
20
Shader/Includes/DefaultSetup.hlsl
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef InLoopSetup
|
||||
#define InLoopSetup(_LightPositions, LightCounter, count, i) \
|
||||
if (LightCounter >= count) break; \
|
||||
\
|
||||
float distanceFromLight = length(i.worldPos - _LightPositions[LightCounter].xyz); \
|
||||
if (distanceFromLight > _LightCutoffDistance) continue; \
|
||||
\
|
||||
float contrib = 0.0;
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef OutLoopSetup
|
||||
#define OutLoopSetup(i, _PlayerCount) \
|
||||
int count = (int)_PlayerCount; \
|
||||
\
|
||||
float4 dmax = float4(0,0,0,1); \
|
||||
float dIntensity = 0;
|
||||
|
||||
|
||||
#endif
|
||||
7
Shader/Includes/DefaultSetup.hlsl.meta
Normal file
7
Shader/Includes/DefaultSetup.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40344ee82b97c734b9f8cd0ce21e57a7
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
7
Shader/Includes/Lambert.hlsl
Normal file
7
Shader/Includes/Lambert.hlsl
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef Lambert
|
||||
#define Lambert(q ,i, N) \
|
||||
float3 L = normalize(q - i.worldPos); /* q = light position */ \
|
||||
float NdotL = saturate(dot(N, L) * 0.5 + 0.5); /* one-sided Lambert */ \
|
||||
if (NdotL <= 0) continue; \
|
||||
|
||||
#endif
|
||||
7
Shader/Includes/Lambert.hlsl.meta
Normal file
7
Shader/Includes/Lambert.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 095e42d7e6cefba45aaf73b9994b97a6
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Shader/Includes/LightStrength.hlsl
Normal file
25
Shader/Includes/LightStrength.hlsl
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef LightTypeCalculations
|
||||
#define LightTypeCalculations(_LightColors ,LightCounter, i, NdotL, dIntensity, radius, Lightposition) \
|
||||
float invSqMul = max(1e-4, _InverseSqareMultiplier); \
|
||||
\
|
||||
if(_LightType[LightCounter] == 0) \
|
||||
{ \
|
||||
contrib = _LightColors[LightCounter].a / max(1e-4, max(0, max(1, distanceFromLight - radius) * invSqMul) * max(0, max(1, distanceFromLight - radius) * invSqMul)); \
|
||||
\
|
||||
dIntensity += contrib * NdotL; \
|
||||
} \
|
||||
else if (_LightType[LightCounter] == 1) \
|
||||
{ \
|
||||
float invSq = _LightColors[LightCounter].a / max(1e-4, (distanceFromLight * invSqMul) * (distanceFromLight * invSqMul)); \
|
||||
float threshold = (-1 + _LightDirections[LightCounter].w / 180); \
|
||||
\
|
||||
contrib = min(dot(normalize(i.worldPos - Lightposition), -normalize(_LightDirections[LightCounter].xyz)), 0); \
|
||||
contrib= 1 - step(threshold, contrib); \
|
||||
\
|
||||
contrib = contrib * invSq; \
|
||||
dIntensity += contrib * NdotL; \
|
||||
} \
|
||||
float3 LightColor = _LightColors[LightCounter].xyz; \
|
||||
|
||||
|
||||
#endif
|
||||
7
Shader/Includes/LightStrength.hlsl.meta
Normal file
7
Shader/Includes/LightStrength.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b5943a3997186745ad720993e483310
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Shader/Includes/Variables.hlsl
Normal file
14
Shader/Includes/Variables.hlsl
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef MoonlightGlobalVariables
|
||||
#define MoonlightGlobalVariables \
|
||||
\
|
||||
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 */ \
|
||||
\
|
||||
|
||||
#endif
|
||||
7
Shader/Includes/Variables.hlsl.meta
Normal file
7
Shader/Includes/Variables.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c46c91c88f0f9954b9d65378c73103a5
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
|
||||
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Includes/LightStrength.hlsl"
|
||||
#include "Includes/Lambert.hlsl"
|
||||
#include "Includes/DefaultSetup.hlsl"
|
||||
#include "Includes/Variables.hlsl"
|
||||
|
||||
|
||||
|
||||
@@ -50,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;
|
||||
@@ -72,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)
|
||||
@@ -91,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;
|
||||
@@ -108,72 +103,29 @@ 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*/
|
||||
|
||||
OutLoopSetup(i, _PlayerCount) //defines count, N, dmax, dIntensity
|
||||
|
||||
float3 N = normalize(i.worldNormal); //for lambertian diffuse
|
||||
// Example: compute distance to nearest player
|
||||
float4 dmax = float4(0,0,0,1);
|
||||
float dIntensity = 0;
|
||||
[loop]
|
||||
for (int idx = 0; idx < MAX_LIGHTS; idx++)
|
||||
for (int LightCounter = 0; LightCounter < MAX_LIGHTS; LightCounter++)
|
||||
{
|
||||
if (idx >= count) break;
|
||||
float radius = _LightPositions[idx].a;
|
||||
float3 q = _LightPositions[idx].xyz;
|
||||
|
||||
float distanceFromLight = length(i.worldPos - q);
|
||||
if (distanceFromLight > _LightCutoffDistance) continue;
|
||||
|
||||
float sd = 0.0;
|
||||
float contrib = 0.0;
|
||||
|
||||
|
||||
float invSqMul = max(1e-4, _InverseSqareMultiplier);
|
||||
|
||||
|
||||
//Lambertian diffuse
|
||||
float3 L = normalize(q - i.worldPos); // q = light position
|
||||
float NdotL = saturate(dot(N, L) * 0.5 + 0.5); // one-sided Lambert
|
||||
if (NdotL <= 0) continue;
|
||||
|
||||
if(_LightType[idx] == 0)
|
||||
{
|
||||
float invSq = _LightColors[idx].a / max(1e-4, max(0, max(1, distanceFromLight - radius) * invSqMul) * max(0, max(1, distanceFromLight - radius) * invSqMul));
|
||||
contrib = invSq;
|
||||
//contrib = contrib * step(-distance(i.worldPos, q), -1 + radius * 1); // 0 if outside sphere
|
||||
dIntensity += contrib * NdotL;
|
||||
}
|
||||
else if (_LightType[idx] == 1)
|
||||
{
|
||||
float invSq = _LightColors[idx].a / max(1e-4, (distanceFromLight * invSqMul) * (distanceFromLight * invSqMul));
|
||||
float threshold = (-1 + _LightDirections[idx].w / 180);
|
||||
|
||||
contrib = min(dot(normalize(i.worldPos - q), -normalize(_LightDirections[idx].xyz)), 0);
|
||||
contrib= 1 - step(threshold, contrib);
|
||||
|
||||
contrib = contrib * invSq;
|
||||
dIntensity += contrib * NdotL;
|
||||
}
|
||||
float3 LightColor = _LightColors[idx].xyz; // * NormalDirMult;
|
||||
InLoopSetup(_LightPositions, LightCounter, count, i); //defines distanceFromLight, contrib
|
||||
|
||||
Lambert(_LightPositions[LightCounter].xyz ,i, N); //defines NdotL
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
#ifndef MOONSLIGHT_INCLUDED
|
||||
#define MOONSLIGHT_INCLUDED
|
||||
|
||||
// You can override this before including if TEXCOORD2 is taken:
|
||||
// #define MOONSLIGHT_TEXCOORD TEXCOORD4
|
||||
#ifndef MOONSLIGHT_TEXCOORD
|
||||
#define MOONSLIGHT_TEXCOORD TEXCOORD2
|
||||
#endif
|
||||
|
||||
// Pick a safe max for your target hardware.
|
||||
#ifndef MAX_LIGHTS
|
||||
#define MAX_LIGHTS 80
|
||||
#endif
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
// ---------- Uniforms (set from script as Global/Material arrays) ----------
|
||||
uniform float4 _LightPositions[MAX_LIGHTS]; // xyz = pos, w = radius
|
||||
uniform float4 _LightColors[MAX_LIGHTS]; // xyz = rgb (not normalized), w = intensity scalar
|
||||
uniform float4 _LightDirections[MAX_LIGHTS]; // xyz = dir, w = half-angle in degrees (cone)
|
||||
uniform float _LightType[MAX_LIGHTS]; // 0 = sphere, 1 = cone
|
||||
uniform float _PlayerCount;
|
||||
|
||||
// ---------- Helpers you can inject into your v2f / vertex ----------
|
||||
#define MOONSLIGHT_V2F_MEMBERS float3 worldPos : MOONSLIGHT_TEXCOORD;
|
||||
|
||||
inline void MoonsLight_FillV2F(float4 vertexOS, out float3 worldPos)
|
||||
{
|
||||
worldPos = mul(unity_ObjectToWorld, vertexOS).xyz;
|
||||
}
|
||||
|
||||
// ---------- Core lighting (return value is 0..1 rgba contribution) ----------
|
||||
inline float4 MoonsLight_Accumulate(float3 worldPos, float3 worldNormal)
|
||||
{
|
||||
float3 N = normalize(worldNormal);
|
||||
float4 accum = float4(0,0,0,1);
|
||||
float dIntensity = 0.0;
|
||||
|
||||
int count = (int)_PlayerCount;
|
||||
|
||||
[loop]
|
||||
for (int idx = 0; idx < MAX_LIGHTS; idx++)
|
||||
{
|
||||
if (idx >= count) break;
|
||||
|
||||
float3 q = _LightPositions[idx].xyz;
|
||||
float radius = _LightPositions[idx].w;
|
||||
|
||||
float3 L = normalize(q - worldPos);
|
||||
float NdotL = saturate(dot(N, L) * 0.5 + 0.5); // one-sided Lambert
|
||||
float contrib = 0.0;
|
||||
|
||||
if (_LightType[idx] == 0.0)
|
||||
{
|
||||
// Sphere (SDF-ish falloff reused from your code)
|
||||
float sd = length(worldPos - q) - radius;
|
||||
sd = lerp(1.0, -sd, step(0.0, sd));
|
||||
contrib = min(1.0, max(max(sd, max(0.01, _LightColors[idx].a) / (sd * sd)), 0.01));
|
||||
dIntensity += contrib * NdotL;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cone (directional spot)
|
||||
float threshold = (-1 + _LightDirections[idx].w / 180.0);
|
||||
contrib = min(dot(normalize(worldPos - q), -normalize(_LightDirections[idx].xyz)), 0.0);
|
||||
contrib = 1.0 - step(threshold, contrib);
|
||||
float distanceFromLight = length(worldPos - q);
|
||||
contrib = min(1.0, contrib * (max(0.01, _LightColors[idx].a) / (distanceFromLight * distanceFromLight)));
|
||||
dIntensity += contrib * NdotL;
|
||||
}
|
||||
|
||||
float3 lightRgb = normalize(_LightColors[idx].xyz);
|
||||
accum += contrib * float4(lightRgb, 1.0);
|
||||
}
|
||||
|
||||
accum.xyz = normalize(accum.xyz);
|
||||
accum.xyz = min(accum.xyz * dIntensity, 1.0);
|
||||
accum.w = 1.0;
|
||||
return min(accum, 1.0);
|
||||
}
|
||||
|
||||
// Optional: reuse your camera-distance fade
|
||||
inline float4 MoonsLight_ApplyDistanceFade(float4 color, float3 worldPos, float distanceFadeMultiplier, float distanceMin)
|
||||
{
|
||||
float dist = length(_WorldSpaceCameraPos.xyz - worldPos) / 100.0;
|
||||
color.xyz *= min(1.0, max(distanceMin, max(0.0, 1.0 - abs(dist) * distanceFadeMultiplier)));
|
||||
return color;
|
||||
}
|
||||
|
||||
#endif // MOONSLIGHT_INCLUDED
|
||||
@@ -11,7 +11,7 @@ Shader "DeMuenu/World/Hoppou/Water"
|
||||
_NormalMapScrollSpeed ("Normal Map Scroll Speed", Float) = 0.1
|
||||
_NormalMapScrollSpeed2 ("Normal Map 2 Scroll Speed", Float) = 0.05
|
||||
|
||||
//MoonsLight
|
||||
//Moonlight
|
||||
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
||||
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
||||
|
||||
@@ -22,7 +22,15 @@ Shader "DeMuenu/World/Hoppou/Water"
|
||||
_F0 ("F0", Range(0,1)) = 0.02
|
||||
_FresnelPower ("Fresnel Power", Range(1,8)) = 5
|
||||
_ReflectionStrength ("Reflection Strength", Range(0,1)) = 0.7
|
||||
//MoonsLight END
|
||||
//Moonlight END
|
||||
|
||||
_WaveInput ("Wave Input", 2D) = "black" {}
|
||||
_WaveTex ("Wave Texture", 2D) = "black" {}
|
||||
_CameraScale ("Camera Scale", Float) = 15
|
||||
_CameraPositionZ ("Camera Position Z", Float) = 0
|
||||
_CameraPositionX ("Camera Position X", Float) = 0
|
||||
|
||||
_WaveScale ("Wave Scale", Range(0.001, 100)) = 1
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
@@ -38,10 +46,14 @@ Shader "DeMuenu/World/Hoppou/Water"
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Includes/LightStrength.hlsl"
|
||||
#include "Includes/Lambert.hlsl"
|
||||
#include "Includes/DefaultSetup.hlsl"
|
||||
#include "Includes/Variables.hlsl"
|
||||
|
||||
//MoonsLight Defines
|
||||
//Moonlight Defines
|
||||
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
||||
//MoonsLight Defines END
|
||||
//Moonlight Defines END
|
||||
|
||||
struct appdata
|
||||
{
|
||||
@@ -56,10 +68,10 @@ Shader "DeMuenu/World/Hoppou/Water"
|
||||
float2 uvnorm : TEXCOORD1;
|
||||
float4 vertex : SV_POSITION;
|
||||
|
||||
//MoonsLight
|
||||
//Moonlight
|
||||
float3 worldPos : TEXCOORD2;
|
||||
float3 worldNormal: TEXCOORD3;
|
||||
//MoonsLight END
|
||||
//Moonlight END
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
@@ -74,20 +86,21 @@ Shader "DeMuenu/World/Hoppou/Water"
|
||||
float _NormalMapScrollSpeed2;
|
||||
|
||||
|
||||
//MoonsLight variables
|
||||
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
|
||||
MoonlightGlobalVariables
|
||||
|
||||
//Watershader specific
|
||||
float _SpecPower, _SpecIntensity;
|
||||
float3 _AmbientFloor;
|
||||
|
||||
sampler2D _WaveInput;
|
||||
sampler2D _WaveTex;
|
||||
float2 _WaveTex_ST;
|
||||
float _CameraScale;
|
||||
float _CameraPositionZ;
|
||||
float _CameraPositionX;
|
||||
float _WaveScale;
|
||||
//Watershader specific END
|
||||
|
||||
|
||||
float _F0, _FresnelPower, _ReflectionStrength;
|
||||
|
||||
@@ -96,7 +109,7 @@ Shader "DeMuenu/World/Hoppou/Water"
|
||||
float f = pow(saturate(1.0 - NoV), power);
|
||||
return saturate(F0 + (1.0 - F0) * f);
|
||||
}
|
||||
//MoonsLight variables END
|
||||
//Moonlight variables END
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
@@ -104,11 +117,11 @@ Shader "DeMuenu/World/Hoppou/Water"
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
o.uvnorm = TRANSFORM_TEX(v.uv, _NormalMap);
|
||||
//MoonsLight Vertex
|
||||
//Moonlight Vertex
|
||||
float4 wp = mul(unity_ObjectToWorld, v.vertex);
|
||||
o.worldPos = wp.xyz;
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
//MoonsLight Vertex END
|
||||
//Moonlight Vertex END
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -121,72 +134,44 @@ Shader "DeMuenu/World/Hoppou/Water"
|
||||
float3 NormalOffset1 = UnpackNormal(norm).xyz;
|
||||
float3 NormalOffset2 = UnpackNormal(norm2).xyz;
|
||||
|
||||
//MoonsLight
|
||||
int count = (int)_PlayerCount;
|
||||
float2 waveUV = float2(_CameraPositionX - i.worldPos.x, _CameraPositionZ - i.worldPos.z) / _CameraScale / 2 + 0.5;
|
||||
fixed4 Wave = tex2D(_WaveInput, waveUV);
|
||||
if ((waveUV.x < 0.1) || (waveUV.x > 0.9) || (waveUV.y < 0.1) || (waveUV.y > 0.9)){
|
||||
Wave = float4(0,0,0,0);
|
||||
}
|
||||
|
||||
float3 N = normalize(i.worldNormal + NormalOffset1 * _NormalMapStrength1 + NormalOffset2 * _NormalMapStrength2); //for lambertian diffuse
|
||||
//i.vertex += float4(0, Wave.g * _WaveScale, 0, 0);
|
||||
//i.worldPos += float3(0, Wave.g * _WaveScale, 0);
|
||||
|
||||
|
||||
//Moonlight
|
||||
float3 N = normalize(i.worldNormal + NormalOffset1 * _NormalMapStrength1 + NormalOffset2 * _NormalMapStrength2 + Wave * _WaveScale); //for lambertian diffuse
|
||||
|
||||
|
||||
//Waterspecific
|
||||
float3 V = normalize(_WorldSpaceCameraPos - i.worldPos);
|
||||
float3 R = reflect(-V, N); //for reflection vector
|
||||
//Waterspecific END
|
||||
//return float4(R,1);
|
||||
|
||||
OutLoopSetup(i, _PlayerCount) //defines count, N, dmax, dIntensity
|
||||
|
||||
|
||||
|
||||
// Example: compute distance to nearest player
|
||||
float4 dmax = float4(0,0,0,1);
|
||||
float dIntensity = 0;
|
||||
[loop]
|
||||
for (int idx = 0; idx < MAX_LIGHTS; idx++)
|
||||
for (int LightCounter = 0; LightCounter < MAX_LIGHTS; LightCounter++)
|
||||
{
|
||||
if (idx >= count) break;
|
||||
float radius = _LightPositions[idx].a;
|
||||
float3 q = _LightPositions[idx].xyz;
|
||||
InLoopSetup(_LightPositions, LightCounter, count, i); //defines distanceFromLight, contrib
|
||||
|
||||
float distanceFromLight = length(i.worldPos - q);
|
||||
if (distanceFromLight > _LightCutoffDistance) continue;
|
||||
Lambert(_LightPositions[LightCounter].xyz ,i, N);
|
||||
|
||||
float sd = 0.0;
|
||||
float contrib = 0.0;
|
||||
LightTypeCalculations(_LightColors, LightCounter, i, 1, dIntensity, _LightPositions[LightCounter].a, _LightPositions[LightCounter].xyz);
|
||||
|
||||
|
||||
float invSqMul = max(1e-4, _InverseSqareMultiplier);
|
||||
|
||||
|
||||
//Lambertian diffuse
|
||||
float3 L = normalize(q - i.worldPos); // q = light position
|
||||
float NdotL = saturate(dot(N, L) * 0.5 + 0.5); // one-sided Lambert
|
||||
if (NdotL <= 0) continue;
|
||||
|
||||
if(_LightType[idx] == 0)
|
||||
{
|
||||
float invSq = _LightColors[idx].a / max(1e-4, max(0, max(1, distanceFromLight - radius) * invSqMul) * max(0, max(1, distanceFromLight - radius) * invSqMul));
|
||||
contrib = invSq;
|
||||
//contrib = contrib * step(-distance(i.worldPos, q), -1 + radius * 1); // 0 if outside sphere
|
||||
dIntensity += contrib * NdotL;
|
||||
}
|
||||
else if (_LightType[idx] == 1)
|
||||
{
|
||||
float invSq = _LightColors[idx].a / max(1e-4, (distanceFromLight * invSqMul) * (distanceFromLight * invSqMul));
|
||||
float threshold = (-1 + _LightDirections[idx].w / 180);
|
||||
|
||||
contrib = min(dot(normalize(i.worldPos - q), -normalize(_LightDirections[idx].xyz)), 0);
|
||||
contrib= 1 - step(threshold, contrib);
|
||||
|
||||
contrib = contrib * invSq;
|
||||
dIntensity += contrib * NdotL;
|
||||
}
|
||||
float3 LightColor = _LightColors[idx].xyz; // * NormalDirMult;
|
||||
|
||||
//Watershader specific
|
||||
//float fres = Schlick(saturate(dot(N, V)), _F0, _FresnelPower);
|
||||
float3 R = reflect(-V, N);
|
||||
float spec = pow(saturate(dot(R, L)), _SpecPower);
|
||||
//return float4(spec, spec, spec,1);
|
||||
dmax.rgb += _LightColors[idx].rgb * contrib + _LightColors[idx].rgb * _SpecIntensity * spec * contrib;
|
||||
dmax.rgb += _LightColors[LightCounter].rgb * contrib + _LightColors[LightCounter].rgb * _SpecIntensity * spec * contrib;
|
||||
dmax.a -= _SpecIntensity * spec;
|
||||
//dmax = dmax + contrib * float4(LightColor, 1); // accumulate light contributions
|
||||
|
||||
@@ -202,10 +187,7 @@ Shader "DeMuenu/World/Hoppou/Water"
|
||||
dmax.w = 1.0;
|
||||
dmax.a = dmax.a * _ReflectionStrength * fres;
|
||||
|
||||
|
||||
//MoonsLight END
|
||||
|
||||
|
||||
//Moonlight END
|
||||
|
||||
// Final color
|
||||
return col * _Color * dmax ;
|
||||
|
||||
62
Shader/WaterParticle.shader
Normal file
62
Shader/WaterParticle.shader
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Shader/WaterParticle.shader.meta
Normal file
9
Shader/WaterParticle.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 257e74905e73c3a40bcd4a4b35d3d647
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user