///<summary> ///Constructor ///</summary> public TestDemo() { test_Shader = new CombineShader(); m_ProjectionMatrix = Matrix4.Identity; m_ModelViewMatrix = Matrix4.Identity; }
/// <summary> /// Creates a new deferred renderer. /// </summary> /// <param name="width">Width of the render targets.</param> /// <param name="height">Height of the render targets.</param> public DeferredRenderer(int width, int height) { this.lightCube = Model.CreateCube(1.1f); this.Width = width; this.Height = height; // Create graphics buffer this.PositionBuffer = CreateTexture(width, height); this.NormalBuffer = CreateTexture(width, height); this.DiffuseLightBuffer = CreateTexture(width, height); this.SpecularLightBuffer = CreateTexture(width, height); this.sceneBuffer = CreateTexture(width, height); // Create 3d shaders this.geometryPixelShader = new ShaderFragment(ShaderType.FragmentShader); this.geometryPixelShader.Compile( @"#version 410 core uniform sampler2D meshNormalMap; uniform sampler2D meshDiffuseTexture; uniform float mtlSpecularPower; in vec3 position; in vec3 normal; in vec3 tangent; in vec3 bitangent; in vec2 uv; layout(location = 0) out vec4 positionOut; layout(location = 1) out vec4 normalOut; void main() { if(texture(meshDiffuseTexture, uv).a < 0.5f) discard; positionOut = vec4(position, 1); vec3 bump = normalize(2.0f * texture(meshNormalMap, uv).xyz - 1.0f); normalOut.xyz = mat3(tangent, bitangent, normal) * bump; normalOut.w = mtlSpecularPower; //normalOut.xyz = normal; }"); this.lightShader = new LightShader(); // Create post processing shaders this.gammaCorrectionShader = new GammaCorrectionShader(); this.gammaCorrectionShader.Gamma = 2.2f; this.lightScatteringShader = new LightScatteringShader(); this.lightScatteringShader.OcclusionBuffer = this.NormalBuffer; this.ditheringShader = new DitheringShader(); this.tonemappingShader = new TonemappingShader(); this.tonemappingShader.HdrExposure = 1.25f; this.tonemappingShader.WhitePoint = 5.0f; this.blurShader = new BlurShader(); this.blurShader.BlurStrength = new Vector2(0.04f, 0.04f); this.bloomCombineShader = new CombineShader(); this.highPassShader = new HighPassShader(); this.highPassShader.BloomThreshold = 0.95f; // Create post processing stages this.preBloomStages = new PostProcessingStage(this.lightScatteringShader) { TargetTexture = CreateTexture(width, height), Stage = new PostProcessingStage(this.gammaCorrectionShader) { TargetTexture = CreateTexture(width, height) } }; this.bloomStages = new PostProcessingStage(this.highPassShader) { TargetTexture = CreateTexture(width, height), Stage = new PostProcessingStage(this.blurShader) { TargetTexture = CreateTexture(width / 2, height / 2), Stage = new PostProcessingStage(this.blurShader) { TargetTexture = CreateTexture(width / 2, height / 2), Stage = new PostProcessingStage(this.bloomCombineShader) { TargetTexture = CreateTexture(width, height), } } } }; this.postBloomStages = new PostProcessingStage(this.tonemappingShader) { TargetTexture = CreateTexture(width, height), Stage = new PostProcessingStage(this.ditheringShader) { TargetTexture = CreateTexture(width, height), } }; //this.tonemapping = new PostProcessingStage(this.tonemappingShader); //this.tonemapping.TargetTexture = CreateTexture(width, height); this.depthBuffer = new RenderBuffer(width, height); this.frameBufferGeometry = new FrameBuffer(this.depthBuffer, this.PositionBuffer, this.NormalBuffer); this.frameBufferClearDiffuse = new FrameBuffer(this.DiffuseLightBuffer); this.frameBufferClearSpecular = new FrameBuffer(this.SpecularLightBuffer); this.frameBufferLights = new FrameBuffer(this.depthBuffer, this.DiffuseLightBuffer, this.SpecularLightBuffer); this.frameBufferScene = new FrameBuffer(this.depthBuffer, this.sceneBuffer); this.DefaultShader = new ObjectShader(); }