public TerrainRaymarcher(GraphicsDevice graphicsDevice, float aspectRatio) { var shaderMacros = new List<EffectData.ShaderMacro>(); #if CONEMAPPING_RAYMARCH computeRelaxedConeShader = new ShaderAutoReload("shader/computerelaxedconemap.fx", GraphicsDevice); shaderMacros.Add(new EffectData.ShaderMacro("CONEMAPPING_RAYMARCH", "1")); #else maxmapGenShader = new ShaderAutoReload("shader/maxmapgen.fx", graphicsDevice); #endif terrainShader = new ShaderAutoReload("shader/terrainRaymarch.fx", graphicsDevice, shaderMacros); terrainShader.Effect.Parameters["ScreenAspectRatio"].SetValue(aspectRatio ); terrainShader.OnReload += () => SetupTerrainConstants(graphicsDevice); // linear sampler var samplerStateDesc = SharpDX.Direct3D11.SamplerStateDescription.Default(); samplerStateDesc.AddressV = SharpDX.Direct3D11.TextureAddressMode.Border; samplerStateDesc.AddressU = SharpDX.Direct3D11.TextureAddressMode.Border; samplerStateDesc.Filter = SharpDX.Direct3D11.Filter.MinMagMipLinear; samplerStateDesc.BorderColor = Color4.Black; linearBorderSamplerState = SamplerState.New(graphicsDevice, "TerrainHeightmapSampler", samplerStateDesc); }
void WPFHost.IScene.Attach(WPFHost.ISceneHost host) { this.host = host; camera = new Camera((float)host.RenderTargetWidth / host.RenderTargetHeight, (float)(75.0 * Math.PI / 180.0), 0.1f, 10000.0f); // device setup if (host.Device == null) throw new Exception("Scene host device is null"); GraphicsDevice = GraphicsDevice.New(host.Device); RenderTarget2D backbufferRenderTarget = RenderTarget2D.New(GraphicsDevice, host.RenderTargetView, true); GraphicsDevice.Presenter = new RenderTargetGraphicsPresenter(GraphicsDevice, backbufferRenderTarget); GraphicsDevice.SetRenderTargets(backbufferRenderTarget); #if RAYMARCH_TERRAIN terrain = new TerrainRaymarcher(GraphicsDevice, (float)host.RenderTargetWidth / host.RenderTargetHeight); #else terrain = new TerrainRasterizer(GraphicsDevice); #endif terrain.HeightScale = terrainScale; // load shader sphereBillboardShader = new ShaderAutoReload("shader/spherebillboards.fx", GraphicsDevice); // vertex input layout sphereVertexInputLayout = VertexInputLayout.New(VertexBufferLayout.New(0, VertexElement.Position(SharpDX.DXGI.Format.R32G32B32_Float))); // generate sky skyShader = new ShaderAutoReload("shader/sky.fx", GraphicsDevice); skyShader.OnReload += ReGenerateSkyCubeMap; skyCubemap = RenderTargetCube.New(GraphicsDevice, CUBEMAP_RES, 0, PixelFormat.R8G8B8A8.SNorm); TimeOfDay = timeOfDay; // constant buffer to defaults SetupConstants(); }
public TerrainRasterizer(GraphicsDevice graphicsDevice) { clipmapRenderer = new InstancedGeomClipMapping(graphicsDevice, 8.0f, 8, 4); shader = new ShaderAutoReload("shader/terrainRasterize.fx", graphicsDevice); shader.OnReload += () => SetupTerrainConstants(graphicsDevice); }