private void PrepareState() { if (m_Passes != null) { return; } unsafe { AOC_Texture = new DataTexture<float> { Name = "AOC_Texture", InternalFormat = PixelInternalFormat.R8, Data2D = new float[m_AocTextureSize, m_AocTextureSize], Params = new TextureBase.Parameters { GenerateMipmap = true, MinFilter = TextureMinFilter.LinearMipmapLinear, MagFilter = TextureMagFilter.Linear, }}; NormalDepth_Texture = new DataTexture<Vector4> { Name = "NormalDepth_Texture", InternalFormat = PixelInternalFormat.Rgba32f, //Format = PixelFormat.DepthComponent, Data2D = new Vector4[m_SolidModeTextureSize, m_SolidModeTextureSize], Params = new TextureBase.Parameters { GenerateMipmap = false, MinFilter = TextureMinFilter.Nearest, MagFilter = TextureMagFilter.Nearest, }}; Depth_Texture = new DataTexture<float> { Name = "Depth_Texture", InternalFormat = PixelInternalFormat.DepthComponent32f, Format = PixelFormat.DepthComponent, Data2D = new float[m_SolidModeTextureSize, m_SolidModeTextureSize], Params = new TextureBase.Parameters { GenerateMipmap = false, MinFilter = TextureMinFilter.Nearest, MagFilter = TextureMagFilter.Nearest, }}; } var ortho = Matrix4.CreateOrthographic (1, 1, (float)NEAR, (float)FAR); m_Projection = new MatrixStack ().Push (ortho); m_TransformationStack = new MatrixStack ().Push (m_Projection); m_UniformState = new UniformState { {"pRayMarchStepFactor", () => this.RayMarchStepFactor}, {"k1", () => this.K1}, {"k2", () => this.K2}, {"k3", () => this.K3}, {"k4", () => this.K4}, {"time", () => this.Time}, }; /*// var firstPassSolid = RenderPassFactory.CreateFullscreenQuad ( "raymarch", "System5", ValueProvider.Create(() => new Vector2(m_SolidModeTextureSize, m_SolidModeTextureSize)), (window) => { SetCamera (window); }, (window) => { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Enable (EnableCap.DepthTest); GL.DepthMask(true); GL.DepthFunc (DepthFunction.Less); GL.Disable (EnableCap.Blend); }, //pass state new FramebufferBindingSet { { FramebufferAttachment.DepthAttachment, Depth_Texture }, { "normal_depth", NormalDepth_Texture } }, m_UniformState );*/ var firstPassSolid = new SeparateProgramPass ( "raymarch", (window) => { SetCamera (window); }, (window) => { /*GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Enable (EnableCap.DepthTest); GL.DepthMask(true); GL.DepthFunc (DepthFunction.Less); GL.Disable (EnableCap.Blend);*/ }, x => { GLExtensions.DispatchCompute(m_SolidModeTextureSize/(4 * 8), m_SolidModeTextureSize/(4 * 8), 1); }, RenderPass.GetShaders ("raymarch", "System5"), //pass state new ImageBindingSet { { "u_NormalDepth", NormalDepth_Texture } }, m_UniformState); AocParameters = new AocParameters { TextureSize = 512, OccConstantArea = false, OccMaxDist = 40, OccMinSampleRatio = 0.5f, OccPixmax = 100, OccPixmin = 2, SamplesCount = 32, Strength = 2.3f, Bias = 0.4f }; var aocPassSolid = RenderPassFactory.CreateAoc ( NormalDepth_Texture, AOC_Texture, m_TransformationStack, new MatrixInversion(m_TransformationStack), m_Projection, new MatrixInversion(m_Projection), AocParameters ); // var thirdPassSolid = RenderPassFactory.CreateFullscreenQuad ( "lighting", "System5", ValueProvider.Create(() => m_Viewport), (window) => { SetCamera (window); }, (window) => { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Enable (EnableCap.DepthTest); GL.DepthMask(true); GL.DepthFunc (DepthFunction.Less); GL.Disable (EnableCap.Blend); }, //pass state FramebufferBindingSet.Default, m_UniformState, new TextureBindingSet { {"normaldepth_texture", NormalDepth_Texture }, { "aoc_texture", AOC_Texture }, } ); m_Passes = new RenderPass[]{ firstPassSolid, aocPassSolid, thirdPassSolid }; m_Manip = new OrbitManipulator (m_Projection); //m_Grid = new Grid (m_TransformationStack); m_TransformationStack.Push (m_Manip.RT); m_UniformState.Set ("modelview_transform", m_Manip.RT); m_UniformState.Set ("modelviewprojection_transform", m_TransformationStack); m_UniformState.Set ("projection_transform", m_Projection); m_UniformState.Set ("projection_inv_transform", new MatrixInversion(m_Projection)); m_UniformState.Set ("modelview_inv_transform", new MatrixInversion(m_Manip.RT)); m_UniformState.Set ("modelviewprojection_inv_transform", new MatrixInversion(m_TransformationStack)); PrepareState (); }
protected virtual void ParameterSetup() { // AocParameters = new AocParameters { TextureSize = 1024, OccConstantArea = false, OccMaxDist = 40, OccMinSampleRatio = 0.5f, OccPixmax = 44, OccPixmin = 2, SamplesCount = 32, Strength = 1, Bias = 0.2f, BlurEdgeAvoidance = 0.2f }; // m_SunLight = new Light { Direction = new Vector3(1, 1, 1), Type = LightType.Directional }; SunLightImpl = new ShadowImplementationParameters(m_SunLight); SunLightImpl.ImplementationType = ShadowImplementationType.Soft2; // ShadowTextureSize = 2048; SolidModeTextureSize = 2048; LightSize = 0.1f; ExpMapLevel = 1; ExpMapNsamples = 15; ExpMapRange = 0.0055f; ExpMapRangeK = 0.85f; }