mirror of
https://github.com/DeMuenu/MoonlightVRC.git
synced 2026-06-23 19:31:58 +00:00
Compare commits
9 Commits
a412ae2dc6
...
dbfed4bc44
| Author | SHA1 | Date | |
|---|---|---|---|
| dbfed4bc44 | |||
| be9da3dee1 | |||
| 21bb6193a2 | |||
| 1a30f72010 | |||
| 79ad33c5f3 | |||
| a3f95883be | |||
| 20034f061d | |||
| 08866b359b | |||
| a1e808ad92 |
@@ -85,7 +85,7 @@ public static class LightUpdaterPreview
|
||||
|
||||
static void PushFromBehaviour(LightUpdater src)
|
||||
{
|
||||
int max = Mathf.Max(1, src.maxLights);
|
||||
int max = Mathf.Max(1, LightUpdater.maxLights);
|
||||
EnsureArrays(src, max);
|
||||
|
||||
var c = _cache[src];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Assets/Lighting/Scripts/LightUpdater.Editor.cs
|
||||
#if UNITY_EDITOR
|
||||
#if !COMPILER_UDONSHARP && UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
|
||||
public partial class LightUpdater
|
||||
@@ -21,38 +21,37 @@ public partial class LightUpdater
|
||||
shadowMapIndices = new float[max];
|
||||
count = 0;
|
||||
|
||||
if (otherLightSources == null) return;
|
||||
LightdataStorage[] sceneLights = Object.FindObjectsOfType<LightdataStorage>();
|
||||
|
||||
for (int i = 0; i < otherLightSources.Length && count < max; i++)
|
||||
for (int i = 0; i < sceneLights.Length && count < max; i++)
|
||||
{
|
||||
Transform t = otherLightSources[i];
|
||||
if (t == null || !t.gameObject.activeInHierarchy) continue;
|
||||
LightdataStorage data = sceneLights[i];
|
||||
if (data == null || !data.gameObject.activeInHierarchy) continue;
|
||||
|
||||
LightdataStorage data = t.GetComponent<LightdataStorage>();
|
||||
Transform t = data.transform;
|
||||
|
||||
// w = cosHalfAngle (0 for omni)
|
||||
float cosHalf = (data != null) ? data.GetCosHalfAngle() : 0f;
|
||||
float cosHalf = data.GetCosHalfAngle();
|
||||
|
||||
Vector3 pos = t.position;
|
||||
float range = 0;
|
||||
if (data.lightType == LightType.Sphere)
|
||||
{
|
||||
range = (data != null) ? data.range * t.localScale.x : t.localScale.x;
|
||||
range = data.range * t.localScale.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
range = (data != null) ? Mathf.Cos(Mathf.Deg2Rad * ((data.spotAngleDeg * 0.5f) + Mathf.Max(data.range, 0))): 0f;
|
||||
range = Mathf.Cos(Mathf.Deg2Rad * ((data.spotAngleDeg * 0.5f) + Mathf.Max(data.range, 0)));
|
||||
}
|
||||
|
||||
// rgb = color, a = intensity (packed to match runtime/shader)
|
||||
Vector4 col = (data != null) ? data.GetFinalColor() : new Vector4(1f, 1f, 1f, 1f);
|
||||
float intensity = (data != null) ? data.intensity * t.localScale.x : 1f;
|
||||
|
||||
Vector4 col = data.GetFinalColor();
|
||||
float intensity = data.intensity * t.localScale.x;
|
||||
|
||||
// 0=Omni, 1=Spot, 2=Directional (your custom enum)
|
||||
int typeId = (data != null) ? data.GetTypeId() : 0;
|
||||
int typeId = data.GetTypeId();
|
||||
|
||||
float shIndex = (data != null) ? data.shadowMapIndex : 0f;
|
||||
float shIndex = data.shadowMapIndex;
|
||||
|
||||
Quaternion rot = t.rotation;
|
||||
Vector3 fwd = rot * Vector3.down;
|
||||
|
||||
@@ -12,12 +12,13 @@ What this includes:
|
||||
- Point/spotlights editable at runtime.
|
||||
- A couple of premade shaders (standard, particle).
|
||||
- Premade code handling lights, normals and a Lambertian diffuse.
|
||||
- Shadow caster planes
|
||||
|
||||
Work in progress:
|
||||
- Water shader
|
||||
- Documentation
|
||||
- More performance testing/improvements
|
||||
- Shadow caster planes
|
||||
|
||||
|
||||
Planned:
|
||||
- Support for additive baked light maps and ambient lighting in the standard shader.
|
||||
@@ -36,11 +37,12 @@ On PC, I haven't encountered any frame drops in the editor at all, even with 400
|
||||
|
||||
2. Add the `LightUpdater` component to a GameObject in your scene:
|
||||
- Tweak strength/intensity of the local and remote player if you want them to have an attached light.
|
||||
- Configure the `PlayerShadowMapIndex` if you want players to interact with shadows.
|
||||
|
||||
3. For lights, attach `LightdataStorage` to a Transform and configure:
|
||||
- `range`, `type`, `color`, `intensity`, and `spotAngleDeg`.
|
||||
- `range`, `lightType`, `color`, `intensity`, `spotAngleDeg`, and `shadowMapIndex`.
|
||||
|
||||
4. Add the light transform to your `LightUpdater` component's `otherLightSources` array.
|
||||
4. On your light's `LightdataStorage` component, assign your scene's `LightUpdater` to the `Light Updater` field. This allows lights to be added or removed dynamically at runtime.
|
||||
|
||||
5. Use one of the premade shaders on your material. Or, if you feel like it, use the provided .hlsl/.cginc in your own shader. You just need to copy everything surrounded by Moonlight comments, and apply it at the end of your shader.
|
||||
|
||||
@@ -62,4 +64,4 @@ On PC, I haven't encountered any frame drops in the editor at all, even with 400
|
||||
## Contributing
|
||||
|
||||
If you want to help with development, please contact me on Discord (@demuenu) so we can coordinate our efforts.
|
||||
If your somebody with a education in Computer graphics, I would be even more thankfull for your help. As right now, it's just me with ~1.5 years of messing around in Shaderlab and ChatGPT as my advisor. So I'm sure that there are serious flaws in the codebase :-)
|
||||
If your somebody with a education in Computer graphics, I would be even more thankful for your help. As right now, it's just me with ~1.5 years of messing around in Shaderlab and ChatGPT as my advisor. So I'm sure that there are serious flaws in the codebase :-)
|
||||
|
||||
+59
-14
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System;
|
||||
using UdonSharp;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
@@ -9,9 +10,6 @@ using VRC.SDK3.Rendering;
|
||||
public partial class LightUpdater : UdonSharpBehaviour
|
||||
{
|
||||
[Header("Lightsources")]
|
||||
[Tooltip("Place Transforms here which should also emit Light (attach LightdataStorage to them).")]
|
||||
public Transform[] otherLightSources;
|
||||
|
||||
|
||||
[Header("Strength")]
|
||||
[Tooltip("Local player light range")]
|
||||
@@ -49,9 +47,9 @@ public partial class LightUpdater : UdonSharpBehaviour
|
||||
[Tooltip("float array: shadow map index (0=none, 1-4=shadow map index)")]
|
||||
public string shadowMapIndexProperty = "_Udon_ShadowMapIndex";
|
||||
|
||||
[Header("Max Lights (advanced users)")]
|
||||
[Header("Max Lighetts (advanced users)")]
|
||||
[Tooltip("Hard cap / array size. 80 = default cap")]
|
||||
public int maxLights = 80;
|
||||
public const int maxLights = 80;
|
||||
|
||||
|
||||
|
||||
@@ -68,6 +66,9 @@ public partial class LightUpdater : UdonSharpBehaviour
|
||||
private float[] _ShadowMapArray;
|
||||
private bool _ShadowMap_isDirty = false;
|
||||
|
||||
private LightdataStorage[] _sceneLights = new LightdataStorage[maxLights];
|
||||
private int _sceneLightCount = 0;
|
||||
|
||||
private VRCPlayerApi[] _players;
|
||||
|
||||
|
||||
@@ -84,7 +85,6 @@ public partial class LightUpdater : UdonSharpBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (maxLights < 1) maxLights = 1;
|
||||
|
||||
_positions = new Vector4[maxLights];
|
||||
_lightColors = new Vector4[maxLights];
|
||||
@@ -101,11 +101,56 @@ public partial class LightUpdater : UdonSharpBehaviour
|
||||
UdonID_LightType = VRCShader.PropertyToID(typeProperty);
|
||||
UdonID_ShadowMapIndex = VRCShader.PropertyToID(shadowMapIndexProperty);
|
||||
|
||||
|
||||
UpdateData();
|
||||
PushToRenderers();
|
||||
}
|
||||
|
||||
public void RegisterLight(LightdataStorage light)
|
||||
{
|
||||
if (light == null) return;
|
||||
|
||||
// Prevent duplicates
|
||||
for (int i = 0; i < _sceneLightCount; i++)
|
||||
{
|
||||
if (_sceneLights[i] == light) return;
|
||||
}
|
||||
|
||||
if (_sceneLightCount < _sceneLights.Length)
|
||||
{
|
||||
_sceneLights[_sceneLightCount] = light;
|
||||
_sceneLightCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"[MoonlightVRC] Cannot register new light, scene light limit reached ({_sceneLights.Length})");
|
||||
}
|
||||
}
|
||||
|
||||
public void DeregisterLight(LightdataStorage light)
|
||||
{
|
||||
if (light == null) return;
|
||||
int foundIndex = -1;
|
||||
for (int i = 0; i < _sceneLightCount; i++)
|
||||
{
|
||||
if (_sceneLights[i] == light)
|
||||
{
|
||||
foundIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundIndex != -1)
|
||||
{
|
||||
// Shift elements down to fill the gap
|
||||
for (int i = foundIndex; i < _sceneLightCount - 1; i++)
|
||||
{
|
||||
_sceneLights[i] = _sceneLights[i + 1];
|
||||
}
|
||||
_sceneLightCount--;
|
||||
_sceneLights[_sceneLightCount] = null; // Clear the last element
|
||||
}
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (Time.time < _nextUpdate) return;
|
||||
@@ -154,6 +199,7 @@ public partial class LightUpdater : UdonSharpBehaviour
|
||||
if (_directions[i] != TempDir)
|
||||
{
|
||||
_directions[i] = new Vector4(TempDir.x, TempDir.y, TempDir.z, 10f);
|
||||
_directions[i] = TempDir;
|
||||
_directions_isDirty = true;
|
||||
}
|
||||
|
||||
@@ -201,14 +247,13 @@ public partial class LightUpdater : UdonSharpBehaviour
|
||||
}
|
||||
|
||||
// --- Scene light sources ---
|
||||
if (otherLightSources != null)
|
||||
if (_sceneLights != null)
|
||||
{
|
||||
for (int j = 0; j < otherLightSources.Length && currentCount < maxLights; j++)
|
||||
for (int j = 0; j < _sceneLightCount && currentCount < maxLights; j++)
|
||||
{
|
||||
Transform t = otherLightSources[j];
|
||||
if (t == null || !t.gameObject.activeInHierarchy) continue;
|
||||
|
||||
LightdataStorage data = t.GetComponent<LightdataStorage>();
|
||||
LightdataStorage data = _sceneLights[j];
|
||||
if (data == null || !data.gameObject.activeInHierarchy) continue;
|
||||
Transform t = data.transform;
|
||||
|
||||
Vector3 pos = t.position;
|
||||
float range = (data != null) ? data.range * t.localScale.x: t.localScale.x;
|
||||
@@ -323,7 +368,7 @@ public partial class LightUpdater : UdonSharpBehaviour
|
||||
if (pushShadowMap) VRCShader.SetGlobalFloatArray(UdonID_ShadowMapIndex, _ShadowMapArray);
|
||||
|
||||
VRCShader.SetGlobalFloat(UdonID_LightCount, currentCount);
|
||||
Debug.Log($"[MoonlightVRC] Pushed {currentCount} lights to shader.");
|
||||
//Debug.Log($"[MoonlightVRC] Pushed {currentCount} lights to shader.");
|
||||
|
||||
// Only now mark them clean
|
||||
if (pushPositions) { _positons_isDirty = false; }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using UdonSharp;
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
using VRC.SDKBase;
|
||||
using VRC.Udon;
|
||||
@@ -10,6 +10,10 @@ public enum LightType { Sphere, Spot }
|
||||
[UdonBehaviourSyncMode(BehaviourSyncMode.None)]
|
||||
public class LightdataStorage : UdonSharpBehaviour
|
||||
{
|
||||
[Header("System")]
|
||||
[Tooltip("The main LightUpdater in the scene. This is required for dynamic lights.")]
|
||||
public LightUpdater lightUpdater;
|
||||
|
||||
|
||||
[Header("Type")]
|
||||
[Tooltip("Select the logical light type for this source.")]
|
||||
@@ -36,6 +40,22 @@ public class LightdataStorage : UdonSharpBehaviour
|
||||
[Tooltip("0 = no shadows, 1-4 = shadow map index")]
|
||||
public float shadowMapIndex = 0f; // 0 = no shadows, 1-4 = shadow map index
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (lightUpdater != null)
|
||||
{
|
||||
lightUpdater.RegisterLight(this);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (lightUpdater != null)
|
||||
{
|
||||
lightUpdater.DeregisterLight(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Convert to a Vector4 for your shader upload
|
||||
public Vector4 GetFinalColor()
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
using System.Security.Permissions;
|
||||
using UdonSharp;
|
||||
using UnityEngine;
|
||||
@@ -18,10 +18,30 @@ public class ShadowcasterUpdater : UdonSharpBehaviour
|
||||
|
||||
private MaterialPropertyBlock _mpb;
|
||||
|
||||
private int _propShadowTex;
|
||||
private int _propShadowColor;
|
||||
private int _propOutsideColor;
|
||||
private int _propMinBrightness;
|
||||
private int _propPlaneOrigin;
|
||||
private int _propPlaneUinv;
|
||||
private int _propPlaneVinv;
|
||||
private int _propPlaneNormal;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_mpb = new MaterialPropertyBlock();
|
||||
|
||||
string suf = "_" + shadowcasterIndex.ToString();
|
||||
_propShadowTex = VRCShader.PropertyToID("_Udon_shadowCasterTex" + suf);
|
||||
_propShadowColor = VRCShader.PropertyToID("_Udon_shadowCasterColor" + suf);
|
||||
_propOutsideColor = VRCShader.PropertyToID("_Udon_OutSideColor" + suf);
|
||||
_propMinBrightness = VRCShader.PropertyToID("_Udon_MinBrightnessShadow" + suf);
|
||||
|
||||
_propPlaneOrigin = VRCShader.PropertyToID("_Udon_Plane_Origin" + suf);
|
||||
_propPlaneUinv = VRCShader.PropertyToID("_Udon_Plane_Uinv" + suf);
|
||||
_propPlaneVinv = VRCShader.PropertyToID("_Udon_Plane_Vinv" + suf);
|
||||
_propPlaneNormal = VRCShader.PropertyToID("_Udon_Plane_Normal" + suf);
|
||||
|
||||
ApplyTextureData();
|
||||
}
|
||||
|
||||
@@ -31,43 +51,47 @@ public class ShadowcasterUpdater : UdonSharpBehaviour
|
||||
{
|
||||
if (mat == null) continue;
|
||||
mat.GetPropertyBlock(_mpb);
|
||||
_mpb.SetTexture("_Udon_shadowCasterTex" + "_" + shadowcasterIndex.ToString(), ShadowcasterTexture);
|
||||
_mpb.SetColor("_Udon_shadowCasterColor" + "_" + shadowcasterIndex.ToString(), TextureColor);
|
||||
_mpb.SetColor("_Udon_OutSideColor" + "_" + shadowcasterIndex.ToString(), OutsideColor);
|
||||
_mpb.SetFloat("_Udon_MinBrightnessShadow" + "_" + shadowcasterIndex.ToString(), MinBrightness);
|
||||
if (ShadowcasterTexture != null) _mpb.SetTexture(_propShadowTex, ShadowcasterTexture);
|
||||
_mpb.SetColor(_propShadowColor, TextureColor);
|
||||
_mpb.SetColor(_propOutsideColor, OutsideColor);
|
||||
_mpb.SetFloat(_propMinBrightness, MinBrightness);
|
||||
mat.SetPropertyBlock(_mpb);
|
||||
}
|
||||
}
|
||||
void LateUpdate()
|
||||
{
|
||||
float quadHalfWidth = 0.5f;
|
||||
float quadHalfHeight = 0.5f;
|
||||
|
||||
// World-space basis directions from transform
|
||||
Vector3 Udir = transform.rotation * Vector3.right; // plane local +X
|
||||
Vector3 Vdir = transform.rotation * Vector3.up; // plane local +Y
|
||||
|
||||
// World-space half extents after non-uniform scaling
|
||||
float halfW = quadHalfWidth * transform.lossyScale.x;
|
||||
float halfH = quadHalfHeight * transform.lossyScale.y;
|
||||
|
||||
// Reciprocal axes so dot(r, Uinv/Vinv) -> [-0.5, 0.5]
|
||||
Vector3 Uinv = Udir / (2.0f * Mathf.Max(halfW, 1e-6f));
|
||||
Vector3 Vinv = Vdir / (2.0f * Mathf.Max(halfH, 1e-6f));
|
||||
|
||||
// Unit normal
|
||||
Vector3 N = Vector3.Normalize(Vector3.Cross(Udir, Vdir));
|
||||
|
||||
Vector4 originVec = new Vector4(transform.position.x, transform.position.y, transform.position.z, 0);
|
||||
Vector4 uinvVec = new Vector4(Uinv.x, Uinv.y, Uinv.z, 0);
|
||||
Vector4 vinvVec = new Vector4(Vinv.x, Vinv.y, Vinv.z, 0);
|
||||
Vector4 nVec = new Vector4(N.x, N.y, N.z, 0);
|
||||
|
||||
foreach (Renderer mat in rendererTargets)
|
||||
{
|
||||
if (mat == null) continue;
|
||||
mat.GetPropertyBlock(_mpb);
|
||||
|
||||
float quadHalfWidth = 0.5f;
|
||||
float quadHalfHeight = 0.5f;
|
||||
|
||||
// World-space basis directions from transform
|
||||
Vector3 Udir = transform.rotation * Vector3.right; // plane local +X
|
||||
Vector3 Vdir = transform.rotation * Vector3.up; // plane local +Y
|
||||
|
||||
// World-space half extents after non-uniform scaling
|
||||
float halfW = quadHalfWidth * transform.lossyScale.x;
|
||||
float halfH = quadHalfHeight * transform.lossyScale.y;
|
||||
|
||||
// Reciprocal axes so dot(r, Uinv/Vinv) -> [-0.5, 0.5]
|
||||
Vector3 Uinv = Udir / (2.0f * Mathf.Max(halfW, 1e-6f));
|
||||
Vector3 Vinv = Vdir / (2.0f * Mathf.Max(halfH, 1e-6f));
|
||||
|
||||
// Unit normal
|
||||
Vector3 N = Vector3.Normalize(Vector3.Cross(Udir, Vdir));
|
||||
|
||||
_mpb.SetVector("_Udon_Plane_Origin_" + shadowcasterIndex.ToString(), new Vector4(transform.position.x, transform.position.y, transform.position.z, 0));
|
||||
_mpb.SetVector("_Udon_Plane_Uinv_" + shadowcasterIndex.ToString(), new Vector4(Uinv.x, Uinv.y, Uinv.z, 0));
|
||||
_mpb.SetVector("_Udon_Plane_Vinv_" + shadowcasterIndex.ToString(), new Vector4(Vinv.x, Vinv.y, Vinv.z, 0));
|
||||
_mpb.SetVector("_Udon_Plane_Normal_" + shadowcasterIndex.ToString(), new Vector4(N.x, N.y, N.z, 0));
|
||||
_mpb.SetVector(_propPlaneOrigin, originVec);
|
||||
_mpb.SetVector(_propPlaneUinv, uinvVec);
|
||||
_mpb.SetVector(_propPlaneVinv, vinvVec);
|
||||
_mpb.SetVector(_propPlaneNormal, nVec);
|
||||
|
||||
mat.SetPropertyBlock(_mpb);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,229 @@
|
||||
Shader "DeMuenu/World/Hoppou/Decal_2SP"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_NormalMap ("Normal Map", 2D) = "bump" {}
|
||||
_NormalMapStrength ("Normal Map Strength", Range(0,1)) = 1
|
||||
_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
|
||||
|
||||
|
||||
//Moonlight
|
||||
_InverseSqareMultiplier ("Inverse Square Multiplier", Float) = 1
|
||||
_LightCutoffDistance ("Light Cutoff Distance", Float) = 100
|
||||
|
||||
_EnableShadowCasting ("Enable Shadowcasting", Float) = 0
|
||||
_BlurPixels ("Shadowcaster Blur Pixels", Float) = 0
|
||||
//Moonlight END
|
||||
|
||||
//Decal
|
||||
_DecalTex ("Decal Texture", 2D) = "white" {}
|
||||
_DecalColor ("Decal Color", Color) = (1,1,1,1)
|
||||
_DecalTex_ScrollX ("Decal Scroll X", Float) = 0
|
||||
_DecalTex_ScrollY ("Decal Scroll Y", Float) = 0
|
||||
[Enum(Multiply,0,Additive,1,Screen,2,AlphaBlend,3)] _DecalBlendMode ("Decal Blend Mode", Float) = 0
|
||||
[Enum(UnityEngine.Rendering.CullMode)] _Cull ("Cull Mode", Float) = 2
|
||||
[Enum(Off, 0, On, 1)] _ZWrite ("ZWrite", Float) = 0
|
||||
[Enum(UnityEngine.Rendering.CompareFunction)] _ZTest ("ZTest", Float) = 4
|
||||
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "RenderType"="Transparent" "Queue"="Overlay" }
|
||||
LOD 100
|
||||
Cull[_Cull]
|
||||
ZWrite [_ZWrite]
|
||||
ZTest [_ZTest]
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
//Moonlight Defines
|
||||
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
||||
//Moonlight Defines END
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Includes/Moonlight.hlsl"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float3 normal : NORMAL;
|
||||
float4 tangent : TANGENT;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float2 uv2 : TEXCOORD1;
|
||||
float2 uvEmmis : TEXCOORD4;
|
||||
float4 vertex : SV_POSITION;
|
||||
float2 normUV : TEXCOORD5;
|
||||
float2 uvDecal : TEXCOORD8;
|
||||
float3 worldTangent : TEXCOORD6;
|
||||
float3 worldBitangent : TEXCOORD7;
|
||||
|
||||
//Moonlight
|
||||
float3 worldPos : TEXCOORD2;
|
||||
float3 worldNormal: TEXCOORD3;
|
||||
//Moonlight END
|
||||
|
||||
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float4 _MainTex_ST;
|
||||
sampler2D _NormalMap;
|
||||
float4 _NormalMap_ST;
|
||||
float4 _Color;
|
||||
float _NormalMapStrength;
|
||||
|
||||
|
||||
|
||||
sampler2D _EmmisiveText;
|
||||
float4 _EmmisiveText_ST;
|
||||
float4 _EmmissiveColor;
|
||||
float _EmmissiveStrength;
|
||||
|
||||
sampler2D _DecalTex;
|
||||
float4 _DecalTex_ST;
|
||||
float4 _DecalColor;
|
||||
float _DecalTex_ScrollX;
|
||||
float _DecalTex_ScrollY;
|
||||
float _DecalBlendMode;
|
||||
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
|
||||
o.normUV = TRANSFORM_TEX(v.uv, _NormalMap);
|
||||
o.uvEmmis = TRANSFORM_TEX(v.uv, _EmmisiveText);
|
||||
o.uvDecal = TRANSFORM_TEX(v.uv, _DecalTex);
|
||||
|
||||
float3 nWS = UnityObjectToWorldNormal(v.normal);
|
||||
float3 tWS = normalize(UnityObjectToWorldDir(v.tangent.xyz));
|
||||
float3 bWS = normalize(cross(nWS, tWS) * v.tangent.w);
|
||||
|
||||
o.worldNormal = nWS;
|
||||
o.worldTangent = tWS;
|
||||
o.worldBitangent= bWS;
|
||||
|
||||
|
||||
//Moonlight Vertex
|
||||
float4 wp = mul(unity_ObjectToWorld, v.vertex);
|
||||
o.worldPos = wp.xyz;
|
||||
//o.worldNormal = UnityObjectToWorldNormal(v.normal);
|
||||
//Moonlight Vertex END
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
// sample the texture
|
||||
fixed4 col = tex2D(_MainTex, i.uv);
|
||||
fixed4 norm = tex2D(_NormalMap, i.normUV);
|
||||
|
||||
fixed4 emmis = tex2D(_EmmisiveText, i.uvEmmis);
|
||||
|
||||
|
||||
//Moonlight
|
||||
float3 nTS = UnpackNormal(norm);
|
||||
float3 NmapWS = normalize(i.worldTangent * nTS.x +
|
||||
i.worldBitangent * nTS.y +
|
||||
i.worldNormal * nTS.z);
|
||||
float3 N = normalize(lerp(normalize(i.worldNormal), NmapWS, saturate(_NormalMapStrength)));
|
||||
|
||||
OutLoopSetup(i, _Udon_PlayerCount) //defines count, N, dmax, dIntensity
|
||||
|
||||
[loop]
|
||||
for (int LightCounter = 0; LightCounter < count; LightCounter++)
|
||||
{
|
||||
InLoopSetup(_Udon_LightPositions, LightCounter, count, i); //defines distanceFromLight, contrib
|
||||
|
||||
|
||||
//Lambertian diffuse
|
||||
Lambert(_Udon_LightPositions[LightCounter].xyz ,i, N); //defines NdotL
|
||||
|
||||
LightTypeCalculations(_Udon_LightColors, LightCounter, i, NdotL, dIntensity, _Udon_LightPositions[LightCounter].a, _Udon_LightPositions[LightCounter].xyz);
|
||||
|
||||
float4 ShadowCasterMult_1 = 1;
|
||||
float4 ShadowCasterMult_2 = 1;
|
||||
|
||||
if ((((_Udon_ShadowMapIndex[LightCounter] > 0.5) && (_Udon_ShadowMapIndex[LightCounter] < 1.5) && (_EnableShadowCasting > 0.5)) || (_Udon_ShadowMapIndex[LightCounter] > 2.5)) && _EnableShadowCasting) {
|
||||
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_1.xyz, _Udon_Plane_Uinv_1.xyz, _Udon_Plane_Vinv_1.xyz, _Udon_Plane_Normal_1.xyz,
|
||||
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
||||
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
||||
}
|
||||
if (_Udon_ShadowMapIndex[LightCounter] > 1.5 && (_EnableShadowCasting > 0.5))
|
||||
{
|
||||
half smIndex = _Udon_ShadowMapIndex[LightCounter];
|
||||
if ((smIndex > 0.5 && smIndex < 1.5) || smIndex > 2.5)
|
||||
{
|
||||
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_1.xyz, _Udon_Plane_Uinv_1.xyz, _Udon_Plane_Vinv_1.xyz, _Udon_Plane_Normal_1.xyz,
|
||||
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
||||
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
||||
}
|
||||
if (smIndex > 1.5)
|
||||
{
|
||||
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
||||
_Udon_shadowCasterTex_2, _Udon_OutSideColor_2, _Udon_shadowCasterColor_2, _BlurPixels, _Udon_shadowCasterTex_2_TexelSize.xy);
|
||||
ShadowCasterMult_2 = max(sc2, _Udon_MinBrightnessShadow_2);
|
||||
}
|
||||
}
|
||||
|
||||
dmax = dmax + contrib * float4(LightColor, 1) * NdotL * ShadowCasterMult_1 * ShadowCasterMult_2;
|
||||
|
||||
}
|
||||
|
||||
//dmax.xyz = min(dmax * dIntensity, 1.0);
|
||||
dmax.w = 1.0;
|
||||
|
||||
//Moonlight END
|
||||
|
||||
fixed4 decal = tex2D(_DecalTex, i.uvDecal + float2(_DecalTex_ScrollX, _DecalTex_ScrollY) * _Time.y);
|
||||
fixed4 base = col * _Color * dmax + emmis * _EmmissiveStrength * _EmmissiveColor;
|
||||
fixed4 dcol = decal * _DecalColor * dmax;
|
||||
|
||||
if (_DecalBlendMode < 0.5)
|
||||
{
|
||||
base = lerp(base, base * dcol, dcol.a);
|
||||
}
|
||||
else if (_DecalBlendMode < 1.5)
|
||||
{
|
||||
base = lerp(base, base + dcol, dcol.a);
|
||||
}
|
||||
else if (_DecalBlendMode < 2.5)
|
||||
{
|
||||
base = lerp(base, 1 - (1 - base) * (1 - dcol), dcol.a);
|
||||
}
|
||||
else
|
||||
{
|
||||
base = lerp(base, dcol, dcol.a);
|
||||
}
|
||||
|
||||
return base;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
|
||||
FallBack "Diffuse"
|
||||
}
|
||||
@@ -2,16 +2,20 @@
|
||||
#define InLoopSetup(_Udon_LightPositions, LightCounter, count, i) \
|
||||
if (LightCounter >= count) break; \
|
||||
\
|
||||
float distanceFromLight = length(i.worldPos - _Udon_LightPositions[LightCounter].xyz); \
|
||||
float3 lightVec = _Udon_LightPositions[LightCounter].xyz - i.worldPos; \
|
||||
float distanceFromLight = length(lightVec); \
|
||||
if (distanceFromLight > _LightCutoffDistance) continue; \
|
||||
\
|
||||
float contrib = 0.0;
|
||||
float contrib = 0.0; \
|
||||
float3 L = lightVec / max(distanceFromLight, 1e-4);
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef OutLoopSetup
|
||||
#define OutLoopSetup(i, _Udon_PlayerCount) \
|
||||
int count = (int)_Udon_PlayerCount; \
|
||||
float invSqMul = max(1e-4, _InverseSqareMultiplier); \
|
||||
bool shadowCastingEnabled = _EnableShadowCasting > 0.5; \
|
||||
\
|
||||
float4 dmax = float4(0,0,0,1); \
|
||||
float dIntensity = 0;
|
||||
|
||||
@@ -1,7 +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 */ \
|
||||
/* 'L' is inherited from InLoopSetup, avoiding an expensive normalize() */ \
|
||||
half NdotL = saturate(dot(N, L) * 0.5 + 0.5); /* one-sided Lambert */ \
|
||||
if (NdotL <= 0) continue; \
|
||||
|
||||
#endif
|
||||
@@ -1,24 +1,27 @@
|
||||
#ifndef LightTypeCalculations
|
||||
#define LightTypeCalculations(_Udon_LightColors ,LightCounter, i, NdotL, dIntensity, radius, Lightposition) \
|
||||
float invSqMul = max(1e-4, _InverseSqareMultiplier); \
|
||||
half typeId = _Udon_LightType[LightCounter]; \
|
||||
\
|
||||
if(_Udon_LightType[LightCounter] == 0) \
|
||||
if(typeId == 0) \
|
||||
{ \
|
||||
contrib = _Udon_LightColors[LightCounter].a / max(1e-4, max(0, max(1, distanceFromLight - radius) * invSqMul) * max(0, max(1, distanceFromLight - radius) * invSqMul)); \
|
||||
\
|
||||
float distAtten = max(1.0, distanceFromLight - radius) * invSqMul; \
|
||||
contrib = _Udon_LightColors[LightCounter].a / max(1e-4, distAtten * distAtten); \
|
||||
if (contrib == 0.0) continue;\
|
||||
dIntensity += contrib; \
|
||||
} \
|
||||
else if (_Udon_LightType[LightCounter] == 1) \
|
||||
else if (typeId == 1) \
|
||||
{ \
|
||||
float invSq = _Udon_LightColors[LightCounter].a / max(1e-4, (distanceFromLight * invSqMul) * (distanceFromLight * invSqMul)); \
|
||||
float distAtten = distanceFromLight * invSqMul; \
|
||||
float invSq = _Udon_LightColors[LightCounter].a / max(1e-4, distAtten * distAtten); \
|
||||
\
|
||||
contrib = dot(normalize(i.worldPos - Lightposition), normalize(_Udon_LightDirections[LightCounter].xyz)); \
|
||||
contrib = dot(-L, normalize(_Udon_LightDirections[LightCounter].xyz)); \
|
||||
contrib = smoothstep(radius,_Udon_LightDirections[LightCounter].w, contrib); \
|
||||
\
|
||||
contrib = contrib * invSq; \
|
||||
if (contrib == 0.0) continue;\
|
||||
dIntensity += contrib; \
|
||||
} \
|
||||
float3 LightColor = _Udon_LightColors[LightCounter].xyz; \
|
||||
half3 LightColor = _Udon_LightColors[LightCounter].xyz; \
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,10 @@
|
||||
#ifndef MOONLIGHT_CORE_INCLUDED
|
||||
#define MOONLIGHT_CORE_INCLUDED
|
||||
|
||||
#include "Variables.hlsl"
|
||||
#include "DefaultSetup.hlsl"
|
||||
#include "LightStrength.hlsl"
|
||||
#include "Lambert.hlsl"
|
||||
#include "Shadowcaster.cginc"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1193ddffee5ac344ea57d621ec8150f6
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,14 +1,40 @@
|
||||
#ifndef MoonlightGlobalVariables
|
||||
#define MoonlightGlobalVariables \
|
||||
\
|
||||
float _InverseSqareMultiplier; \
|
||||
float _LightCutoffDistance; \
|
||||
\
|
||||
float4 _Udon_LightPositions[MAX_LIGHTS]; /* xyz = position */ \
|
||||
float4 _Udon_LightColors[MAX_LIGHTS]; /* xyz = position */ \
|
||||
float4 _Udon_LightDirections[MAX_LIGHTS]; /* xyz = direction, w = cos(halfAngle) */ \
|
||||
float _Udon_LightType[MAX_LIGHTS]; /* 0 = sphere, 1 = cone */ \
|
||||
float _Udon_ShadowMapIndex[MAX_LIGHTS];\
|
||||
float _Udon_PlayerCount; /* set via SetFloat */ \
|
||||
#ifndef MOONLIGHT_GLOBAL_VARIABLES_INCLUDED
|
||||
#define MOONLIGHT_GLOBAL_VARIABLES_INCLUDED
|
||||
|
||||
float _InverseSqareMultiplier;
|
||||
float _LightCutoffDistance;
|
||||
|
||||
float4 _Udon_LightPositions[MAX_LIGHTS]; /* xyz = position */
|
||||
float4 _Udon_LightColors[MAX_LIGHTS]; /* xyz = position */
|
||||
float4 _Udon_LightDirections[MAX_LIGHTS]; /* xyz = direction, w = cos(halfAngle) */
|
||||
float _Udon_LightType[MAX_LIGHTS]; /* 0 = sphere, 1 = cone */
|
||||
float _Udon_ShadowMapIndex[MAX_LIGHTS];
|
||||
float _Udon_PlayerCount; /* set via SetFloat */
|
||||
|
||||
float4 _Udon_Plane_Origin_1; // xyz = origin (world), w unused
|
||||
float4 _Udon_Plane_Uinv_1; // xyz = Udir / (2*halfWidth)
|
||||
float4 _Udon_Plane_Vinv_1; // xyz = Vdir / (2*halfHeight)
|
||||
float4 _Udon_Plane_Normal_1; // xyz = unit normal
|
||||
|
||||
sampler2D _Udon_shadowCasterTex_1;
|
||||
float4 _Udon_shadowCasterColor_1;
|
||||
float4 _Udon_OutSideColor_1;
|
||||
float _Udon_MinBrightnessShadow_1;
|
||||
|
||||
float4 _Udon_Plane_Origin_2;
|
||||
float4 _Udon_Plane_Uinv_2;
|
||||
float4 _Udon_Plane_Vinv_2;
|
||||
float4 _Udon_Plane_Normal_2;
|
||||
|
||||
sampler2D _Udon_shadowCasterTex_2;
|
||||
float4 _Udon_shadowCasterColor_2;
|
||||
float4 _Udon_OutSideColor_2;
|
||||
float _Udon_MinBrightnessShadow_2;
|
||||
|
||||
float _BlurPixels;
|
||||
float4 _Udon_shadowCasterTex_1_TexelSize; // xy = 1/width, 1/height
|
||||
float4 _Udon_shadowCasterTex_2_TexelSize;
|
||||
|
||||
bool _EnableShadowCasting;
|
||||
|
||||
#endif
|
||||
@@ -35,11 +35,7 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles_2SP"
|
||||
#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"
|
||||
#include "Includes/Shadowcaster.cginc"
|
||||
#include "Includes/Moonlight.hlsl"
|
||||
|
||||
|
||||
|
||||
@@ -79,35 +75,6 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles_2SP"
|
||||
float4 _EmmissiveColor;
|
||||
float _EmmissiveStrength;
|
||||
|
||||
|
||||
MoonlightGlobalVariables
|
||||
|
||||
float4 _Udon_Plane_Origin_1; // xyz = origin (world), w unused
|
||||
float4 _Udon_Plane_Uinv_1; // xyz = Udir / (2*halfWidth)
|
||||
float4 _Udon_Plane_Vinv_1; // xyz = Vdir / (2*halfHeight)
|
||||
float4 _Udon_Plane_Normal_1; // xyz = unit normal
|
||||
|
||||
sampler2D _Udon_shadowCasterTex_1;
|
||||
float4 _Udon_shadowCasterColor_1;
|
||||
float4 _Udon_OutSideColor_1;
|
||||
float _Udon_MinBrightnessShadow_1;
|
||||
|
||||
float4 _Udon_Plane_Origin_2;
|
||||
float4 _Udon_Plane_Uinv_2;
|
||||
float4 _Udon_Plane_Vinv_2;
|
||||
float4 _Udon_Plane_Normal_2;
|
||||
|
||||
sampler2D _Udon_shadowCasterTex_2;
|
||||
float4 _Udon_shadowCasterColor_2;
|
||||
float4 _Udon_OutSideColor_2;
|
||||
float _Udon_MinBrightnessShadow_2;
|
||||
|
||||
float _BlurPixels;
|
||||
float4 _Udon_shadowCasterTex_1_TexelSize; // xy = 1/width, 1/height
|
||||
float4 _Udon_shadowCasterTex_2_TexelSize;
|
||||
|
||||
bool _EnableShadowCasting;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
@@ -138,7 +105,7 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles_2SP"
|
||||
OutLoopSetup(i, _Udon_PlayerCount) //defines count, N, dmax, dIntensity
|
||||
|
||||
[loop]
|
||||
for (int LightCounter = 0; LightCounter < MAX_LIGHTS; LightCounter++)
|
||||
for (int LightCounter = 0; LightCounter < count; LightCounter++)
|
||||
{
|
||||
|
||||
InLoopSetup(_Udon_LightPositions, LightCounter, count, i); //defines distanceFromLight, contrib
|
||||
@@ -151,18 +118,23 @@ Shader "DeMuenu/World/Hoppou/Particles/LitParticles_2SP"
|
||||
|
||||
if ((((_Udon_ShadowMapIndex[LightCounter] > 0.5) && (_Udon_ShadowMapIndex[LightCounter] < 1.5) && (_EnableShadowCasting > 0.5)) || (_Udon_ShadowMapIndex[LightCounter] > 2.5)) && _EnableShadowCasting)
|
||||
{
|
||||
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_1.xyz, _Udon_Plane_Uinv_1.xyz, _Udon_Plane_Vinv_1.xyz, _Udon_Plane_Normal_1.xyz,
|
||||
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
||||
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
||||
}
|
||||
if (_Udon_ShadowMapIndex[LightCounter] > 1.5 && (_EnableShadowCasting > 0.5)) {
|
||||
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
||||
_Udon_shadowCasterTex_2, _Udon_OutSideColor_2, _Udon_shadowCasterColor_2, _BlurPixels, _Udon_shadowCasterTex_2_TexelSize.xy);
|
||||
ShadowCasterMult_2 = max(sc2, _Udon_MinBrightnessShadow_2);
|
||||
half smIndex = _Udon_ShadowMapIndex[LightCounter];
|
||||
if ((smIndex > 0.5 && smIndex < 1.5) || smIndex > 2.5)
|
||||
{
|
||||
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_1.xyz, _Udon_Plane_Uinv_1.xyz, _Udon_Plane_Vinv_1.xyz, _Udon_Plane_Normal_1.xyz,
|
||||
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
||||
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
||||
}
|
||||
if (smIndex > 1.5)
|
||||
{
|
||||
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
||||
_Udon_shadowCasterTex_2, _Udon_OutSideColor_2, _Udon_shadowCasterColor_2, _BlurPixels, _Udon_shadowCasterTex_2_TexelSize.xy);
|
||||
ShadowCasterMult_2 = max(sc2, _Udon_MinBrightnessShadow_2);
|
||||
}
|
||||
}
|
||||
|
||||
dmax = dmax + contrib * float4(LightColor, 1) * ShadowCasterMult_1 * ShadowCasterMult_2;
|
||||
|
||||
+21
-42
@@ -37,16 +37,12 @@ Shader "DeMuenu/World/Hoppou/Standard_2SP"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Includes/LightStrength.hlsl"
|
||||
#include "Includes/Lambert.hlsl"
|
||||
#include "Includes/DefaultSetup.hlsl"
|
||||
#include "Includes/Variables.hlsl"
|
||||
#include "Includes/Shadowcaster.cginc"
|
||||
|
||||
//Moonlight Defines
|
||||
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
||||
//Moonlight Defines END
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Includes/Moonlight.hlsl"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
@@ -89,35 +85,6 @@ Shader "DeMuenu/World/Hoppou/Standard_2SP"
|
||||
float _EmmissiveStrength;
|
||||
|
||||
|
||||
MoonlightGlobalVariables
|
||||
|
||||
|
||||
float4 _Udon_Plane_Origin_1; // xyz = origin (world), w unused
|
||||
float4 _Udon_Plane_Uinv_1; // xyz = Udir / (2*halfWidth)
|
||||
float4 _Udon_Plane_Vinv_1; // xyz = Vdir / (2*halfHeight)
|
||||
float4 _Udon_Plane_Normal_1; // xyz = unit normal
|
||||
|
||||
sampler2D _Udon_shadowCasterTex_1;
|
||||
float4 _Udon_shadowCasterColor_1;
|
||||
float4 _Udon_OutSideColor_1;
|
||||
float _Udon_MinBrightnessShadow_1;
|
||||
|
||||
float4 _Udon_Plane_Origin_2;
|
||||
float4 _Udon_Plane_Uinv_2;
|
||||
float4 _Udon_Plane_Vinv_2;
|
||||
float4 _Udon_Plane_Normal_2;
|
||||
|
||||
sampler2D _Udon_shadowCasterTex_2;
|
||||
float4 _Udon_shadowCasterColor_2;
|
||||
float4 _Udon_OutSideColor_2;
|
||||
float _Udon_MinBrightnessShadow_2;
|
||||
|
||||
float _BlurPixels;
|
||||
float4 _Udon_shadowCasterTex_1_TexelSize; // xy = 1/width, 1/height
|
||||
float4 _Udon_shadowCasterTex_2_TexelSize;
|
||||
|
||||
bool _EnableShadowCasting;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
@@ -163,7 +130,7 @@ Shader "DeMuenu/World/Hoppou/Standard_2SP"
|
||||
OutLoopSetup(i, _Udon_PlayerCount) //defines count, N, dmax, dIntensity
|
||||
|
||||
[loop]
|
||||
for (int LightCounter = 0; LightCounter < MAX_LIGHTS; LightCounter++)
|
||||
for (int LightCounter = 0; LightCounter < count; LightCounter++)
|
||||
{
|
||||
InLoopSetup(_Udon_LightPositions, LightCounter, count, i); //defines distanceFromLight, contrib
|
||||
|
||||
@@ -185,11 +152,23 @@ Shader "DeMuenu/World/Hoppou/Standard_2SP"
|
||||
}
|
||||
if (_Udon_ShadowMapIndex[LightCounter] > 1.5 && (_EnableShadowCasting > 0.5))
|
||||
{
|
||||
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
||||
_Udon_shadowCasterTex_2, _Udon_OutSideColor_2, _Udon_shadowCasterColor_2, _BlurPixels, _Udon_shadowCasterTex_2_TexelSize.xy);
|
||||
ShadowCasterMult_2 = max(sc2, _Udon_MinBrightnessShadow_2);
|
||||
half smIndex = _Udon_ShadowMapIndex[LightCounter];
|
||||
if ((smIndex > 0.5 && smIndex < 1.5) || smIndex > 2.5)
|
||||
{
|
||||
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_1.xyz, _Udon_Plane_Uinv_1.xyz, _Udon_Plane_Vinv_1.xyz, _Udon_Plane_Normal_1.xyz,
|
||||
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
||||
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
||||
}
|
||||
if (smIndex > 1.5)
|
||||
{
|
||||
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
||||
_Udon_shadowCasterTex_2, _Udon_OutSideColor_2, _Udon_shadowCasterColor_2, _BlurPixels, _Udon_shadowCasterTex_2_TexelSize.xy);
|
||||
ShadowCasterMult_2 = max(sc2, _Udon_MinBrightnessShadow_2);
|
||||
}
|
||||
}
|
||||
|
||||
dmax = dmax + contrib * float4(LightColor, 1) * NdotL * ShadowCasterMult_1 * ShadowCasterMult_2;
|
||||
|
||||
@@ -39,16 +39,12 @@ Shader "DeMuenu/World/Hoppou/Standard_Lightmap_2SP"
|
||||
#pragma multi_compile _ LIGHTMAP_ON
|
||||
#pragma multi_compile _ DIRLIGHTMAP_COMBINED
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Includes/LightStrength.hlsl"
|
||||
#include "Includes/Lambert.hlsl"
|
||||
#include "Includes/DefaultSetup.hlsl"
|
||||
#include "Includes/Variables.hlsl"
|
||||
#include "Includes/Shadowcaster.cginc"
|
||||
|
||||
//Moonlight Defines
|
||||
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
||||
//Moonlight Defines END
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Includes/Moonlight.hlsl"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
@@ -97,37 +93,6 @@ Shader "DeMuenu/World/Hoppou/Standard_Lightmap_2SP"
|
||||
float _EmmissiveStrength;
|
||||
|
||||
|
||||
MoonlightGlobalVariables
|
||||
|
||||
|
||||
float4 _Udon_Plane_Origin_1; // xyz = origin (world), w unused
|
||||
float4 _Udon_Plane_Uinv_1; // xyz = Udir / (2*halfWidth)
|
||||
float4 _Udon_Plane_Vinv_1; // xyz = Vdir / (2*halfHeight)
|
||||
float4 _Udon_Plane_Normal_1; // xyz = unit normal
|
||||
|
||||
sampler2D _Udon_shadowCasterTex_1;
|
||||
float4 _Udon_shadowCasterColor_1;
|
||||
float4 _Udon_OutSideColor_1;
|
||||
float _Udon_MinBrightnessShadow_1;
|
||||
|
||||
float4 _Udon_Plane_Origin_2;
|
||||
float4 _Udon_Plane_Uinv_2;
|
||||
float4 _Udon_Plane_Vinv_2;
|
||||
float4 _Udon_Plane_Normal_2;
|
||||
|
||||
sampler2D _Udon_shadowCasterTex_2;
|
||||
float4 _Udon_shadowCasterColor_2;
|
||||
float4 _Udon_OutSideColor_2;
|
||||
float _Udon_MinBrightnessShadow_2;
|
||||
|
||||
float _BlurPixels;
|
||||
float4 _Udon_shadowCasterTex_1_TexelSize; // xy = 1/width, 1/height
|
||||
float4 _Udon_shadowCasterTex_2_TexelSize;
|
||||
|
||||
bool _EnableShadowCasting;
|
||||
|
||||
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
@@ -177,7 +142,7 @@ Shader "DeMuenu/World/Hoppou/Standard_Lightmap_2SP"
|
||||
OutLoopSetup(i, _Udon_PlayerCount) //defines count, N, dmax, dIntensity
|
||||
|
||||
[loop]
|
||||
for (int LightCounter = 0; LightCounter < MAX_LIGHTS; LightCounter++)
|
||||
for (int LightCounter = 0; LightCounter < count; LightCounter++)
|
||||
{
|
||||
InLoopSetup(_Udon_LightPositions, LightCounter, count, i); //defines distanceFromLight, contrib
|
||||
|
||||
@@ -200,11 +165,23 @@ Shader "DeMuenu/World/Hoppou/Standard_Lightmap_2SP"
|
||||
}
|
||||
if (_Udon_ShadowMapIndex[LightCounter] > 1.5 && (_EnableShadowCasting > 0.5))
|
||||
{
|
||||
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
||||
_Udon_shadowCasterTex_2, _Udon_OutSideColor_2, _Udon_shadowCasterColor_2, _BlurPixels, _Udon_shadowCasterTex_2_TexelSize.xy);
|
||||
ShadowCasterMult_2 = max(sc2, _Udon_MinBrightnessShadow_2);
|
||||
half smIndex = _Udon_ShadowMapIndex[LightCounter];
|
||||
if ((smIndex > 0.5 && smIndex < 1.5) || smIndex > 2.5)
|
||||
{
|
||||
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_1.xyz, _Udon_Plane_Uinv_1.xyz, _Udon_Plane_Vinv_1.xyz, _Udon_Plane_Normal_1.xyz,
|
||||
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
||||
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
||||
}
|
||||
if (smIndex > 1.5)
|
||||
{
|
||||
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
||||
_Udon_shadowCasterTex_2, _Udon_OutSideColor_2, _Udon_shadowCasterColor_2, _BlurPixels, _Udon_shadowCasterTex_2_TexelSize.xy);
|
||||
ShadowCasterMult_2 = max(sc2, _Udon_MinBrightnessShadow_2);
|
||||
}
|
||||
}
|
||||
|
||||
dmax = dmax + contrib * float4(LightColor, 1) * NdotL * ShadowCasterMult_1 * ShadowCasterMult_2;
|
||||
|
||||
+21
-49
@@ -49,16 +49,12 @@ Shader "DeMuenu/World/Hoppou/WaterFlat_2SP"
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Includes/LightStrength.hlsl"
|
||||
#include "Includes/Lambert.hlsl"
|
||||
#include "Includes/DefaultSetup.hlsl"
|
||||
#include "Includes/Variables.hlsl"
|
||||
#include "Includes/Shadowcaster.cginc"
|
||||
|
||||
//Moonlight Defines
|
||||
#define MAX_LIGHTS 80 // >= maxPlayers in script
|
||||
//Moonlight Defines END
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Includes/Moonlight.hlsl"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
@@ -95,35 +91,6 @@ Shader "DeMuenu/World/Hoppou/WaterFlat_2SP"
|
||||
float _NormalMapScrollSpeed2;
|
||||
float _MinTransparency;
|
||||
|
||||
|
||||
MoonlightGlobalVariables
|
||||
|
||||
float4 _Udon_Plane_Origin_1; // xyz = origin (world), w unused
|
||||
float4 _Udon_Plane_Uinv_1; // xyz = Udir / (2*halfWidth)
|
||||
float4 _Udon_Plane_Vinv_1; // xyz = Vdir / (2*halfHeight)
|
||||
float4 _Udon_Plane_Normal_1; // xyz = unit normal
|
||||
|
||||
sampler2D _Udon_shadowCasterTex_1;
|
||||
float4 _Udon_shadowCasterColor_1;
|
||||
float4 _Udon_OutSideColor_1;
|
||||
float _Udon_MinBrightnessShadow_1;
|
||||
|
||||
float4 _Udon_Plane_Origin_2;
|
||||
float4 _Udon_Plane_Uinv_2;
|
||||
float4 _Udon_Plane_Vinv_2;
|
||||
float4 _Udon_Plane_Normal_2;
|
||||
|
||||
sampler2D _Udon_shadowCasterTex_2;
|
||||
float4 _Udon_shadowCasterColor_2;
|
||||
float4 _Udon_OutSideColor_2;
|
||||
float _Udon_MinBrightnessShadow_2;
|
||||
|
||||
float _BlurPixels;
|
||||
float4 _Udon_shadowCasterTex_1_TexelSize; // xy = 1/width, 1/height
|
||||
float4 _Udon_shadowCasterTex_2_TexelSize;
|
||||
|
||||
bool _EnableShadowCasting;
|
||||
|
||||
|
||||
//Watershader specific
|
||||
float _SpecPower, _SpecIntensity;
|
||||
@@ -208,7 +175,7 @@ Shader "DeMuenu/World/Hoppou/WaterFlat_2SP"
|
||||
OutLoopSetup(i, _Udon_PlayerCount) //defines count, N, dmax, dIntensity
|
||||
|
||||
[loop]
|
||||
for (int LightCounter = 0; LightCounter < MAX_LIGHTS; LightCounter++)
|
||||
for (int LightCounter = 0; LightCounter < count; LightCounter++)
|
||||
{
|
||||
InLoopSetup(_Udon_LightPositions, LightCounter, count, i); //defines distanceFromLight, contrib
|
||||
|
||||
@@ -221,18 +188,23 @@ Shader "DeMuenu/World/Hoppou/WaterFlat_2SP"
|
||||
|
||||
if ((((_Udon_ShadowMapIndex[LightCounter] > 0.5) && (_Udon_ShadowMapIndex[LightCounter] < 1.5) && (_EnableShadowCasting > 0.5)) || (_Udon_ShadowMapIndex[LightCounter] > 2.5)) && _EnableShadowCasting)
|
||||
{
|
||||
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_1.xyz, _Udon_Plane_Uinv_1.xyz, _Udon_Plane_Vinv_1.xyz, _Udon_Plane_Normal_1.xyz,
|
||||
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
||||
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
||||
}
|
||||
if (_Udon_ShadowMapIndex[LightCounter] > 1.5 && (_EnableShadowCasting > 0.5)) {
|
||||
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
||||
_Udon_shadowCasterTex_2, _Udon_OutSideColor_2, _Udon_shadowCasterColor_2, _BlurPixels, _Udon_shadowCasterTex_2_TexelSize.xy);
|
||||
ShadowCasterMult_2 = max(sc2, _Udon_MinBrightnessShadow_2);
|
||||
half smIndex = _Udon_ShadowMapIndex[LightCounter];
|
||||
if ((smIndex > 0.5 && smIndex < 1.5) || smIndex > 2.5)
|
||||
{
|
||||
float4 sc1 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_1.xyz, _Udon_Plane_Uinv_1.xyz, _Udon_Plane_Vinv_1.xyz, _Udon_Plane_Normal_1.xyz,
|
||||
_Udon_shadowCasterTex_1, _Udon_OutSideColor_1, _Udon_shadowCasterColor_1, _BlurPixels, _Udon_shadowCasterTex_1_TexelSize.xy);
|
||||
ShadowCasterMult_1 = max(sc1, _Udon_MinBrightnessShadow_1);
|
||||
}
|
||||
if (smIndex > 1.5)
|
||||
{
|
||||
float4 sc2 = SampleShadowcasterPlaneWS_Basis(
|
||||
_Udon_LightPositions[LightCounter].xyz, i.worldPos,
|
||||
_Udon_Plane_Origin_2.xyz, _Udon_Plane_Uinv_2.xyz, _Udon_Plane_Vinv_2.xyz, _Udon_Plane_Normal_2.xyz,
|
||||
_Udon_shadowCasterTex_2, _Udon_OutSideColor_2, _Udon_shadowCasterColor_2, _BlurPixels, _Udon_shadowCasterTex_2_TexelSize.xy);
|
||||
ShadowCasterMult_2 = max(sc2, _Udon_MinBrightnessShadow_2);
|
||||
}
|
||||
}
|
||||
|
||||
//Watershader specific
|
||||
|
||||
Reference in New Issue
Block a user