/// <summary> /// creates non-separable filter pass /// </summary> public static RenderPass CreateFilter( string filterName, string filterNamespace, TextureBase source, TextureBase result) { var viewport = ValueProvider.Create (() => new Vector2 (result.Width, result.Height)); var uniformState = new UniformState (); uniformState.Set ("viewport_size", viewport); var _1stPass = CreateFullscreenQuad (filterName, filterNamespace, viewport, null , window => { GL.Clear (ClearBufferMask.ColorBufferBit); GL.Disable (EnableCap.DepthTest); GL.Disable (EnableCap.Blend); //pass state }, new FramebufferBindingSet {{ "OUT_FragData_result", result }}, uniformState, new TextureBindingSet {{ "source_texture", source }}); return _1stPass; }
unsafe void PrepareState() { if (m_AttributeState != null) { UpdateGrid (); PositionBuffer.Publish (); ParameterBuffer.Publish (); m_State.Activate (); return; } m_Count = m_GridDiameter / m_GridDensity + 1; unsafe { PositionBuffer = new BufferObjectCompact<Vector3> (sizeof(Vector3), 4 * m_Count + 2) { Name = "position_buffer", Usage = BufferUsageHint.DynamicDraw }; ParameterBuffer = new BufferObjectCompact<float> (sizeof(float), 4 * m_Count + 2) { Name = "parameter_buffer", Usage = BufferUsageHint.DynamicDraw }; } m_UniformState = new UniformState ().Set ("modelview_transform", m_CameraMvp.ModelViewProjection); m_AttributeState = new ArrayObject (new VertexAttribute { AttributeName = "pos", Buffer = PositionBuffer, Size = 3, Type = VertexAttribPointerType.Float }, new VertexAttribute { AttributeName = "param", Buffer = ParameterBuffer, Size = 1, Type = VertexAttribPointerType.Float }); m_Program = new Program ("coordinate_grid_program", GetShaders ("GridRenderPass", "").ToArray ()); m_State = new State (null, m_AttributeState, m_Program, m_UniformState); PrepareState (); }
//computed world-space normal and clipping space depth (depth in range 0, 1) //where the result will be stored, results will be stored to the first component of the texture //how many samples will be used for occlusion estimation public static RenderPass CreateAoc( TextureBase normalDepth, TextureBase aoc, IValueProvider<Matrix4> modelviewprojection, IValueProvider<Matrix4> modelviewprojection_inv, IValueProvider<Matrix4> projection, IValueProvider<Matrix4> projection_inv, IValueProvider<int> samplesCount, IValueProvider<float> occ_max_dist = null, IValueProvider<float> occ_pixmax = null, IValueProvider<float> occ_pixmin = null, IValueProvider<float> occ_min_sample_ratio = null, IValueProvider<bool> occ_constant_area = null, IValueProvider<float> strength = null, IValueProvider<float> bias = null) { var viewport = ValueProvider.Create (() => new Vector2 (aoc.Width, aoc.Height)); // var sampling_pattern = ValueProvider.Create // ( // () => MathHelper2.RandomVectorSet (256, new Vector2 (1, 1)) // ); var current_pattern = MathHelper2.RandomVectorSet (256, new Vector2 (1, 1)); var sampling_pattern = ValueProvider.Create ( () => current_pattern ); var uniformState = new UniformState (); uniformState.Set ("viewport_size", viewport); uniformState.Set ("sampling_pattern", sampling_pattern); uniformState.Set ("sampling_pattern_len", samplesCount); uniformState.Set ("modelviewprojection_transform", modelviewprojection); uniformState.Set ("modelviewprojection_inv_transform", modelviewprojection_inv); uniformState.Set ("projection_transform", projection); uniformState.Set ("projection_inv_transform", projection_inv); uniformState.Set ("OCCLUDER_MAX_DISTANCE", occ_max_dist ?? ValueProvider.Create(35.0f)); uniformState.Set ("PROJECTED_OCCLUDER_DISTANCE_MAX_SIZE", occ_pixmax ?? ValueProvider.Create(35.0f)); uniformState.Set ("PROJECTED_OCCLUDER_DISTANCE_MIN_SIZE", occ_pixmin ?? ValueProvider.Create(2.0f)); uniformState.Set ("MINIMAL_SAMPLES_COUNT_RATIO", occ_min_sample_ratio ?? ValueProvider.Create(0.1f)); uniformState.Set ("USE_CONSTANT_OCCLUDER_PROJECTION", occ_constant_area ?? ValueProvider.Create(false)); uniformState.Set ("AOC_STRENGTH", strength ?? ValueProvider.Create(2f)); uniformState.Set ("AOC_BIAS", bias ?? ValueProvider.Create(-0.5f)); return CreateFullscreenQuad ( "aoc", "RenderPassFactory", viewport, null, window => { GL.Clear (ClearBufferMask.ColorBufferBit); GL.Disable (EnableCap.DepthTest); GL.Disable (EnableCap.Blend); }, new FramebufferBindingSet{{ "OUT_FragData_aoc", aoc }}, uniformState, new TextureBindingSet {{ "normaldepth_texture", normalDepth }}); }
// public static RenderPass CreateBilateralFilter( TextureBase source, TextureBase interm, TextureBase result, IValueProvider<Vector4> k) { UniformState parameters = new UniformState(); parameters.Set ("K", k); return CreateSeparableFilter("bilateralfilter", "RenderPassFactory", source, interm, result, parameters); }
unsafe void PrepareState() { if (m_ParticleRenderingState != null) { Simulate (DateTime.Now); PositionBuffer.Publish (); ColorAndSizeBuffer.Publish (); m_SystemState.Activate (); return; } unsafe { //VelocityBuffer = new BufferObject<Vector4> (sizeof(Vector4), size) { Name = "velocity_buffer", Usage = BufferUsageHint.DynamicDraw }; PositionBuffer = new BufferObject<Vector4> (sizeof(Vector4), PARTICLES_COUNT) { Name = "position_buffer", Usage = BufferUsageHint.DynamicDraw }; ColorAndSizeBuffer = new BufferObject<Vector4> (sizeof(Vector4), PARTICLES_COUNT) { Name = "colorandsize_buffer", Usage = BufferUsageHint.DynamicDraw }; } m_Projection = new MatrixStack ().Push (Matrix4.CreateOrthographic (14, 14, -1, 1)); m_TransformationStack = new MatrixStack (m_Projection).Push (Matrix4.Identity).Push (Matrix4.Identity); m_UniformState = new UniformState ().Set ("color", new Vector4 (0, 0, 1, 1)).Set ("red", 1.0f).Set ("green", 0.0f).Set ("blue", 1.0f).Set ("colors", new float[] { 0, 1, 0, 1 }).Set ("colors2", new Vector4[] { new Vector4 (1, 0.1f, 0.1f, 0), new Vector4 (1, 0, 0, 0), new Vector4 (1, 1, 0.1f, 0) }).Set ("modelview_transform", m_TransformationStack); var sprite = new[] { new Vector3 (-1, -1, 0), new Vector3 (-1, 1, 0), new Vector3 (1, 1, 0), new Vector3 (1, -1, 0) }; var vdata_buffer = new BufferObject<Vector3> (sizeof(Vector3)) { Name = "vdata_buffer", Usage = BufferUsageHint.DynamicDraw, Data = sprite }; m_ParticleRenderingState = new ArrayObject (new VertexAttribute { AttributeName = "vertex_pos", Buffer = vdata_buffer, Size = 3, Type = VertexAttribPointerType.Float }, new VertexAttribute { AttributeName = "sprite_pos", Buffer = PositionBuffer, Divisor = 1, Size = 4, Stride = 0, Type = VertexAttribPointerType.Float }, new VertexAttribute { AttributeName = "sprite_colorandsize", Buffer = ColorAndSizeBuffer, Divisor = 1, Size = 4, Type = VertexAttribPointerType.Float }); m_ParticleRenderingProgram = new Program ("main_program", opentk.ShadingSetup.RenderPass.GetResourceShaders(string.Empty, GetType ().Namespace.Split ('.').Last ()).ToArray ()); m_SystemState = new State (null, m_ParticleRenderingState, m_ParticleRenderingProgram, m_UniformState); var hnd = PositionBuffer.Handle; hnd = ColorAndSizeBuffer.Handle; m_DebugView = new opentk.QnodeDebug.QuadTreeDebug(10000, m_TransformationStack); InitializeSystem(); PrepareState (); }
// private void PrepareState() { if (m_Initialized) { if (PARTICLES_COUNT != m_PositionBuffer.Data.Length) { Position = m_PositionBuffer.Data = new Vector4[PARTICLES_COUNT]; Dimension = m_DimensionBuffer.Data = new Vector4[PARTICLES_COUNT]; Color = m_ColorBuffer.Data = new Vector4[PARTICLES_COUNT]; Rotation = m_RotationBuffer.Data = new Matrix4[PARTICLES_COUNT]; RotationLocal = m_RotationLocalBuffer.Data = new Matrix4[PARTICLES_COUNT]; InitializeSystem (); } Simulate (DateTime.Now); switch (PublishMethod){ case PublishMethod.AllAtOnce: m_PositionBuffer.Publish (); m_DimensionBuffer.Publish (); m_ColorBuffer.Publish (); m_RotationBuffer.Publish(); m_RotationLocalBuffer.Publish(); Publish (0, PARTICLES_COUNT); break; case PublishMethod.Incremental: { m_PublishCounter %= PARTICLES_COUNT; var start = m_PublishCounter; var end = Math.Min(start + PublishSize, PARTICLES_COUNT); var cnt = end - start; m_PositionBuffer.PublishPart (start, cnt); m_DimensionBuffer.PublishPart (start, cnt); m_ColorBuffer.PublishPart (start, cnt); m_RotationBuffer.PublishPart (start, cnt); m_RotationLocalBuffer.PublishPart (start, cnt); Publish (start, cnt); m_PublishCounter = end; } break; default: break; } return; } unsafe { m_PositionBuffer = new BufferObject<Vector4> (sizeof(Vector4), 0) { Name = "position_buffer", Usage = BufferUsageHint.DynamicDraw }; m_DimensionBuffer = new BufferObject<Vector4> (sizeof(Vector4), 0) { Name = "dimension_buffer", Usage = BufferUsageHint.DynamicDraw }; m_ColorBuffer = new BufferObject<Vector4> (sizeof(Vector4), 0) { Name = "color_buffer", Usage = BufferUsageHint.DynamicDraw }; m_RotationBuffer = new BufferObject<Matrix4> (sizeof(Matrix4), 0) { Name = "rotation_buffer", Usage = BufferUsageHint.DynamicDraw }; m_RotationLocalBuffer = new BufferObject<Matrix4> (sizeof(Matrix4), 0) { Name = "rotation_local_buffer", Usage = BufferUsageHint.DynamicDraw }; } ParticleStateArrayObject = new ArrayObject ( new VertexAttribute { AttributeName = "sprite_pos", Buffer = m_PositionBuffer, Size = 3, Stride = 16, Type = VertexAttribPointerType.Float }, new VertexAttribute { AttributeName = "sprite_color", Buffer = m_ColorBuffer, Size = 3, Stride = 16, Type = VertexAttribPointerType.Float }, new VertexAttribute { AttributeName = "sprite_dimensions", Buffer = m_DimensionBuffer, Size = 3, Stride = 16, Type = VertexAttribPointerType.Float }, new VertexAttribute { AttributeName = "sprite_rotation_local", Buffer = m_RotationLocalBuffer, Size = 16, Stride = 64, Type = VertexAttribPointerType.Float }, new VertexAttribute { AttributeName = "sprite_rotation", Buffer = m_RotationBuffer, Size = 16, Stride = 64, Type = VertexAttribPointerType.Float } ); // PublishSize = 100000; ModelScaleFactor = 1; TransformationStack = new MatrixStack(2); ProjectionStack = new MatrixStack(1); CameraMvp = new ModelViewProjectionParameters("", TransformationStack, ProjectionStack); // m_Manip = new OrbitManipulator (ProjectionStack); m_Grid = new Grid (CameraMvp); TransformationStack[0] = m_Manip.RT; TransformationStack.ValueStack[1] = Matrix4.Scale(ModelScaleFactor); // Uniforms = new UniformState { {"particle_scale_factor", () => this.ParticleScaleFactor}, {CameraMvp} }; // Shading = GlobalContext.Container.GetExportedValues<IShadingSetup>().FirstOrDefault(); PrepareStateCore(); m_Initialized = true; PrepareState (); }
/// <summary> /// given color and depth textures, render them. /// </summary> private static RenderPass CreateSolidSphere( FramebufferBindingSet targets, BufferObject<Vector4> sprite_pos_buffer, BufferObject<Vector4> sprite_color_buffer, BufferObject<Vector4> sprite_dimensions_buffer, IValueProvider<Vector2> viewport, IValueProvider<int> particles_count, IValueProvider<float> particle_scale_factor, IValueProvider<string> fragdepthroutine, IValueProvider<string> outputroutine, ModelViewProjectionParameters mvp, UniformState subroutineMapping, IEnumerable<Shader> subroutines ) { var uniform_state = subroutineMapping != null? new UniformState (subroutineMapping): new UniformState(); uniform_state.Set ("viewport_size", viewport); uniform_state.Set ("particle_scale_factor", particle_scale_factor); uniform_state.Set ("u_SetFragmentDepth", ShaderType.FragmentShader, fragdepthroutine); uniform_state.Set ("u_SetOutputs", ShaderType.FragmentShader, outputroutine); uniform_state.SetMvp("", mvp); var array_state = new ArrayObject ( new VertexAttribute { AttributeName = "sprite_pos", Buffer = sprite_pos_buffer, Size = 3, Stride = 16, Type = VertexAttribPointerType.Float }, new VertexAttribute { AttributeName = "sprite_color", Buffer = sprite_color_buffer, Size = 3, Stride = 16, Type = VertexAttribPointerType.Float }, new VertexAttribute { AttributeName = "sprite_dimensions", Buffer = sprite_dimensions_buffer, Size = 3, Stride = 16, Type = VertexAttribPointerType.Float } ); var shaders = SeparateProgramPass.GetShaders("solid_sphere", "RenderPassFactory"); shaders = shaders.Concat(subroutines ?? new Shader[0]).ToArray(); // var resultPass = new SeparateProgramPass ( //the name of the pass-program "solid_sphere_RenderPassFactory", //before state null, //before render null, //render code (window) => { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Enable (EnableCap.DepthTest); GL.DepthMask(true); GL.DepthFunc (DepthFunction.Less); GL.Disable (EnableCap.Blend); //setup viewport GL.Viewport(0, 0, (int)viewport.Value.X, (int)viewport.Value.Y); GL.DrawArrays (BeginMode.Points, 0, particles_count.Value); }, //shaders shaders, //pass state array_state, uniform_state, targets ); return resultPass; }
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 (); }
/// <summary> /// create two passes in one compound pass. First pass has set "horizontal" uniform boolean to true, /// the second has it set to false. /// </summary> public static RenderPass CreateSeparableFilter( string filterName, string filterNamespace, TextureBase source, TextureBase interm, TextureBase result, UniformState parameters) { var viewport = ValueProvider.Create (() => new Vector2 (result.Width, result.Height)); var horizontal = false; var uniformState = new UniformState (); uniformState.Set ("viewport_size", viewport); uniformState.Set ("horizontal", ValueProvider.Create (() => horizontal)); parameters = parameters?? new UniformState(); var _1stPass = CreateFullscreenQuad (filterName, filterNamespace, viewport, window => { horizontal = false; } , window => { GL.Clear (ClearBufferMask.ColorBufferBit); GL.Disable (EnableCap.DepthTest); GL.Disable (EnableCap.Blend); //pass state }, new FramebufferBindingSet {{ "OUT_FragData_result", interm }}, uniformState, parameters, new TextureBindingSet {{ "source_texture", source }}); var _2ndPass = CreateFullscreenQuad (filterName, filterNamespace, viewport, window => { horizontal = true; } , window => { GL.Clear (ClearBufferMask.ColorBufferBit); GL.Disable (EnableCap.DepthTest); GL.Disable (EnableCap.Blend); //pass state }, new FramebufferBindingSet {{ "OUT_FragData_result", result }}, uniformState, parameters, new TextureBindingSet {{ "source_texture", interm }}); return new CompoundRenderPass(_1stPass, _2ndPass); }
unsafe void PrepareState() { if (m_AttributeState != null) { FillBuffers(); PositionBuffer.Publish (); DimensionBuffer.Publish (); m_State.Activate (); return; } unsafe { PositionBuffer = new BufferObjectCompact<Vector3> (sizeof(Vector3), m_MaxSize) { Name = "position_buffer", Usage = BufferUsageHint.DynamicDraw }; DimensionBuffer = new BufferObjectCompact<Vector3> (sizeof(Vector3), m_MaxSize) { Name = "dimension_buffer", Usage = BufferUsageHint.DynamicDraw }; } m_UniformState = new UniformState () .Set ("modelview_transform", m_TransformationStack); m_AttributeState = new ArrayObject ( new VertexAttribute { AttributeName = "cube_pos", Buffer = PositionBuffer, Size = 3, Type = VertexAttribPointerType.Float }, new VertexAttribute { AttributeName = "cube_dimensions", Buffer = DimensionBuffer, Size = 3, Type = VertexAttribPointerType.Float }); m_Program = new Program ("debug_qnode_program", GetShaders("QnodeDebug", "").ToArray ()); m_State = new State (null, m_AttributeState, m_Program, m_UniformState); var hnd = PositionBuffer.Handle; hnd = DimensionBuffer.Handle; PrepareState (); }
private void PrepareState() { if (m_Passes != null) { return; } unsafe { BeforeAATexture = new DataTexture<Vector4> { Name = "BeforeAATexture", 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, }}; AccumTexture = new DataTexture<Vector4> { Name = "AccumTexture", InternalFormat = PixelInternalFormat.Rgba32f, Data2D = new Vector4[m_SolidModeTextureSize, m_SolidModeTextureSize], Params = new TextureBase.Parameters { GenerateMipmap = false, MinFilter = TextureMinFilter.Nearest, MagFilter = TextureMagFilter.Nearest, }}; AATexture = new Texture { Name = "AATexture", InternalFormat = PixelInternalFormat.Rgba8, Target = TextureTarget.Texture2D, Width = m_SolidModeTextureSize, Height = m_SolidModeTextureSize, Params = new TextureBase.Parameters { //GenerateMipmap = true, 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); var frameCount = 1; m_UniformState = new UniformState { {"pRayMarchStepFactor", () => this.RayMarchStepFactor}, {"k1", () => this.K1}, {"k2", () => this.K2}, {"k3", () => this.K3}, {"k4", () => this.K4}, {"time", () => this.Time}, {"u_FrameCount", () => frameCount}, }; var workgroupSize = 8; var giPass = new SeparateProgramPass( "system6.globalillumination", window => { GLExtensions.DispatchCompute ((int)Math.Ceiling((float)Depth_Texture.Width/workgroupSize), (int)Math.Ceiling((float)Depth_Texture.Height/workgroupSize), 1); }, new Program ("system6.gi") { RenderPass.GetShaders ("system6", "gi", "compute")//.PrependText(namemodifier, scode), }, new ImageBindingSet { {"u_TargetDepth", () => Depth_Texture }, {"u_TargetColorLuma", () => BeforeAATexture }, {"u_TargetAccumLuma", () => AccumTexture }, }, m_UniformState); //var antialiasPass = RenderPassFactory.CreatePass( new Fxaa3Filter{ Source = BeforeAATexture, Target = AATexture}); var finalRender = RenderPassFactory.CreateRenderTextureToBuffer ( BeforeAATexture, Depth_Texture, ValueProvider.Create(() => m_Viewport), (window) => { SetCamera (window); }, (window) => { GL.Clear (ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Disable (EnableCap.DepthTest); GL.Disable (EnableCap.Blend); frameCount++; }, FramebufferBindingSet.Default); m_Passes = new RenderPass[]{ giPass, /*antialiasPass, */finalRender }; 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)); m_Manip.RT.PropertyChanged += (s, args) => { frameCount = 0; }; PrepareState (); }
public void SetUniforms(string prefix, UniformState state) { string pp = String.IsNullOrEmpty(prefix)? String.IsNullOrEmpty(Prefix) ? string.Empty: Prefix + "_": prefix + "_"; state.Set (pp + "modelview_transform", ModelView); state.Set (pp + "modelviewprojection_transform", ModelViewProjection); state.Set (pp + "projection_transform", Projection); state.Set (pp + "projection_inv_transform", ProjectionInv); state.Set (pp + "modelview_inv_transform", ModelViewInv); state.Set (pp + "modelviewprojection_inv_transform", ModelViewProjectionInv); }
protected virtual void PassSetup(ParticleSystemBase p) { // m_Uniforms = new UniformState(p.Uniforms) { {SunLightImpl.LightMvp, "light"}, {"u_GetShadow", (ShaderType)ShaderTypeExt.ComputeShader, () => "GetShadow" + SunLightImpl.ImplementationType.ToString () }, //{"u_ShadowmapGet", () => "ShadowmapGet" + SunLightImpl.ShadowmapType.ToString () }, //{"u_ShadowmapGetFiltered", () => "ShadowmapGetFiltered" + SunLightImpl.ShadowmapType.ToString () }, {"u_MaterialColorSource", ValueProvider.Create(() => MaterialType)}, {"u_LightSize", ValueProvider.Create(() => LightSize )}, {"u_ShadowSampleCount", ValueProvider.Create(() => ShadowSampleCount )}, {"u_SamplingPattern", MathHelper2.RandomVectorSet (256, new Vector2 (1, 1))}, {"sampling_pattern_len", 256}, }; //m_Uniforms.SetMvp("light", SunLightImpl.LightMvp); }
RenderPass IShadingSetup.GetPass(ParticleSystemBase p) { PrepareTexture(); if(m_Pass != null) return m_Pass; m_Uniforms = new UniformState(p.Uniforms); m_Uniforms.Set ("particle_shape", ValueProvider.Create (() => (int)this.ParticleShape)); m_Uniforms.Set ("particle_brightness", ValueProvider.Create (() => this.ParticleBrightness)); m_Uniforms.Set ("smooth_shape_sharpness", ValueProvider.Create (() => this.SmoothShapeSharpness)); // m_Pass = new SeparateProgramPass ( "light", "SmoothShading", null, null, //pass code (window) => { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Disable (EnableCap.DepthTest); GL.Enable (EnableCap.Blend); GL.BlendFunc (BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One); GL.BlendEquation (BlendEquationMode.FuncAdd); //TODO: viewport size actually doesn't propagate to shader, because uniform state has been already activated p.SetViewport (window); GL.DrawArrays (BeginMode.Points, 0, p.PARTICLES_COUNT); }, //pass state FramebufferBindingSet.Default, p.ParticleStateArrayObject, m_Uniforms, new TextureBindingSet( new TextureBinding { VariableName = "custom_texture", Texture = m_Texture } ) ); return m_Pass; }
protected virtual void PassSetup(ParticleSystemBase p) { // m_Uniforms = new UniformState(p.Uniforms) { {SunLightImpl.LightMvp, "light"}, {"u_GetShadow", ShaderType.FragmentShader, () => "GetShadow" + SunLightImpl.ImplementationType.ToString () }, //{"u_ShadowmapGet", () => "ShadowmapGet" + SunLightImpl.ShadowmapType.ToString () }, //{"u_ShadowmapGetFiltered", () => "ShadowmapGetFiltered" + SunLightImpl.ShadowmapType.ToString () }, {"material_color_source", ValueProvider.Create(() => MaterialType)}, {"light_size", ValueProvider.Create(() => LightSize )}, {"light_expmap_level", ValueProvider.Create(() => ExpMapLevel )}, {"light_expmap_range", ValueProvider.Create(() => ExpMapRange )}, {"light_expmap_range_k", ValueProvider.Create(() => ExpMapRangeK )}, {"light_expmap_nsamples", ValueProvider.Create(() => ExpMapNsamples )}, // {"sampling_pattern", MathHelper2.RandomVectorSet (256, new Vector2 (1, 1))}, {"sampling_pattern_len", 256}, }; //m_Uniforms.SetMvp("light", SunLightImpl.LightMvp); }
protected override void PassSetup(ParticleSystemBase p) { base.PassSetup(p); // var particle_scale_factor = ValueProvider.Create (() => p.ParticleScaleFactor); var particle_count = ValueProvider.Create (() => p.PARTICLES_COUNT); var firstPassSolid = RenderPassFactory.CreateSolidSphere ( NormalDepth_Texture, m_ParticleAttribute1_Texture, Depth_Texture, p.PositionBuffer, p.ColorBuffer, p.DimensionBuffer, particle_count, particle_scale_factor, p.CameraMvp ); var firstPassShadow = RenderPassFactory.CreateSolidSphere ( Shadow_Texture, p.PositionBuffer, p.ColorBuffer, p.DimensionBuffer, particle_count, particle_scale_factor, ValueProvider.Create ( () => "FragDepth" + SunLightImpl.ShadowmapType.ToString ()), SunLightImpl.LightMvp ); var mvpUniforms = new UniformState { {"viewport_size", ValueProvider.Create(() => new Vector2(SolidModeTextureSize, SolidModeTextureSize))}, {"K", ValueProvider.Create(() => new Vector4(0.0f, 0.0f, 0.0f, 20 * NormalBlurAvoidance))}, {p.CameraMvp} }; var normalDepthBlur = RenderPassFactory.CreateFullscreenQuad ( "stringfilter", "SolidModel", ValueProvider.Create(() => new Vector2(SolidModeTextureSize, SolidModeTextureSize)), (window) => { }, (window) => { }, //pass state new FramebufferBindingSet{ { "Fragdata.result", NormalDepth_Texture} }, m_Uniforms, mvpUniforms, new TextureBindingSet{ { "normaldepth_texture", NormalDepth_Texture_Unfiltered }, { "tangent_texture", m_ParticleAttribute1_Texture } } ); var aocPassSolid = RenderPassFactory.CreateAoc ( NormalDepth_Texture, AOC_Texture, p.CameraMvp.ModelViewProjection, p.CameraMvp.ModelViewProjectionInv, p.CameraMvp.Projection, p.CameraMvp.ProjectionInv, AocParameters ); var aocBlur = RenderPassFactory.CreateBilateralFilter ( AOC_Texture, AOC_Texture_Blurred_H, AOC_Texture_Blurred_HV, ValueProvider.Create(() => 20 * new Vector4(AocParameters.BlurEdgeAvoidance, AocParameters.BlurEdgeAvoidance, AocParameters.BlurEdgeAvoidance, 0)) ); // var thirdPassSolid = RenderPassFactory.CreateFullscreenQuad ( "solid3", "SolidModel", ValueProvider.Create(() => new Vector2(SolidModeTextureSize, SolidModeTextureSize)), (window) => { }, (window) => { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Disable (EnableCap.DepthTest); GL.Disable (EnableCap.Blend); }, //pass state new FramebufferBindingSet{ { FramebufferAttachment.DepthAttachment, Depth_Texture }, { "color_luma", BeforeAA_Texture} }, p.ParticleStateArrayObject, m_Uniforms, new TextureBindingSet{ { "colorramp_texture", ValueProvider.Create(() => (ColorRamp ?? ColorRamps.RedBlue).Texture)}, { "normaldepth_texture", NormalDepth_Texture }, { "particle_attribute1_texture", m_ParticleAttribute1_Texture }, { "shadow_texture", Shadow_Texture }, { "aoc_texture", AOC_Texture_Blurred_HV } } ); var antialiasPass = RenderPassFactory.CreateFxaa3Filter ( BeforeAA_Texture, AA_Texture ); var finalRender = RenderPassFactory.CreateRenderTextureToBuffer ( AA_Texture, Depth_Texture, ValueProvider.Create(() => p.Viewport), (window) => { p.SetViewport (window); }, (window) => { GL.Clear (ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Disable (EnableCap.DepthTest); GL.Disable (EnableCap.Blend); }, //TODO: BUG m_ParticleRenderingState is necessary, but it shouldn't be FramebufferBindingSet.Default, p.ParticleStateArrayObject ); m_Pass = new CompoundRenderPass ( firstPassSolid, firstPassShadow, /*normalDepthBlur,*/ aocPassSolid, aocBlur, thirdPassSolid, antialiasPass, finalRender ); }