public DeferredRenderer(SurfaceManager surfaces) { this.surfaces = surfaces; gTarget.Attach(FramebufferAttachment.ColorAttachment0, diffuseBuffer); gTarget.Attach(FramebufferAttachment.ColorAttachment1, normalBuffer); gTarget.Attach(FramebufferAttachment.ColorAttachment2, depthBuffer); gTarget.Attach(FramebufferAttachment.DepthAttachment, depthMaskBuffer); renderTo(gTarget, new ScreenCoords(0, 0)); GL.DrawBuffers(3, new [] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2, }); renderTo(null, new ScreenCoords(0, 0)); accumTarget.Attach(FramebufferAttachment.ColorAttachment0, accumBuffer); compositeSurface = new PostProcessSurface() .WithShader(surfaces.Shaders["Deferred/compose"]) .AndSettings( new TextureUniform("albedoTexture", diffuseBuffer, TextureUnit.Texture0), new TextureUniform("lightTexture", accumBuffer, TextureUnit.Texture1) ); debugSurfaces = new[] { diffuseBuffer, normalBuffer, depthBuffer, accumBuffer } .Select(createDebugSurface).ToArray(); surfaces.InjectDeferredBuffer(normalBuffer, depthBuffer); }
protected override void OnLoad(EventArgs e) { this.shaderMan = new ShaderManager(); var shaderLoader = ShaderFileLoader.CreateDefault("shaders"); // load all shaders var shaders = shaderLoader.Load("").ToList(); this.shaderMan.Add(shaders); var layerShader = this.shaderMan.MakeShaderProgram() .WithVertexShader("copy").WithFragmentShader("copy") .As("layer"); var copyShader = this.shaderMan.MakeShaderProgram() .WithVertexShader("post").WithFragmentShader("copy") .As("copypost"); var wispShader = this.shaderMan.MakeShaderProgram() .WithVertexShader("wisp").WithFragmentShader("wisp") .As("wisp"); var rayShader = this.shaderMan.MakeShaderProgram() .WithVertexShader("crepuscularrays") .WithGeometryShader("crepuscularrays") .WithFragmentShader("crepuscularrays") .As("crepuscularrays"); this.renderTexture = new Texture(1, 1); this.renderTexture.SetParameters(TextureMinFilter.Linear, TextureMagFilter.Linear, TextureWrapMode.ClampToBorder, TextureWrapMode.ClampToBorder); this.renderTarget = new RenderTarget(this.renderTexture); var renderTextureUniform = new TextureUniform("diffuseTexture", this.renderTexture); this.copyToScreen = new PostProcessSurface(); this.copyToScreen.AddSettings(renderTextureUniform, new ColorUniform("color", Color.White)); copyShader.UseOnSurface(this.copyToScreen); this.raySurface = new VertexSurface<CrepuscularRayVertex>(PrimitiveType.Points); this.raySurface.AddSettings(renderTextureUniform); rayShader.UseOnSurface(this.raySurface); var rayGeo = new CrepuscularRayGeometry(this.raySurface); const int layerCount = 4; const float maxBrightness = 0.03f; const float brightnessStep = maxBrightness / layerCount; this.layers = Enumerable.Range(0, layerCount).Reverse() .Select(i => new Layer(layerShader, wispShader, rayGeo, "layer" + i, GameMath.Sqrt(brightnessStep * i), i * i * 5)) .ToList(); InputManager.Initialize(this.Mouse); }
public Heatmap(ShaderManager shaderMan, SurfaceManager surfaceMan) { this.texture = new Texture(); this.texture.Resize(size, size, PixelInternalFormat.R32f); this.texture.SetParameters(TextureMinFilter.Linear, TextureMagFilter.Linear, TextureWrapMode.ClampToBorder, TextureWrapMode.ClampToBorder); this.renderTarget = new RenderTarget(this.texture); this.tempTexture = new Texture(); this.tempTexture.Resize(size, size, PixelInternalFormat.R32f); this.tempTexture.SetParameters(TextureMinFilter.Linear, TextureMagFilter.Linear, TextureWrapMode.ClampToBorder, TextureWrapMode.ClampToBorder); this.tempRenderTarget = new RenderTarget(this.tempTexture); var sampleStep = 1f / size; var blurShader = shaderMan.MakeShaderProgram("blur"); blurHSurface = new PostProcessSurface(); blurHSurface.AddSettings( new Vector2Uniform("sampleStep", new Vector2(sampleStep, 0)), new TextureUniform("diffuse", texture) ); blurShader.UseOnSurface(this.blurHSurface); blurVSurface = new PostProcessSurface(); blurVSurface.AddSettings( new Vector2Uniform("sampleStep", new Vector2(0, sampleStep)), new TextureUniform("diffuse", tempTexture) ); blurShader.UseOnSurface(this.blurVSurface); var spectrum = new Texture("data/images/spectrum.png"); spectrum.SetParameters(TextureMinFilter.Linear, TextureMagFilter.Linear, TextureWrapMode.ClampToEdge, TextureWrapMode.ClampToEdge); this.heatSurface = new IndexedSurface <HeatmapVertex>(); heatSurface.AddSettings( new TextureUniform("heatmap", this.texture), new TextureUniform("spectrum", spectrum, TextureUnit.Texture1), surfaceMan.ModelviewMatrix, surfaceMan.ProjectionMatrix ); shaderMan.MakeShaderProgram("render-heatmap").UseOnSurface(this.heatSurface); this.heatGeo = new HeatmapGeometry(this.heatSurface); }
public GameRenderer() { this.deferredBuffer = new DeferredBuffer(); this.shaders = new ShaderManager(); this.surfaces = new SurfaceManager(this.shaders, this.deferredBuffer); this.sprites = new SpriteManager(this.surfaces); this.debugDeferred = new PostProcessSurface(); this.debugDeferred.AddSettings(this.deferredBuffer); this.shaders.DebugDeferred.UseOnSurface(this.debugDeferred); this.copyLightToScreen = new PostProcessSurface(); this.copyLightToScreen.AddSetting(this.deferredBuffer.LightAccumulationTexture); this.shaders.PostCopy.UseOnSurface(this.copyLightToScreen); this.shaderReloadTimer = Stopwatch.StartNew(); }
public Layer(ISurfaceShader shader, ISurfaceShader wispShader, CrepuscularRayGeometry rayGeo, string filename, float brightness, int wisps) { this.rayGeo = rayGeo; var texture = new Texture("gfx/" + filename + ".png", true); this.surface = new PostProcessSurface(); this.surface.AddSettings( new TextureUniform("diffuseTexture", texture), new ColorUniform("color", Color.GrayScale((byte)(255 * brightness))) ); shader.UseOnSurface(this.surface); this.wispSurface = new IndexedSurface<UVColorVertexData>(); wispShader.UseOnSurface(this.wispSurface); this.wispGeo = new Sprite2DGeometry(this.wispSurface) { Color = Color.White.WithAlpha() }; this.wisps = Enumerable.Range(0, wisps) .Select(i => new Wisp()).ToList(); }