mirror of
https://github.com/DeMuenu/MoonlightVRC.git
synced 2025-12-13 11:33:54 +00:00
Initial commit
This commit is contained in:
190
Shader/BlendinShader.shader
Normal file
190
Shader/BlendinShader.shader
Normal file
@@ -0,0 +1,190 @@
|
||||
Shader "DeMuenu/World/Hoppou/RevealStandart"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_MultTex ("Multiply Texture", 2D) = "white" {}
|
||||
_MultiplicatorTex ("Multiply Texture Strength", Range(0,3)) = 0
|
||||
_Color ("Color", Color) = (1,1,1,1)
|
||||
|
||||
_EmmisiveText ("Emmissive Texture", 2D) = "white" {}
|
||||
_EmmissiveColor ("Emmissive Color", Color) = (1,1,1,1)
|
||||
_EmmissiveStrength ("Emmissive Strength", Range(0,10)) = 0
|
||||
|
||||
|
||||
//MoonsLight
|
||||
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
||||
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
||||
//MoonsLight END
|
||||
|
||||
|
||||
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
//MoonsLight Defines
|
||||
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
||||
//MoonsLight Defines END
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float3 normal : NORMAL;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uv2 : TEXCOORD1;
|
||||
float2 uvEmmis : TEXCOORD4;
|
||||
//UNITY_FOG_COORDS(1)
|
||||
float4 vertex : SV_POSITION;
|
||||
|
||||
//MoonsLight
|
||||
float3 worldPos : TEXCOORD2;
|
||||
float3 worldNormal: TEXCOORD3;
|
||||
|
||||
//MoonsLight END
|
||||
|
||||
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
sampler2D _MultTex;
|
||||
float4 _MultTex_ST;
|
||||
float _MultiplicatorTex;
|
||||
float4 _Color;
|
||||
|
||||
|
||||
sampler2D _EmmisiveText;
|
||||
float4 _EmmisiveText_ST;
|
||||
float4 _EmmissiveColor;
|
||||
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
|
||||
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
o.uv2 = TRANSFORM_TEX(v.uv, _MultTex);
|
||||
o.uvEmmis = TRANSFORM_TEX(v.uv, _EmmisiveText);
|
||||
|
||||
|
||||
//MoonsLight Vertex
|
||||
float4 wp = mul(unity_ObjectToWorld, v.vertex);
|
||||
o.worldPos = wp.xyz;
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
//MoonsLight Vertex END
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
// sample the texture
|
||||
fixed4 col = tex2D(_MainTex, i.uv);
|
||||
fixed4 mult = tex2D(_MultTex, i.uv2);
|
||||
col = lerp(col, mult, _MultiplicatorTex);
|
||||
fixed4 emmis = tex2D(_EmmisiveText, i.uvEmmis);
|
||||
|
||||
|
||||
//MoonsLight
|
||||
int count = (int)_PlayerCount;
|
||||
|
||||
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++)
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
return col * _Color * dmax + emmis * _EmmissiveStrength * _EmmissiveColor;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
FallBack "Diffuse"
|
||||
}
|
||||
9
Shader/BlendinShader.shader.meta
Normal file
9
Shader/BlendinShader.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10b36b8f1c13f5947ba9527616152cdb
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
83
Shader/GhostWhiteShader.shader
Normal file
83
Shader/GhostWhiteShader.shader
Normal file
@@ -0,0 +1,83 @@
|
||||
Shader "DeMuenu/World/Hoppou/GhostWhite"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_Color ("Color", Color) = (1,1,1,1)
|
||||
_EmmissiveColor ("Emmissive Color", Color) = (1,1,1,1)
|
||||
_EmmissiveStrength ("Emmissive Strength", Range(0,10)) = 0
|
||||
|
||||
_BaseColor ("Base Color", Color) = (0.06,0.08,0.1,1)
|
||||
_FresnelColor ("Fresnel Color", Color) = (0.3,0.7,1,1)
|
||||
_Power ("Fresnel Power", Range(0.1, 8)) = 3
|
||||
_Intensity ("Fresnel Intensity", Range(0, 4)) = 1
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Opaque" }
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
// make fog work
|
||||
#pragma multi_compile_fog
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float3 normal : NORMAL;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
float3 worldNormal : TEXCOORD2;
|
||||
float3 worldViewDir : TEXCOORD1;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
fixed4 _Color;
|
||||
fixed4 _EmmissiveColor;
|
||||
float _EmmissiveStrength;
|
||||
fixed4 _BaseColor, _FresnelColor;
|
||||
float _Power, _Intensity;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
|
||||
o.worldViewDir = _WorldSpaceCameraPos - worldPos;
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
float3 N = normalize(i.worldNormal);
|
||||
float3 V = normalize(i.worldViewDir);
|
||||
// Schlick-style rim: (1 - N·V)^power
|
||||
float fresnel = pow(1.0 - saturate(dot(N, V)), _Power);
|
||||
|
||||
// sample the texture
|
||||
fixed4 col = tex2D(_MainTex, i.uv) * _Color ;
|
||||
|
||||
|
||||
col = float4(col.rgb + _FresnelColor.rgb * (fresnel * _Intensity), 1);
|
||||
|
||||
// apply fog
|
||||
return col + (_EmmissiveColor * _EmmissiveStrength);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Shader/GhostWhiteShader.shader.meta
Normal file
9
Shader/GhostWhiteShader.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0914d1e38b9fb9748b943666168cb363
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
186
Shader/LitParticles.shader
Normal file
186
Shader/LitParticles.shader
Normal file
@@ -0,0 +1,186 @@
|
||||
Shader "DeMuenu/World/Hoppou/Particles/LitParticles"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_Color ("Color", Color) = (1,1,1,1)
|
||||
|
||||
|
||||
//MoonsLight
|
||||
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
||||
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
||||
//MoonsLight END
|
||||
|
||||
|
||||
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
|
||||
Blend SrcAlpha One
|
||||
Cull Off
|
||||
Lighting Off
|
||||
ZWrite Off
|
||||
LOD 100
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
|
||||
float4 color : COLOR;
|
||||
|
||||
float3 normal : NORMAL;
|
||||
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
//MoonsLight
|
||||
float3 worldPos : TEXCOORD2;
|
||||
|
||||
float4 color : COLOR;
|
||||
|
||||
float3 worldNormal: TEXCOORD3;
|
||||
//MoonsLight END
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
sampler2D _MultTex;
|
||||
float4 _MultTex_ST;
|
||||
float4 _Color;
|
||||
|
||||
|
||||
sampler2D _EmmisiveText;
|
||||
float4 _EmmisiveText_ST;
|
||||
float4 _EmmissiveColor;
|
||||
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
|
||||
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
|
||||
|
||||
//MoonsLight
|
||||
float4 wp = mul(unity_ObjectToWorld, v.vertex);
|
||||
o.worldPos = wp.xyz;
|
||||
o.color = v.color;
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
//MoonsLight END
|
||||
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
// sample the texture
|
||||
fixed4 col = tex2D(_MainTex, i.uv);
|
||||
|
||||
|
||||
//MoonsLight
|
||||
int count = (int)_PlayerCount;
|
||||
|
||||
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++)
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
return col * _Color * min(dmax, 1.0) * i.color;
|
||||
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
FallBack "Diffuse"
|
||||
}
|
||||
9
Shader/LitParticles.shader.meta
Normal file
9
Shader/LitParticles.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ee874bc1f0a27c4caf078bd17d5c0c7
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
90
Shader/MoonsLight.cingc
Normal file
90
Shader/MoonsLight.cingc
Normal file
@@ -0,0 +1,90 @@
|
||||
#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
|
||||
7
Shader/MoonsLight.cingc.meta
Normal file
7
Shader/MoonsLight.cingc.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76476ee372212af4e9094c2e42bc3cc5
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
216
Shader/Water.shader
Normal file
216
Shader/Water.shader
Normal file
@@ -0,0 +1,216 @@
|
||||
Shader "DeMuenu/World/Hoppou/Water"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_Color ("Color", Color) = (1,1,1,0.5)
|
||||
_NormalMap ("Normal Map", 2D) = "bump" {}
|
||||
_NormalMapStrength1 ("Normal Map Strength", Range(0,1)) = 1
|
||||
_NormalMapStrength2 ("Normal Map Strength 2", Range(0,1)) = 0.5
|
||||
_NormalMap2Tiling ("Normal Map 2 Tiling", Float) = 2
|
||||
_NormalMapScrollSpeed ("Normal Map Scroll Speed", Float) = 0.1
|
||||
_NormalMapScrollSpeed2 ("Normal Map 2 Scroll Speed", Float) = 0.05
|
||||
|
||||
//MoonsLight
|
||||
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
||||
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
||||
|
||||
_SpecPower ("Spec Power", Range(4,256)) = 64
|
||||
_SpecIntensity ("Spec Intensity", Range(0,10)) = 1
|
||||
_AmbientFloor ("Ambient Floor", Range(0,1)) = 0.08
|
||||
|
||||
_F0 ("F0", Range(0,1)) = 0.02
|
||||
_FresnelPower ("Fresnel Power", Range(1,8)) = 5
|
||||
_ReflectionStrength ("Reflection Strength", Range(0,1)) = 0.7
|
||||
//MoonsLight END
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
|
||||
LOD 100
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
//MoonsLight Defines
|
||||
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
||||
//MoonsLight Defines END
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float3 normal : NORMAL;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uvnorm : TEXCOORD1;
|
||||
float4 vertex : SV_POSITION;
|
||||
|
||||
//MoonsLight
|
||||
float3 worldPos : TEXCOORD2;
|
||||
float3 worldNormal: TEXCOORD3;
|
||||
//MoonsLight END
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
float4 _Color;
|
||||
sampler2D _NormalMap;
|
||||
float4 _NormalMap_ST;
|
||||
float _NormalMapStrength1;
|
||||
float _NormalMapStrength2;
|
||||
float _NormalMap2Tiling;
|
||||
float _NormalMapScrollSpeed;
|
||||
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
|
||||
|
||||
//Watershader specific
|
||||
float _SpecPower, _SpecIntensity;
|
||||
float3 _AmbientFloor;
|
||||
|
||||
|
||||
float _F0, _FresnelPower, _ReflectionStrength;
|
||||
|
||||
inline float SchlickFresnel(float NoV, float F0, float power)
|
||||
{
|
||||
float f = pow(saturate(1.0 - NoV), power);
|
||||
return saturate(F0 + (1.0 - F0) * f);
|
||||
}
|
||||
//MoonsLight variables END
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
o.uvnorm = TRANSFORM_TEX(v.uv, _NormalMap);
|
||||
//MoonsLight Vertex
|
||||
float4 wp = mul(unity_ObjectToWorld, v.vertex);
|
||||
o.worldPos = wp.xyz;
|
||||
o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
//MoonsLight Vertex END
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
// sample the texture
|
||||
fixed4 col = tex2D(_MainTex, i.uv);
|
||||
fixed4 norm = tex2D(_NormalMap, i.uvnorm + float2(0, _NormalMapScrollSpeed * sin(_Time.y)));
|
||||
fixed4 norm2 = tex2D(_NormalMap, i.uvnorm * _NormalMap2Tiling + float2(_NormalMapScrollSpeed2 * sin(_Time.y), 0));
|
||||
float3 NormalOffset1 = UnpackNormal(norm).xyz;
|
||||
float3 NormalOffset2 = UnpackNormal(norm2).xyz;
|
||||
|
||||
//MoonsLight
|
||||
int count = (int)_PlayerCount;
|
||||
|
||||
float3 N = normalize(i.worldNormal + NormalOffset1 * _NormalMapStrength1 + NormalOffset2 * _NormalMapStrength2); //for lambertian diffuse
|
||||
|
||||
|
||||
//Waterspecific
|
||||
float3 V = normalize(_WorldSpaceCameraPos - i.worldPos);
|
||||
float3 R = reflect(-V, N); //for reflection vector
|
||||
//Waterspecific END
|
||||
//return float4(R,1);
|
||||
|
||||
|
||||
|
||||
|
||||
// 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++)
|
||||
{
|
||||
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;
|
||||
|
||||
//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.a -= _SpecIntensity * spec;
|
||||
//dmax = dmax + contrib * float4(LightColor, 1); // accumulate light contributions
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//dmax.xyz = min(dmax * dIntensity, 1.0);
|
||||
|
||||
float NoV = saturate(dot(N, V));
|
||||
float fres = SchlickFresnel(NoV, _F0, _FresnelPower);
|
||||
|
||||
dmax.w = 1.0;
|
||||
dmax.a = dmax.a * _ReflectionStrength * fres;
|
||||
|
||||
|
||||
//MoonsLight END
|
||||
|
||||
|
||||
|
||||
// Final color
|
||||
return col * _Color * dmax ;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Shader/Water.shader.meta
Normal file
9
Shader/Water.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b99615b9af356d248a6940b9961c417a
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user