public void Setup(ScriptableRenderContext renderContext, CullingResults cullingResults, ShadowSettings shadowSettings) { this.cullingResults = cullingResults; commandBuffer.BeginSample(bufferName); shadowRenderer.Setup(renderContext, cullingResults, shadowSettings); SetupLights(); shadowRenderer.Render(); commandBuffer.EndSample(bufferName); renderContext.ExecuteCommandBuffer(commandBuffer); commandBuffer.Clear(); }
public void Render() { // Update hulls internal data structures. Hulls.Update(); // We want to use clamping sampler state throughout the lightmap rendering process. // This is required when drawing lights. Since light rendering and alpha clearing is done // in a single step, light is rendered with slightly larger quad where tex coords run out of the [0..1] range. Device.SamplerStates[0] = SamplerState.LinearClamp; // Switch render target to lightmap. Device.SetRenderTargets(Textures.LightmapBindings); // Clear lightmap color, depth and stencil data. Device.Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil | ClearOptions.Target, _ambientColor, 1f, 0); // Set per frame shader data. ShadowRenderer.PreRender(); // Generate lightmap. For each light, mask the shadowed areas determined by hulls and render light. int lightCount = Lights.Count; for (int i = 0; i < lightCount; i++) { Light light = Lights[i]; // Continue only if light is enabled and not inside any hull. if (!light.Enabled || Hulls.Contains(light)) { continue; } // Update light's internal data structures. light.Update(); // Continue only if light is within camera view. if (!light.Intersects(Camera)) { continue; } // Set scissor rectangle to clip any shadows outside of light's range. BoundingRectangle scissor; Camera.GetScissorRectangle(light, out scissor); Device.SetScissorRectangle(ref scissor); // Mask shadowed areas by reducing alpha. ShadowRenderer.Render(light); // Draw light and clear alpha (reset it to 1 [fully lit] for next light). LightRenderer.Render(light); // Clear light's dirty flag. light.Dirty = false; } // Switch render target back to default. Device.SetRenderTargets(Textures.GetOriginalRenderTargetBindings()); // Blend original scene and lightmap and present to backbuffer. LightMapRenderer.Present(); // Clear hulls dirty flag. Hulls.Dirty = false; }