/// <summary>
        /// A helper method to set a common skeleton bone block layout.
        /// Note not all games use the same skeleton bone block data!
        /// </summary>
        public virtual void SetBoneMatrixBlock(STSkeleton skeleton, bool useInverse, UniformBlock block, int maxTransforms = 170)
        {
            block.Buffer.Clear();

            //Fixed buffer of max amount of transform values
            for (int i = 0; i < maxTransforms; i++)
            {
                Matrix4 value = Matrix4.Zero;

                //Set the inverse matrix and load the matrix data into 3 vec4s
                if (i < skeleton.Bones.Count)
                {
                    //Check if the bone is smooth skinning aswell for accuracy purposes.
                    if (useInverse || ((BfresBone)skeleton.Bones[i]).UseSmoothMatrix) //Use inverse transforms for smooth skinning
                    {
                        value = skeleton.Bones[i].Inverse * skeleton.Bones[i].Transform;
                    }
                    else
                    {
                        value = skeleton.Bones[i].Transform;
                    }
                }

                block.Add(value.Column0);
                block.Add(value.Column1);
                block.Add(value.Column2);
            }
        }
        static void LoadUniforms(int programID, Vector4[] shData)
        {
            UniformBlock paramBlock = GetBlock("paramBlock");

            paramBlock.Buffer.Clear();
            //Variables from the sharcfb binaries
            paramBlock.Add(new Vector4(LightmapWeight[0], 0, 0, 0));
            paramBlock.Add(new Vector4(LightmapWeight[1], 0, 0, 0));
            paramBlock.Add(new Vector4(LightmapArrayIndex[0], 0, 0, 0));
            paramBlock.Add(new Vector4(LightmapArrayIndex[1], 0, 0, 0));
            paramBlock.Add(new Vector4(SHWeight[0], 0, 0, 0));
            paramBlock.RenderBuffer(programID, "cbuf_block3");

            UniformBlock dataBlock = GetBlock("shBlock");

            dataBlock.Buffer.Clear();
            dataBlock.Add(shData[0]);
            dataBlock.Add(shData[1]);
            dataBlock.Add(shData[2]);
            dataBlock.Add(shData[3]);
            dataBlock.Add(shData[4]);
            dataBlock.Add(shData[5]);
            dataBlock.Add(shData[6]);
            dataBlock.RenderBuffer(programID, "cbuf_block4");
        }
        public void SetBoneMatrixBlock(STSkeleton skeleton, bool useInverse, UniformBlock block, int maxTransforms = 64)
        {
            block.Buffer.Clear();

            //Fixed buffer of max amount of transform values
            for (int i = 0; i < maxTransforms; i++)
            {
                Matrix4 value = Matrix4.Zero;

                //Set the inverse matrix and load the matrix data into 3 vec4s
                if (i < skeleton.Bones.Count)
                {
                    if (useInverse) //Use inverse transforms for smooth skinning
                    {
                        value = skeleton.Bones[i].Inverse * skeleton.Bones[i].Transform;
                    }
                    else
                    {
                        value = skeleton.Bones[i].Transform;
                    }
                }

                block.Add(value.Column0);
                block.Add(value.Column1);
                block.Add(value.Column2);
            }
        }
        /// <summary>
        /// A helper method to set a common shape block layout.
        /// Note not all games use the same shape block data!
        /// </summary>
        public virtual void SetShapeBlock(BfresMeshAsset mesh, Matrix4 transform, UniformBlock block)
        {
            int numSkinning = (int)mesh.SkinCount;

            block.Buffer.Clear();
            block.Add(transform.Column0);
            block.Add(transform.Column1);
            block.Add(transform.Column2);
            block.AddInt(numSkinning);
        }
