protected void SetShadowMaterials() { ShadowVolumeRenderer shadowVolumeRenderer = ShadowVolumeRenderer.Instance; if (shadowVolumeRenderer == null) { return; } ShadowVolumeBackend rendererBackend = shadowVolumeRenderer.Backend; if (backend == rendererBackend && updateMaterials == false) { return; } backend = rendererBackend; updateMaterials = false; if (backend == ShadowVolumeBackend.StencilBuffer) { if (isSimple) { GetComponent <Renderer>().sharedMaterials = new Material[] { stencilFrontBack }; } else { GetComponent <Renderer>().sharedMaterials = new Material[] { stencilBackFrontAlways, stencilFrontBack }; } } else if (backend == ShadowVolumeBackend.StencilBufferNoTwoSided) { if (isSimple) { GetComponent <Renderer>().sharedMaterials = new Material[] { stencilFront, stencilBack }; } else { GetComponent <Renderer>().sharedMaterials = new Material[] { stencilBackAlways, stencilFrontAlways, stencilFront, stencilBack }; } } else if (backend == ShadowVolumeBackend.AlphaChannel) { if (isSimple) { GetComponent <Renderer>().sharedMaterials = new Material[] { alphaFront, alphaBack }; } else { GetComponent <Renderer>().sharedMaterials = new Material[] { alphaBackAlways, alphaFrontAlways, alphaFront, alphaBack }; } } else if (backend == ShadowVolumeBackend.AlphaChannelNoBlendOp) { if (isSimple) { GetComponent <Renderer>().sharedMaterials = new Material[] { alphaFront, alphaBackNoBlendOp }; } else { GetComponent <Renderer>().sharedMaterials = new Material[] { alphaBackAlways, alphaFrontAlwaysNoBlendOp, alphaFront, alphaBackNoBlendOp }; } } }
protected void DrawShadowMesh() { if (shadowMesh == null) { return; } ShadowVolumeRenderer shadowVolumeRenderer = ShadowVolumeRenderer.Instance; if (shadowVolumeRenderer == null) { return; } ShadowVolumeBackend backend = shadowVolumeRenderer.Backend; Matrix4x4 shadowTransform = transform.localToWorldMatrix; if (backend == ShadowVolumeBackend.StencilBuffer) { if (isSimple) { Graphics.DrawMesh(shadowMesh, shadowTransform, stencilFrontBack, layer, null, 0, null, false, false); } else { Graphics.DrawMesh(shadowMesh, shadowTransform, stencilBackFrontAlways, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, stencilFrontBack, layer, null, 0, null, false, false); } } else if (backend == ShadowVolumeBackend.StencilBufferNoTwoSided) { if (isSimple) { Graphics.DrawMesh(shadowMesh, shadowTransform, stencilFront, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, stencilBack, layer, null, 0, null, false, false); } else { Graphics.DrawMesh(shadowMesh, shadowTransform, stencilBackAlways, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, stencilFrontAlways, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, stencilFront, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, stencilBack, layer, null, 0, null, false, false); } } else if (backend == ShadowVolumeBackend.AlphaChannel) { if (isSimple) { Graphics.DrawMesh(shadowMesh, shadowTransform, alphaFront, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, alphaBack, layer, null, 0, null, false, false); } else { Graphics.DrawMesh(shadowMesh, shadowTransform, alphaBackAlways, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, alphaFrontAlways, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, alphaFront, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, alphaBack, layer, null, 0, null, false, false); } } else if (backend == ShadowVolumeBackend.AlphaChannelNoBlendOp) { if (isSimple) { Graphics.DrawMesh(shadowMesh, shadowTransform, alphaFront, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, alphaBackNoBlendOp, layer, null, 0, null, false, false); } else { Graphics.DrawMesh(shadowMesh, shadowTransform, alphaBackAlways, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, alphaFrontAlwaysNoBlendOp, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, alphaFront, layer, null, 0, null, false, false); Graphics.DrawMesh(shadowMesh, shadowTransform, alphaBackNoBlendOp, layer, null, 0, null, false, false); } } }
public void Start() { ShadowVolumeRenderer shadowVolumeRenderer = ShadowVolumeRenderer.Instance; if (shadowVolumeRenderer == null) { return; } ShadowVolumeBackend backend = shadowVolumeRenderer.Backend; ShadowVolume component = GetComponent <ShadowVolume>(); GameObject shadow = new GameObject("Shadow"); shadow.layer = component.Layer; shadow.transform.parent = gameObject.transform; shadow.transform.localPosition = Vector3.zero; shadow.transform.localRotation = Quaternion.identity; shadow.AddComponent <MeshFilter>().sharedMesh = component.ShadowMesh; Material[] materials = null; if (backend == ShadowVolumeBackend.StencilBuffer) { if (component.IsSimple) { materials = new Material[] { component.stencilFrontBack }; } else { materials = new Material[] { component.stencilBackFrontAlways, component.stencilFrontBack }; } } else if (backend == ShadowVolumeBackend.StencilBufferNoTwoSided) { if (component.IsSimple) { materials = new Material[] { component.stencilFront, component.stencilBack }; } else { materials = new Material[] { component.stencilBackAlways, component.stencilFrontAlways, component.stencilFront, component.stencilBack }; } } else if (backend == ShadowVolumeBackend.AlphaChannel) { if (component.IsSimple) { materials = new Material[] { component.alphaFront, component.alphaBack }; } else { materials = new Material[] { component.alphaBackAlways, component.alphaFrontAlways, component.alphaFront, component.alphaBack }; } } else if (backend == ShadowVolumeBackend.AlphaChannelNoBlendOp) { if (component.IsSimple) { materials = new Material[] { component.alphaFront, component.alphaBackNoBlendOp }; } else { materials = new Material[] { component.alphaBackAlways, component.alphaFrontAlwaysNoBlendOp, component.alphaFront, component.alphaBackNoBlendOp }; } } shadow.AddComponent <MeshRenderer>().sharedMaterials = materials; component.enabled = false; }