void RenderSpotShadows(int index, int split, int tileSize) { ShadowedOtherLight light = shadowedOtherLights[index]; var shadowSettings = new ShadowDrawingSettings(cullingResults, light.visibleLightIndex) { useRenderingLayerMaskTest = true }; cullingResults.ComputeSpotShadowMatricesAndCullingPrimitives( light.visibleLightIndex, out Matrix4x4 viewMatrix, out Matrix4x4 projectionMatrix, out ShadowSplitData splitData ); shadowSettings.splitData = splitData; float texelSize = 2f / (tileSize * projectionMatrix.m00); float filterSize = texelSize * ((float)settings.other.filter + 1f); float bias = light.normalBias * filterSize * 1.4142136f; Vector2 offset = SetTileViewport(index, split, tileSize); float tileScale = 1f / split; SetOtherTileData(index, offset, tileScale, bias); otherShadowMatrices[index] = ConvertToAtlasMatrix( projectionMatrix * viewMatrix, offset, tileScale ); buffer.SetViewProjectionMatrices(viewMatrix, projectionMatrix); buffer.SetGlobalDepthBias(0f, light.slopeScaleBias); ExecuteBuffer(); context.DrawShadows(ref shadowSettings); buffer.SetGlobalDepthBias(0f, 0f); }
public Vector4 ReserveOtherShadows(Light light, int visibleLightIndex) { if (light.shadows != LightShadows.None && light.shadowStrength > 0f) { float maskChannel = -1f; LightBakingOutput lightBaking = light.bakingOutput; if (lightBaking.lightmapBakeType == LightmapBakeType.Mixed && lightBaking.mixedLightingMode == MixedLightingMode.Shadowmask) { useShadowMask = true; maskChannel = lightBaking.occlusionMaskChannel; } bool isPoint = light.type == LightType.Point; int newLightCount = shadowedOtherLightCount + (isPoint ? 6 : 1); if (newLightCount > maxShadowedOtherLightCount || !cullingResults.GetShadowCasterBounds(visibleLightIndex, out Bounds b)) { return(new Vector4(-light.shadowStrength, 0f, 0f, maskChannel)); } shadowedOtherLights[shadowedOtherLightCount] = new ShadowedOtherLight { visibleLightIndex = visibleLightIndex, slopeScaleBias = light.shadowBias, normalBias = light.shadowNormalBias, isPoint = isPoint }; Vector4 data = new Vector4( light.shadowStrength, shadowedOtherLightCount, isPoint ? 1f : 0f, maskChannel); shadowedOtherLightCount = newLightCount; return(data); } return(new Vector4(0f, 0f, 0f, -1f)); }
private void RenderPointShadows(int index, int split, int tileSize) { ShadowedOtherLight light = shadowedOtherLights[index]; ShadowDrawingSettings shadowSettings = new ShadowDrawingSettings(cullingResults, light.visibleLightIndex); float texelSize = 2f / tileSize; float filterSize = texelSize * ((float)this.shadowSettings.other.filter + 1f); float bias = light.normalBias * filterSize * 1.4142136f; float tileScale = 1f / split; float fovBias = Mathf.Atan(1f + bias + filterSize) * Mathf.Rad2Deg * 2f - 90f; for (int i = 0; i < 6; ++i) { cullingResults.ComputePointShadowMatricesAndCullingPrimitives( light.visibleLightIndex, (CubemapFace)i, fovBias, out Matrix4x4 viewMatrix, out Matrix4x4 projectionMatrix, out ShadowSplitData splitData); viewMatrix.m11 = -viewMatrix.m11; viewMatrix.m12 = -viewMatrix.m12; viewMatrix.m13 = -viewMatrix.m13; shadowSettings.splitData = splitData; int tileIndex = index + i; //float texelSize = 2f / (tileSize * projectionMatrix.m00); //float filterSize = texelSize * ((float)this.shadowSettings.other.filter + 1f); //float bias = light.normalBias * filterSize * 1.4142136f; Vector2 offset = SetTileViewport(tileIndex, split, tileSize); //float tileScale = 1f / split; SetOtherTileData(tileIndex, offset, tileScale, bias); otherShadowMatrices[tileIndex] = ConvertToAtlasMatrix(projectionMatrix * viewMatrix, offset, tileScale); buffer.SetViewProjectionMatrices(viewMatrix, projectionMatrix); buffer.SetGlobalDepthBias(0f, light.slopeScaleBias); ExecuteBuffer(); context.DrawShadows(ref shadowSettings); buffer.SetGlobalDepthBias(0f, 0f); } }
void RenderPointShadows(int index, int split, int tileSize) { ShadowedOtherLight light = shadowedOtherLights[index]; //6 face FOV is fixed to 90 degree float texelSize = 2f / (tileSize); float filterSize = texelSize * ((float)shadowSettings.other.filter + 1f); float bias = light.normalBias * filterSize * 1.414f; float tileScale = 1f / split; //create a shadowdrawsetting based on the light index var shadowDSettings = new ShadowDrawingSettings(cullingResults, light.visibleLightIndex) { useRenderingLayerMaskTest = true }; //make shadow effcted by rendering layer mask //FOV bias to extend fov for a bit to get rid of seams float fovBias = Mathf.Atan(1f + bias + filterSize) * Mathf.Rad2Deg * 2f - 90f; for (int i = 0; i < 6; i++) { //get matrcies cullingResults.ComputePointShadowMatricesAndCullingPrimitives( light.visibleLightIndex, (CubemapFace)i, fovBias, out Matrix4x4 viewMatrix, out Matrix4x4 projectionMatrix, out ShadowSplitData splitData); //negate the unity reverse unity render shadow unside down(Stop light leak) viewMatrix.m11 = -viewMatrix.m11; viewMatrix.m12 = -viewMatrix.m12; viewMatrix.m13 = -viewMatrix.m13; shadowDSettings.splitData = splitData; int tileIndex = index + i; //m00 for projectiona matrix is the projection scale? Vector2 offset = SetTileViewport(tileIndex, split, tileSize); SetOtherTileData(tileIndex, offset, tileScale, bias); otherShadowMatrices[tileIndex] = ConvertToAtlasMatrix( projectionMatrix * viewMatrix, offset, tileScale ); buffer.SetViewProjectionMatrices(viewMatrix, projectionMatrix); buffer.SetGlobalDepthBias(0f, light.slopeScaleBias); ExecuteBuffer(); context.DrawShadows(ref shadowDSettings); buffer.SetGlobalDepthBias(0f, 0f); } }