Exemplo n.º 5
0
        public void SetModelBlock(UniformBlock block)
        {
            Matrix4 transform = Matrix4.Identity;

            block.Buffer.Clear();
            block.Add(transform.Column0);
            block.Add(transform.Column1);
            block.Add(transform.Column2);
            block.Add(transform.Column3);
        }
        private void SetModelUniforms(UniformBlock block)
        {
            var matrix = Matrix4.Identity;

            block.Add(new Vector4(1, 1, 0.5f, 0.5f));
            for (int i = 0; i < 7; i++)
            {
                block.Add(matrix.Column0);
                block.Add(matrix.Column1);
                block.Add(matrix.Column2);
                block.Add(matrix.Column3);
            }
        }
        private void SetEnvUniforms(GLContext control, UniformBlock block)
        {
            Fog[] fog = new Fog[4];
            for (int i = 0; i < 4; i++)
            {
                fog[i] = new Fog();
            }

            fog[0] = new Fog()
            {
                Start     = 1000000,
                End       = 1000000,
                Color     = new Vector4(1, 0, 0, 1),
                Direciton = new Vector3(0, 1, 0),
            };

            if (AreaIndex != -1 && control.EnableFog)
            {
                var courseArea = LightingEngine.LightSettings.Resources.EnvFiles["course_area.baglenv"];
                var areaFog    = courseArea.GetAreaFog(false, AreaIndex);

                if (areaFog != null && areaFog.Enable)
                {
                    var color = areaFog.Color.ToColorF();
                    fog[0] = new Fog()
                    {
                        Start     = areaFog.Start,
                        End       = areaFog.End,
                        Color     = new Vector4(color.X, color.Y, color.Z, color.W),
                        Direciton = new Vector3(
                            areaFog.Direction.X,
                            areaFog.Direction.Y,
                            areaFog.Direction.Z),
                    };
                }
            }

            var mem = new MemoryStream();

            using (var writer = new Toolbox.Core.IO.FileWriter(mem))
            {
                writer.SeekBegin(10 * 16);
                for (int i = 0; i < 1; i++)
                {
                    writer.Write(fog[i].Color);
                    writer.Write(fog[i].Direciton);
                    writer.Write(fog[i].StartC);
                    writer.Write(fog[i].EndC);
                }

                float amount = 0.1f;

                writer.Write(new Vector4(1, 0, 0, amount));
                writer.Write(new Vector3(0.6771527f, -0.4863142f, 131.3442f));
            }

            block.Buffer.Clear();
            block.Add(mem.ToArray());
        }
        private void SetViewportUniforms(Camera camera, UniformBlock block)
        {
            Matrix4 mdlMat         = camera.ModelMatrix;
            var     viewMatrix     = camera.ViewMatrix;
            var     projMatrix     = camera.ProjectionMatrix;
            var     viewProjMatrix = mdlMat * viewMatrix * projMatrix;

            //cView used for matcaps. Invert and transpose it
            viewMatrix.Invert();
            viewMatrix.Transpose();

            Vector4[] cView = new Vector4[3]
            {
                viewMatrix.Column0,
                viewMatrix.Column1,
                viewMatrix.Column2,
            };
            Vector4[] cViewProj = new Vector4[4]
            {
                viewProjMatrix.Column0,
                viewProjMatrix.Column1,
                viewProjMatrix.Column2,
                viewProjMatrix.Column3,
            };
            Vector4[] cLightDiffDir   = new Vector4[8];
            Vector4[] cLightDiffColor = new Vector4[8];
            Vector4[] cAmbColor       = new Vector4[2];
            Vector4[] cFogColor       = new Vector4[8];
            Vector4[] cFogStart       = new Vector4[8];
            Vector4[] cFogStartEndInv = new Vector4[8];

            for (int i = 0; i < 2; i++)
            {
                cAmbColor[i] = new Vector4(1);
            }
            for (int i = 0; i < 8; i++)
            {
                cLightDiffDir[i]   = new Vector4(0.1f, -0.5f, -0.5f, 0);
                cLightDiffColor[i] = new Vector4(1);
            }
            for (int i = 0; i < 8; i++)
            {
                cFogColor[i]       = new Vector4(1);
                cFogStart[i]       = new Vector4(10000000, 0, 0, 0);
                cFogStartEndInv[i] = new Vector4(0.00003f, 0, 0, 0);
            }

            block.Add(cView);
            block.Add(cViewProj);
            block.Add(cLightDiffDir);
            block.Add(cLightDiffColor);
            block.Add(cAmbColor);
            block.Add(cFogColor);
            block.Add(cFogStart);
            block.Add(cFogStartEndInv);
        }
        public override void SetShapeBlock(BfresMeshAsset mesh, Matrix4 transform, UniformBlock block)
        {
            int numSkinning = (int)mesh.SkinCount;

            block.Buffer.Clear();
            block.Add(transform.Column0);
            block.Add(transform.Column1);
            block.Add(transform.Column2);
            block.Add(new Vector4(numSkinning, 0, 0, 0));
            block.Add(new Vector4(0));
            block.Add(AreaIndex);
            block.Add(AreaIndex);
            block.Add(AreaIndex);
            block.Add(AreaIndex);
        }
