mirror of
https://github.com/DeMuenu/MoonlightVRC.git
synced 2025-12-13 11:33:54 +00:00
Add shadowcaster support to lighting and shaders
Introduces shadowcaster support by adding shadow map index fields to light data, updating PlayerPositionsToShader and LightdataStorage to handle shadow map indices, and extending the shader and its includes to sample shadowcaster planes. Adds ShadowcasterUpdater script and editor preview for updating world-to-local matrices, and updates relevant arrays and property handling throughout the codebase. Also adds a sample plane mesh for shadowcasting.
This commit is contained in:
@@ -9,44 +9,52 @@ public partial class PlayerPositionsToShader
|
||||
out Vector4[] colors,
|
||||
out Vector4[] directions,
|
||||
out float[] types,
|
||||
out float[] shadowMapIndices,
|
||||
out int count)
|
||||
{
|
||||
int max = Mathf.Max(1, maxLights);
|
||||
|
||||
positions = new Vector4[max];
|
||||
colors = new Vector4[max];
|
||||
directions = new Vector4[max];
|
||||
types = new float[max];
|
||||
count = 0;
|
||||
positions = new Vector4[max];
|
||||
colors = new Vector4[max];
|
||||
directions = new Vector4[max];
|
||||
types = new float[max];
|
||||
shadowMapIndices = new float[max];
|
||||
count = 0;
|
||||
|
||||
// ✅ Avoid Array.Empty<T>(); just guard the loop
|
||||
if (otherLightSources != null)
|
||||
if (otherLightSources == null) return;
|
||||
|
||||
for (int i = 0; i < otherLightSources.Length && count < max; i++)
|
||||
{
|
||||
for (int i = 0; i < otherLightSources.Length && count < max; i++)
|
||||
{
|
||||
Transform t = otherLightSources[i];
|
||||
if (t == null || !t.gameObject.activeInHierarchy) continue;
|
||||
Transform t = otherLightSources[i];
|
||||
if (t == null || !t.gameObject.activeInHierarchy) continue;
|
||||
|
||||
LightdataStorage data = t.GetComponent<LightdataStorage>();
|
||||
LightdataStorage data = t.GetComponent<LightdataStorage>();
|
||||
|
||||
Vector3 pos = t.position;
|
||||
float range = (data != null) ? data.range * t.localScale.x : t.localScale.x;
|
||||
Vector4 col = (data != null) ? data.GetFinalColor() : new Vector4(1f, 1f, 1f, 1f);
|
||||
float intens = (data != null) ? data.intensity * t.localScale.x : 1f;
|
||||
float cosHalf = (data != null) ? data.GetCosHalfAngle() : 1f;
|
||||
int typeId = (data != null) ? data.GetTypeId() : 0;
|
||||
Vector3 pos = t.position;
|
||||
float range = (data != null) ? data.range * t.localScale.x : t.localScale.x;
|
||||
|
||||
// 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;
|
||||
|
||||
Quaternion rot = t.rotation;
|
||||
Vector3 fwd = rot * Vector3.down;
|
||||
// w = cosHalfAngle (0 for omni)
|
||||
float cosHalf = (data != null) ? data.GetCosHalfAngle() : 0f;
|
||||
|
||||
positions[count] = new Vector4(pos.x, pos.y, pos.z, range);
|
||||
colors[count] = new Vector4(col.x, col.y, col.z, intens);
|
||||
directions[count] = new Vector4(fwd.x, fwd.y, fwd.z, data.spotAngleDeg);
|
||||
types[count] = (float)typeId;
|
||||
// 0=Omni, 1=Spot, 2=Directional (your custom enum)
|
||||
int typeId = (data != null) ? data.GetTypeId() : 0;
|
||||
|
||||
count++;
|
||||
}
|
||||
float shIndex = (data != null) ? data.shadowMapIndex : 0f;
|
||||
|
||||
Quaternion rot = t.rotation;
|
||||
Vector3 fwd = rot * Vector3.down;
|
||||
|
||||
positions[count] = new Vector4(pos.x, pos.y, pos.z, range);
|
||||
colors[count] = new Vector4(col.x, col.y, col.z, intensity);
|
||||
directions[count] = new Vector4(fwd.x, fwd.y, fwd.z, cosHalf);
|
||||
types[count] = (float)typeId;
|
||||
shadowMapIndices[count] = shIndex;
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user