public void RenderLights(DeviceContext context, Camera camera, List <RenderableLightInst> lights) { //instanced rendering of all other lights, using appropriate shapes //blend mode: additive var ps = (MSAASampleCount > 1) ? LightMSPS : LightPS; context.VertexShader.Set(LightVS); context.PixelShader.Set(ps); LightVSVars.Vars.ViewProj = Matrix.Transpose(camera.ViewProjMatrix); LightVSVars.Vars.CameraPos = new Vector4(camera.Position, 0.0f); LightVSVars.Vars.LightType = 0; LightVSVars.Vars.IsLOD = 0; LightVSVars.Vars.Pad0 = 0; LightVSVars.Vars.Pad1 = 0; LightVSVars.Update(context); LightVSVars.SetVSCBuffer(context, 0); LightPSVars.Vars.ViewProjInv = Matrix.Transpose(camera.ViewProjInvMatrix); LightPSVars.Vars.CameraPos = new Vector4(camera.Position, 0.0f); LightPSVars.Vars.EnableShadows = 0; LightPSVars.Vars.RenderMode = 0; LightPSVars.Vars.RenderModeIndex = 1; LightPSVars.Vars.RenderSamplerCoord = 0; LightPSVars.Vars.LightType = 0; LightPSVars.Vars.IsLOD = 0; LightPSVars.Vars.SampleCount = (uint)MSAASampleCount; LightPSVars.Vars.SampleMult = 1.0f / MSAASampleCount; LightPSVars.Update(context); LightPSVars.SetPSCBuffer(context, 0); context.PixelShader.SetShaderResources(0, GBuffers.DepthSRV); context.PixelShader.SetShaderResources(2, GBuffers.SRVs); for (int i = 0; i < lights.Count; i++) { var li = lights[i]; var rl = li.Light; LightInstVars.Vars.InstPosition = li.EntityPosition + li.EntityRotation.Multiply(rl.Position) - camera.Position; LightInstVars.Vars.InstDirection = li.EntityRotation.Multiply(rl.Direction); LightInstVars.Vars.InstTangentX = li.EntityRotation.Multiply(rl.TangentX); LightInstVars.Vars.InstTangentY = li.EntityRotation.Multiply(rl.TangentY); LightInstVars.Vars.InstCapsuleExtent = li.EntityRotation.Multiply(rl.CapsuleExtent); LightInstVars.Vars.InstCullingPlaneNormal = li.EntityRotation.Multiply(rl.CullingPlaneNormal); LightInstVars.Vars.InstColour = rl.Colour; LightInstVars.Vars.InstIntensity = rl.Intensity; LightInstVars.Vars.InstFalloff = rl.Falloff; LightInstVars.Vars.InstFalloffExponent = rl.FalloffExponent; LightInstVars.Vars.InstConeInnerAngle = rl.ConeInnerAngle; LightInstVars.Vars.InstConeOuterAngle = rl.ConeOuterAngle; LightInstVars.Vars.InstType = (uint)rl.Type; LightInstVars.Vars.InstCullingPlaneOffset = rl.CullingPlaneOffset; LightInstVars.Update(context); LightInstVars.SetVSCBuffer(context, 1); LightInstVars.SetPSCBuffer(context, 2); switch (rl.Type) { case LightType.Point: LightSphere.Draw(context); break; case LightType.Spot: LightCone.Draw(context); break; case LightType.Capsule: LightCapsule.Draw(context); break; default: break; } } context.VertexShader.Set(null); context.PixelShader.Set(null); context.PixelShader.SetShaderResources(0, null, null, null); context.PixelShader.SetSamplers(0, null, null); }