Exemplo n.º 10
0
        private void SetHdrUniforms(UniformBlock block)
        {
            float pow   = 4.0f;
            float range = 8192.0f;

            //The current cubemap used uses 1024 but in game it's usually 8192
            range = 1024.0f;

            block.Add(new Vector4(pow, range, 0.0f, 0.0f));
        }
        private void SetSceneMatUniforms(UniformBlock block)
        {
            float light_intensity = 1.0f; //Multipled by light scale param (fp_c7_data[2].y)

            //Note alpha for colors also are intensity factors
            Vector4 shadow_color = new Vector4(0, 0, 0, 1);
            Vector4 ao_color     = new Vector4(0, 0, 0, 1);

            Vector4 lighting            = new Vector4(1.0f, light_intensity, 1.0f, 1.0f);
            Vector4 lighting_specular   = new Vector4(1, 0.9f, 1, 1);
            Vector4 light_prepass_param = new Vector4(1, 1, 0, 1);
            Vector4 exposure            = new Vector4(1);

            block.Buffer.Clear();
            block.Add(shadow_color);
            block.Add(ao_color);
            block.Add(lighting);
            block.Add(lighting_specular);
            block.Add(light_prepass_param);
            block.Add(exposure);

            if (block.Buffer.Count != 96)
            {
                throw new Exception("Invalid gsys_scene_material size");
            }
        }
 public void AddBlock(UniformBlock block)
 {
     block.Add(shadow_color);
     block.Add(ao_color);
     block.Add(lighting);
     block.Add(lighting_specular);
     block.Add(light_prepass_param);
     block.Add(exposure);
 }
Exemplo n.º 13
0
        private void SetEnvUniforms(UniformBlock block)
        {
            Fog[] fog = new Fog[4];
            for (int i = 0; i < 4; i++)
            {
                fog[i] = new Fog();
            }

            fog[0] = new Fog()
            {
                Start     = 1000000,
                End       = 1000000,
                Color     = new Vector4(1, 0, 0, 1),
                Direciton = new Vector3(0, 1, 0),
            };

            var mem = new MemoryStream();

            using (var writer = new Toolbox.Core.IO.FileWriter(mem))
            {
                writer.SeekBegin(10 * 16);
                for (int i = 0; i < 1; i++)
                {
                    writer.Write(fog[i].Color);
                    writer.Write(fog[i].Direciton);
                    writer.Write(fog[i].StartC);
                    writer.Write(fog[i].EndC);
                }

                float amount = 0.1f;

                writer.Write(new Vector4(1, 0, 0, amount));
                writer.Write(new Vector3(0.6771527f, -0.4863142f, 131.3442f));
            }

            block.Buffer.Clear();
            block.Add(mem.ToArray());
        }
