/// <summary>
        /// given color and depth textures, render them.
        /// </summary>
        public static RenderPass CreateSolidBox(
			 TextureBase depth_texture,
			 BufferObject<Vector4> sprite_pos_buffer,
			 BufferObject<Vector4> sprite_color_buffer,
			 BufferObject<Vector4> sprite_dimensions_buffer,
			 BufferObject<Matrix4> sprite_rotation_local_buffer,
			 BufferObject<Matrix4> sprite_rotation_buffer,
			 IValueProvider<int> particles_count,
				IValueProvider<float> particle_scale_factor,
				IValueProvider<string> fragdepthroutine,
			 ModelViewProjectionParameters mvp
		)
        {
            var viewport = ValueProvider.Create (() => new Vector2 (depth_texture.Width, depth_texture.Height));
            var outputroutine = ValueProvider.Create (() => "SetOutputsNone");
            return CreateSolidBox
            (
                 new FramebufferBindingSet(
                  new DrawFramebufferBinding { Attachment = FramebufferAttachment.DepthAttachment, Texture = depth_texture }
                 ),
                 sprite_pos_buffer, sprite_color_buffer, sprite_dimensions_buffer, sprite_rotation_local_buffer, sprite_rotation_buffer,
                 viewport,
                 particles_count, particle_scale_factor, fragdepthroutine, outputroutine,
                 mvp,
                 null,
                 null
            );
        }
        /*
        /// <summary>
        /// given color and depth textures, render them.
        /// </summary>
        public static RenderPass CreateSolidSphere
        (
             TextureBase normal_depth_target,
             TextureBase uv_colorindex_target,
             TextureBase depth_texture,
             BufferObject<Vector4> sprite_pos_buffer,
             BufferObject<Vector4> sprite_color_buffer,
             BufferObject<Vector4> sprite_dimensions_buffer,
             IValueProvider<int> particles_count,
             IValueProvider<float> particle_scale_factor,
             ModelViewProjectionParameters mvp,
             UniformState subroutineMapping,
             IEnumerable<Shader> subroutines
        )
        {
            var viewport = ValueProvider.Create (() => new Vector2 (depth_texture.Width, depth_texture.Height));
            var mode = ValueProvider.Create (() => 0);

            return CreateSolidSphere
            (
                 new FramebufferBindingSet(
                  new DrawFramebufferBinding { Attachment = FramebufferAttachment.DepthAttachment, Texture = depth_texture },
                  new DrawFramebufferBinding { VariableName = "Fragdata.uv_colorindex_none", Texture = uv_colorindex_target },
                  new DrawFramebufferBinding { VariableName = "Fragdata.normal_depth", Texture = normal_depth_target }
                 ),
                 sprite_pos_buffer, sprite_color_buffer, sprite_dimensions_buffer,
                 viewport,
                 particles_count, particle_scale_factor, mode,
                 mvp,
                 subroutineMapping,
                 subroutines
            );
        }*/
        /// <summary>
        /// given color and depth textures, render them.
        /// </summary>
        public static RenderPass CreateSolidSphere(
			 TextureBase normal_depth_target,
			 TextureBase uv_colorindex_target,
			 TextureBase depth_texture,
			 BufferObject<Vector4> sprite_pos_buffer,
			 BufferObject<Vector4> sprite_color_buffer,
			 BufferObject<Vector4> sprite_dimensions_buffer,
			 IValueProvider<int> particles_count,
			 IValueProvider<float> particle_scale_factor,
			 ModelViewProjectionParameters mvp
		)
        {
            var viewport = ValueProvider.Create (() => new Vector2 (depth_texture.Width, depth_texture.Height));
            var fragdepthroutine = ValueProvider.Create (() => "FragDepthDefault");
            var outputroutine = ValueProvider.Create (() => "SetOutputsDefault");

            return CreateSolidSphere
            (
                 new FramebufferBindingSet(
                  new DrawFramebufferBinding { Attachment = FramebufferAttachment.DepthAttachment, Texture = depth_texture },
                  new DrawFramebufferBinding { VariableName = "uv_colorindex_none", Texture = uv_colorindex_target },
                  new DrawFramebufferBinding { VariableName = "normal_depth", Texture = normal_depth_target }
                 ),
                 sprite_pos_buffer, sprite_color_buffer, sprite_dimensions_buffer,
                 viewport,
                 particles_count, particle_scale_factor, fragdepthroutine, outputroutine,
                 mvp,
                 null,
                 null
            );
        }
        public ShadowImplementationParameters(Light light)
        {
            Light = light;

            var LightSpaceModelviewProvider =
                ValueProvider.Create(() => Matrix4.LookAt(- Light.Direction * 300, Light.Direction * 300, Vector3.UnitZ));

            var LightSpaceProjectionProvider =
                ValueProvider.Create(
                () =>
                {
                    if(Light.Type == LightType.Directional)
                    {
                        return Matrix4.CreateOrthographic(300, 300, 0, 600);
                    }
                    else
                    {
                        return  Matrix4.CreateTranslation(- Light.Position);
                    }
                });

            LightMvp = new ModelViewProjectionParameters
            (
                 "",
                 LightSpaceModelviewProvider,
                 LightSpaceProjectionProvider
            );

            //
            LightIlluminationTransformProvider = ValueProvider.Create(
            () =>
            {
                if(Light.Type == LightType.Directional)
                {
                    return Matrix4.CreateTranslation(Light.Direction);
                }
                else
                {
                    return  Matrix4.CreateTranslation(- Light.Position);
                }
            });
        }
        //
        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;
        }
Exemplo n.º 6
0
 public Grid(ModelViewProjectionParameters mvp)
 {
     m_CameraMvp = mvp;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Sets the mvp.
 /// </summary>
 /// <param name="state">State.</param>
 /// <param name="prefix">Prefix.</param>
 /// <param name="mvp">Mvp.</param>
 public static void SetMvp(this UniformState state, string prefix, ModelViewProjectionParameters mvp)
 {
     mvp.SetUniforms(prefix, state);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Add the specified state, prefix and mvp.
 /// </summary>
 /// <param name="state">State.</param>
 /// <param name="prefix">Prefix.</param>
 /// <param name="mvp">Mvp.</param>
 public static void Add(this UniformState state, ModelViewProjectionParameters mvp, string prefix = "")
 {
     mvp.SetUniforms(prefix, state);
 }