public void RenderLightmaps(Camera renderCamera, DwarfTime gameTime, GraphicsDevice graphicsDevice, Shader effect, Matrix worldMatrix) { RasterizerState state = RasterizerState.CullNone; RasterizerState origState = graphicsDevice.RasterizerState; effect.CurrentTechnique = effect.Techniques[Shader.Technique.Lightmap]; effect.SelfIlluminationTexture = ChunkData.IllumMap; effect.MainTexture = ChunkData.Tilemap; effect.SunlightGradient = ChunkData.SunMap; effect.AmbientOcclusionGradient = ChunkData.AmbientMap; effect.TorchlightGradient = ChunkData.TorchMap; effect.LightRampTint = Color.White; effect.VertexColorTint = Color.White; effect.SelfIlluminationEnabled = true; effect.EnableShadows = GameSettings.Default.UseDynamicShadows; graphicsDevice.RasterizerState = state; Graphics.BlendState = BlendState.NonPremultiplied; List <VoxelChunk> renderListCopy = RenderList.ToArray().ToList(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); foreach (VoxelChunk chunk in renderListCopy) { Graphics.SetRenderTarget(chunk.Primitive.Lightmap); Graphics.Clear(ClearOptions.Target, Color.Black, 0.0f, 0); chunk.Render(Graphics); } } Graphics.SetRenderTarget(null); effect.SelfIlluminationEnabled = false; effect.CurrentTechnique = effect.Techniques[Shader.Technique.Textured]; graphicsDevice.RasterizerState = origState; }
public void RenderShadowmap(Shader effect, GraphicsDevice graphicsDevice, ShadowRenderer shadowRenderer, Matrix worldMatrix, Texture2D tilemap) { Vector3[] corners = new Vector3[8]; Camera tempCamera = new Camera(World, camera.Target, camera.Position, camera.FOV, camera.AspectRatio, camera.NearPlane, 30); tempCamera.GetFrustrum().GetCorners(corners); BoundingBox cameraBox = MathFunctions.GetBoundingBox(corners); cameraBox = cameraBox.Expand(1.0f); effect.World = worldMatrix; effect.MainTexture = tilemap; shadowRenderer.SetupViewProj(cameraBox); shadowRenderer.PrepareEffect(effect, false); shadowRenderer.BindShadowmapEffect(effect); shadowRenderer.BindShadowmap(graphicsDevice); List <VoxelChunk> renderListCopy = RenderList.ToArray().ToList(); foreach (VoxelChunk chunk in renderListCopy) { foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); chunk.Render(Graphics); } } shadowRenderer.UnbindShadowmap(graphicsDevice); effect.CurrentTechnique = effect.Techniques[Shader.Technique.Textured]; effect.SelfIlluminationEnabled = false; }
public void RenderLightmaps(Camera renderCamera, DwarfTime gameTime, GraphicsDevice graphicsDevice, Effect effect, Matrix worldMatrix) { RasterizerState state = RasterizerState.CullNone; RasterizerState origState = graphicsDevice.RasterizerState; effect.CurrentTechnique = effect.Techniques["Lightmap"]; effect.Parameters["xIllumination"].SetValue(ChunkData.IllumMap); effect.Parameters["xTexture"].SetValue(ChunkData.Tilemap); effect.Parameters["xSunGradient"].SetValue(ChunkData.SunMap); effect.Parameters["xAmbientGradient"].SetValue(ChunkData.AmbientMap); effect.Parameters["xTorchGradient"].SetValue(ChunkData.TorchMap); effect.Parameters["xTint"].SetValue(new Vector4(1.0f, 1.0f, 1.0f, 1.0f)); effect.Parameters["SelfIllumination"].SetValue(1); effect.Parameters["xEnableShadows"].SetValue(GameSettings.Default.UseDynamicShadows ? 1 : 0); graphicsDevice.RasterizerState = state; Graphics.BlendState = BlendState.NonPremultiplied; List<VoxelChunk> renderListCopy = RenderList.ToArray().ToList(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); foreach (VoxelChunk chunk in renderListCopy) { Graphics.SetRenderTarget(chunk.Primitive.Lightmap); Graphics.Clear(ClearOptions.Target, Color.Black, 0.0f, 0); chunk.Render(Graphics); } } Graphics.SetRenderTarget(null); effect.Parameters["SelfIllumination"].SetValue(0); effect.CurrentTechnique = effect.Techniques["Textured"]; graphicsDevice.RasterizerState = origState; }
public void RenderSelectionBuffer(Shader effect, GraphicsDevice graphicsDevice, Matrix viewmatrix) { effect.CurrentTechnique = effect.Techniques[Shader.Technique.SelectionBuffer]; effect.MainTexture = ChunkData.Tilemap; effect.World = Matrix.Identity; effect.View = viewmatrix; effect.SelectionBufferColor = Vector4.Zero; List <VoxelChunk> renderListCopy = RenderList.ToArray().ToList(); foreach (VoxelChunk chunk in renderListCopy) { foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); chunk.Render(Graphics); } } }
public void Render(Camera renderCamera, DwarfTime gameTime, GraphicsDevice graphicsDevice, Shader effect, Matrix worldMatrix) { if (GameSettings.Default.UseLightmaps) { effect.CurrentTechnique = effect.Techniques[Shader.Technique.TexturedWithLightmap]; effect.EnableShadows = false; } else { effect.CurrentTechnique = effect.Techniques[Shader.Technique.Textured]; effect.EnableShadows = GameSettings.Default.UseDynamicShadows; } effect.SelfIlluminationTexture = ChunkData.IllumMap; effect.MainTexture = ChunkData.Tilemap; effect.SunlightGradient = ChunkData.SunMap; effect.AmbientOcclusionGradient = ChunkData.AmbientMap; effect.TorchlightGradient = ChunkData.TorchMap; effect.LightRampTint = Color.White; effect.VertexColorTint = Color.White; effect.SelfIlluminationEnabled = true; effect.EnableShadows = GameSettings.Default.UseDynamicShadows; effect.World = Matrix.Identity; List <VoxelChunk> renderListCopy = RenderList.ToArray().ToList(); foreach (VoxelChunk chunk in renderListCopy) { foreach (EffectPass pass in effect.CurrentTechnique.Passes) { if (GameSettings.Default.UseLightmaps) { effect.LightMap = chunk.Primitive.Lightmap; effect.PixelSize = new Vector2(1.0f / chunk.Primitive.Lightmap.Width, 1.0f / chunk.Primitive.Lightmap.Height); } pass.Apply(); chunk.Render(Graphics); } } effect.SelfIlluminationEnabled = false; effect.CurrentTechnique = effect.Techniques[Shader.Technique.Textured]; }
public void Render(Camera renderCamera, DwarfTime gameTime, GraphicsDevice graphicsDevice, Effect effect, Matrix worldMatrix) { if (GameSettings.Default.UseLightmaps) { effect.CurrentTechnique = effect.Techniques["Textured_From_Lightmap"]; effect.Parameters["xEnableShadows"].SetValue(0); } else { effect.CurrentTechnique = effect.Techniques["Textured"]; effect.Parameters["xEnableShadows"].SetValue(GameSettings.Default.UseDynamicShadows ? 1 : 0); } effect.Parameters["xIllumination"].SetValue(ChunkData.IllumMap); effect.Parameters["xTexture"].SetValue(ChunkData.Tilemap); effect.Parameters["xSunGradient"].SetValue(ChunkData.SunMap); effect.Parameters["xAmbientGradient"].SetValue(ChunkData.AmbientMap); effect.Parameters["xTorchGradient"].SetValue(ChunkData.TorchMap); effect.Parameters["xTint"].SetValue(new Vector4(1.0f, 1.0f, 1.0f, 1.0f)); effect.Parameters["SelfIllumination"].SetValue(1); effect.Parameters["xWorld"].SetValue(Matrix.Identity); List<VoxelChunk> renderListCopy = RenderList.ToArray().ToList(); foreach (VoxelChunk chunk in renderListCopy) { foreach (EffectPass pass in effect.CurrentTechnique.Passes) { if (GameSettings.Default.UseLightmaps) { effect.Parameters["xLightmap"].SetValue(chunk.Primitive.Lightmap); effect.Parameters["pixelSize"].SetValue(new Vector2(1.0f/chunk.Primitive.Lightmap.Width, 1.0f/chunk.Primitive.Lightmap.Height)); } pass.Apply(); chunk.Render(Graphics); } } effect.Parameters["SelfIllumination"].SetValue(0); effect.CurrentTechnique = effect.Techniques["Textured"]; }