Exemplo n.º 14
0
        private void SetViewportUniforms(Camera camera, UniformBlock block)
        {
            Matrix4 mdlMat         = camera.ModelMatrix;
            var     viewMatrix     = camera.ViewMatrix;
            var     projMatrix     = camera.ProjectionMatrix;
            var     viewProjMatrix = mdlMat * viewMatrix * projMatrix;

            //cView used for matcaps. Invert and transpose it
            viewMatrix.Invert();
            viewMatrix.Transpose();

            Vector4[] cView = new Vector4[3]
            {
                viewMatrix.Column0,
                viewMatrix.Column1,
                viewMatrix.Column2,
            };
            Vector4[] cViewProj = new Vector4[4]
            {
                viewProjMatrix.Column0,
                viewProjMatrix.Column1,
                viewProjMatrix.Column2,
                viewProjMatrix.Column3,
            };
            Vector3[] cLightDiffDir   = new Vector3[8];
            Vector4[] cLightDiffColor = new Vector4[8];
            Vector4[] cAmbColor       = new Vector4[2];
            Vector3[] cFogColor       = new Vector3[8];
            float[]   cFogStart       = new float[8];
            float[]   cFogStartEndInv = new float[8];

            for (int i = 0; i < 2; i++)
            {
                cAmbColor[i] = new Vector4(1);
            }
            for (int i = 0; i < 8; i++)
            {
                cLightDiffDir[i]   = new Vector3(0.1f, -0.5f, -0.5f);
                cLightDiffColor[i] = new Vector4(1);
            }
            for (int i = 0; i < 8; i++)
            {
                cFogColor[i]       = new Vector3(1);
                cFogStart[i]       = 100000;
                cFogStartEndInv[i] = 20000;
            }

            Vector4[] unkExtra  = new Vector4[8];
            Vector4[] unkExtra2 = new Vector4[8];
            for (int i = 0; i < 8; i++)
            {
                unkExtra[i]  = new Vector4(1);
                unkExtra2[i] = new Vector4(1);
            }

            block.Add(cView);
            block.Add(cViewProj);
            block.Add(cLightDiffDir);
            block.Add(cLightDiffColor);
            block.Add(cAmbColor);
            block.Add(cFogColor);
            block.Add(cFogStart);
            block.Add(cFogStartEndInv);
            block.Add(unkExtra);
            block.Add(unkExtra2);

            if (block.Buffer.Count != 1040)
            {
                throw new Exception("Invalid MdlEnvView size");
            }
        }
Exemplo n.º 15
0
        private void SetLightUniforms(UniformBlock block)
        {
            Matrix4 lightMatrix     = Matrix4.Identity;
            Matrix4 cloudProjMatrix = Matrix4.Identity;

            for (int i = 0; i < 4; i++)
            {
                block.Add(lightMatrix.Column0);
                block.Add(lightMatrix.Column1);
                block.Add(lightMatrix.Column2);
                block.Add(lightMatrix.Column3);
            }
            block.Add(new Vector4(1));
            //Cloud proj mtx
            block.Add(cloudProjMatrix.Column0);
            block.Add(cloudProjMatrix.Column1);
            block.Add(cloudProjMatrix.Column2);
            block.Add(cloudProjMatrix.Column3);
            //Depth shadow pow
            block.Add(1);
            block.Add(1);
            block.Add(1);
            block.Add(1);
            block.Add(new Vector4(1));
            //light pre pass param
            block.Add(new Vector4(1));
        }
Exemplo n.º 16
0
 private void SetModelUniforms(UniformBlock block)
 {
     block.Add(new Vector4(4, 4, 4, 1));
     block.Add(new Vector4(1, 1, 0, 0));
 }
Exemplo n.º 17
0
        private void SetViewportUniforms(Camera camera, UniformBlock block)
        {
            Matrix4 mdlMat         = camera.ModelMatrix;
            var     viewMatrix     = camera.ViewMatrix;
            var     projMatrix     = camera.ProjectionMatrix;
            var     viewProjMatrix = mdlMat * viewMatrix * projMatrix;

            Vector4[] cView = new Vector4[3]
            {
                viewMatrix.Column0,
                viewMatrix.Column1,
                viewMatrix.Column2,
            };
            Vector4[] cViewProj = new Vector4[4]
            {
                viewProjMatrix.Column0,
                viewProjMatrix.Column1,
                viewProjMatrix.Column2,
                viewProjMatrix.Column3,
            };
            Vector4[] cProj = new Vector4[4]
            {
                projMatrix.Column0,
                projMatrix.Column1,
                projMatrix.Column2,
                projMatrix.Column3,
            };
            Vector4[] cLightDiffDir   = new Vector4[8];
            Vector4[] cLightDiffColor = new Vector4[8];
            Vector4[] cAmbColor       = new Vector4[2];
            Vector3   cFogColor       = new Vector3(1);
            float     cFogStart       = 0;
            float     cFogStartEndInv = 0;

            for (int i = 0; i < 2; i++)
            {
                cAmbColor[i] = new Vector4(1);
            }
            for (int i = 0; i < 8; i++)
            {
                cLightDiffDir[i]   = new Vector4(0.1f, -0.5f, -0.5f, 0);
                cLightDiffColor[i] = new Vector4(1);
            }

            block.Buffer.Clear();
            block.Add(cView);
            block.Add(cViewProj);
            block.Add(cLightDiffDir);
            block.Add(cLightDiffColor);
            block.Add(cAmbColor);
            block.Add(cFogColor);
            block.Add(cFogStart);
            block.Add(cFogStartEndInv);
            block.Add(0);
            block.Add(0);
            block.Add(cProj);
        }
Exemplo n.º 18
0
 private void SetFogUniforms(UniformBlock block)
 {
     block.Buffer.Clear();
     block.Add(new Vector4(1, 1, 1, -10000.0f));
     block.Add(new Vector4(-20000.0f, 0, 1, 0));
 }
        private void SetSceneMatUniforms(UniformBlock block)
        {
            Vector4 toon_light_adjust   = new Vector4(1);
            float   cloud_ratio         = 1.0f;
            float   depth_shadow_offset = 0;
            float   proj_shadow_offset  = 0;
            float   rain_ratio          = 0;
            float   rainfall            = 0;
            float   exposure            = 0;
            float   world_shadow_offset = 0;
            float   base_light_ratio    = 0;
            float   main_light          = 1;
            float   sky_occ_offset      = 0;
            float   depth_shadow_scale  = 1;
            float   item_filter_alpha   = 0;
            float   ui_highlight        = 0;
            float   proj_discard_scale1 = 0.12f;
            float   proj_discard_scale2 = 0.85f;
            float   proj_discard_scale3 = 2.5f;
            float   debug0 = 0.8f;
            float   debug1 = 0;
            float   debug2 = 0.4f;
            float   debug3 = 1.0f;

            var mem = new System.IO.MemoryStream();

            using (var writer = new Toolbox.Core.IO.FileWriter(mem))
            {
                writer.SeekBegin(0);
                writer.Write(toon_light_adjust);
                writer.Write(cloud_ratio);
                writer.Write(depth_shadow_offset);
                writer.Write(proj_shadow_offset);
                writer.Write(rain_ratio);

                writer.Write(rainfall);
                writer.Write(exposure);
                writer.Write(world_shadow_offset);
                writer.Write(base_light_ratio);

                writer.Write(main_light);
                writer.Write(sky_occ_offset);
                writer.Write(depth_shadow_scale);
                writer.Write(item_filter_alpha);

                writer.Write(ui_highlight);
                writer.Write(proj_discard_scale1);
                writer.Write(proj_discard_scale2);
                writer.Write(proj_discard_scale3);

                writer.Write(debug0);
                writer.Write(debug1);
                writer.Write(debug2);
                writer.Write(debug3);
            }

            block.Buffer.Clear();
            block.Add(mem.ToArray());

            if (block.Buffer.Count != 96)
            {
                throw new Exception("Invalid gsys_scene_material size");
            }
        }
 private void SetResMatUniforms(UniformBlock block)
 {
     block.Buffer.Clear();
     block.Add(new Vector4(2.007874f, 0.4f, 0.586611f, 0.114478f));
     block.Add(new Vector4(1.666667f, 0, 0, 0));
 }
Exemplo n.º 21
0
 private void SetShapeUniforms(BfresMeshAsset mesh, Matrix4 mat, UniformBlock block)
 {
     block.Add(mat.Column0);
     block.Add(mat.Column1);
     block.Add(mat.Column2);
 }
        private void SetUser0Uniforms(UniformBlock block)
        {
            //Todo figure out what values do what.

            Vector4[] blockData = new Vector4[40];
            blockData[0] = new Vector4(0.5539238f, 0.0001027618f, 0.1277139f, 0);
            blockData[1] = new Vector4(0.5539238f, 0.0001027618f, 0.1277139f, 0);
            blockData[2] = new Vector4(0.6320431f, 0.0001071832f, 0.1332085f, 0);
            blockData[3] = new Vector4(0.6589496f, 0.01626004f, 0.002031374f, 0);
            blockData[4] = new Vector4(0.5524251f, 0.002031374f, 0.7208676f, 0);
            blockData[5] = new Vector4(0.004354607f, 0.3782967f, 0.001357751f, 0);

            blockData[32] = new Vector4(-0.1398054f, 0.4021495f, -0.2326191f, 0.6173416f);
            blockData[33] = new Vector4(-0.1931684f, 0.5908378f, -0.3368035f, 0.7598742f);
            blockData[34] = new Vector4(-0.2408963f, 0.8209172f, -0.3954142f, 0.8875099f);
            blockData[35] = new Vector4(-0.1189116f, -0.1235714f, -0.003013233f, 0.1132319f);
            blockData[36] = new Vector4(-0.1978887f, -0.2433449f, 0.004212617f, 0.1701293f);
            blockData[37] = new Vector4(-0.2578259f, -0.3457301f, -0.01130502f, 0.2127025f);
            blockData[38] = new Vector4(-0.1228433f, -0.168933f, -0.2239204f, 1f);

            //    block.Add(Properties.Resources.User0);

            block.Add(blockData);

            /*  block.Add(new Vector4(0.5539238f, 0.0001027618f, 0.1277139f, 0));
             * block.Add(new Vector4(0.5539238f, 0.0001027618f, 0.1277139f, 0));
             * block.Add(new Vector4(0.6320431f, 0.0001071832f, 0.1332085f, 0));
             * block.Add(new Vector4(0.6589496f, 0.01626004f, 0.002031374f, 0));
             * block.Add(new Vector4(0.5524251f, 0.002031374f, 0.7208676f, 0));
             * block.Add(new Vector4(0.004354607f, 0.3782967f, 0.001357751f, 0));
             * block.Add(new Vector4(0.004354607f, 0.3782967f, 0.001357751f, 0));
             * block.Add(new Vector4(0.005028193f, 0.399294f, 0.00143311f, 0));
             * block.Add(new Vector4(0.2000978f, 0.4690126f, 0.005039762f, 0));
             * block.Add(new Vector4(0.004606879f, 0.4690126f, 0.149474f, 0));
             * block.Add(new Vector4(0.3544904f, 0.4615507f, 0, 0));
             * block.Add(new Vector4(0.5075025f, 0.6489585f, 0.004094653f, 0));
             *
             * block.Add(new Vector4(0.025f, 1.2f, 0.2f, 0.3f));
             * block.Add(new Vector4(0.991f, 0.8f, 1.88f, 1.0f));
             * block.Add(new Vector4(1, 0.7071068f, -0.7071068f, 0.3f));
             *
             * block.Add(new Vector4(0));
             * block.Add(new Vector4(0));
             * block.Add(new Vector4(0));
             * block.Add(new Vector4(0));
             * block.Add(new Vector4(0));
             * block.Add(new Vector4(0));
             *
             * block.Add(new Vector4(1, 0, 0, 0));
             * block.Add(new Vector4(0, 1, 0, 0));
             * block.Add(new Vector4(0, 0, 1, 0));
             *
             * block.Add(new Vector4(1, 0, 0, 0));
             * block.Add(new Vector4(0, 1, 0, 0));
             * block.Add(new Vector4(0, 0, 1, 0));
             * block.Add(new Vector4(0, 0, 0, 1));
             *
             * block.Add(new Vector4(0));
             *
             * block.Add(new Vector4(0.5f, 2.5f, 1000f, 0.7f));
             * block.Add(new Vector4(0.5f, 0.25f, 0.9f, 0.0f));*/
        }