Example #1
0
        public override void Draw(GL_ControlModern control, Pass pass, EditorSceneBase editorScene)
        {
            CheckBuffers();

            if (!Runtime.OpenTKInitialized || !Runtime.renderBones || !Visible)
            {
                return;
            }

            SF.Shader shader = OpenTKSharedResources.shaders["BONE"];
            shader.UseProgram();

            GL.Disable(EnableCap.CullFace);

            if (Runtime.boneXrayDisplay)
            {
                GL.Disable(EnableCap.DepthTest);
            }

            if (Runtime.renderBoundingBoxes)
            {
                DrawBoundingBoxes();
            }

            control.UpdateModelMatrix(
                Matrix4.CreateScale(Runtime.previewScale * PreviewScale) *
                Matrix4.CreateTranslation(Selected ? editorScene.CurrentAction.NewPos(position) : position));


            shader.EnableVertexAttributes();
            shader.SetMatrix4x4("rotation", ref prismRotation);

            Matrix4 camMat         = control.CameraMatrix;
            Matrix4 mdlMat         = control.ModelMatrix;
            Matrix4 projMat        = control.ProjectionMatrix;
            Matrix4 computedCamMtx = camMat * projMat;

            shader.SetMatrix4x4("mtxCam", ref computedCamMtx);
            shader.SetMatrix4x4("mtxMdl", ref mdlMat);

            foreach (STBone bn in bones)
            {
                if (!bn.Checked)
                {
                    continue;
                }

                shader.SetVector4("boneColor", ColorUtility.ToVector4(boneColor));
                shader.SetFloat("scale", Runtime.bonePointSize * BonePointScale);
                shader.SetMatrix4x4("ModelMatrix", ref bn.ModelMatrix);


                Matrix4 transform = bn.Transform;

                shader.SetMatrix4x4("bone", ref transform);
                shader.SetInt("hasParent", bn.parentIndex != -1 ? 1 : 0);

                if (bn.parentIndex != -1)
                {
                    var transformParent = ((STBone)bn.Parent).Transform;
                    shader.SetMatrix4x4("parent", ref transformParent);
                }

                Draw(shader);

                if (Runtime.SelectedBoneIndex == bn.GetIndex())
                {
                    shader.SetVector4("boneColor", ColorUtility.ToVector4(selectedBoneColor));
                }

                shader.SetInt("hasParent", 0);
                Draw(shader);
            }

            shader.DisableVertexAttributes();

            GL.UseProgram(0);
            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
        }
Example #2
0
        private static void SetUniforms(FMAT mat, SF.Shader shader, FSHP m, int id)
        {
            shader.SetBoolToInt("isTransparent", mat.isTransparent);

            shader.SetFloat("ao_density", 1);
            shader.SetFloat("shadow_density", 1);

            shader.SetFloat("normal_map_weight", 1);

            //Bake map UV coordinate ST
            shader.SetVector4("gsys_bake_st0", new Vector4(1, 1, 0, 0));
            shader.SetVector4("gsys_bake_st1", new Vector4(1, 1, 0, 0));

            shader.SetBoolToInt("UseSpecularColor",
                                (mat.GetOptionValue("specular_mask_is_color") == 1) ||
                                mat.GetOptionValue("enable_specular_color") == 1);

            shader.SetBoolToInt("UseMultiTexture", mat.GetOptionValue("enable_multi_texture") == 1);

            //Colors
            shader.SetVector4("const_color0", new Vector4(1, 1, 1, 1));
            shader.SetVector4("base_color_mul_color", new Vector4(1, 1, 1, 1));
            shader.SetVector3("albedo_tex_color", new Vector3(1, 1, 1));
            shader.SetVector3("emission_color", new Vector3(1, 1, 1));
            shader.SetVector3("specular_color", new Vector3(1, 1, 1));

            shader.SetFloat("fuv1_mtx", 0);

            //SRT
            shader.SetVector4("tex_mtx0", new Vector4(1, 1, 1, 1));
            shader.SetVector2("SRT_Scale", new Vector2(1, 1));
            shader.SetFloat("SRT_Rotate", 0);
            shader.SetVector2("SRT_Translate", new Vector2(0, 0));

            shader.SetInt("selectedBoneIndex", Runtime.SelectedBoneIndex);

            SetUniformData(mat, shader, "base_color_mul_color");

            shader.SetInt("enableCellShading", 0);
            bool HasTans = m.vertexAttributes.Any(x => x.Name == "_t0");

            shader.SetBoolToInt("hasTangents", HasTans);

            SetUniformData(mat, shader, "fuv1_mtx");

            SetUniformData(mat, shader, "gsys_bake_st0");
            SetUniformData(mat, shader, "gsys_bake_st1");

            SetUniformData(mat, shader, "ao_density");
            SetUniformData(mat, shader, "shadow_density");
            SetUniformData(mat, shader, "normal_map_weight");

            SetUniformData(mat, shader, "const_color0");
            SetUniformData(mat, shader, "base_color_mul_color");
            SetUniformData(mat, shader, "albedo_tex_color");
            SetUniformData(mat, shader, "emission_color");
            SetUniformData(mat, shader, "specular_color");


            //This uniform sets various maps for BOTW to use second UV channel
            SetUniformData(mat, shader, "uking_texture2_texcoord");

            SetUniformData(mat, shader, "cIsEnableNormalMap");

            SetUniformData(mat, shader, "texsrt0");
            SetUniformData(mat, shader, "tex_mtx0");
            SetUniformData(mat, shader, "texmtx0");

            //Sets shadow type
            //0 = Ambient occusion bake map
            //1 = Shadow
            //2 = Shadow + Ambient occusion map
            SetUniformData(mat, shader, "bake_shadow_type");
            SetUniformData(mat, shader, "bake_light_type");
            SetUniformData(mat, shader, "gsys_bake_light_scale");

            SetUniformData(mat, shader, "enable_projection_light");
            SetUniformData(mat, shader, "enable_actor_light");

            SetUniformData(mat, shader, "bake_calc_type");
        }
Example #3
0
        private static void SetUniformData(FMAT mat, SF.Shader shader, string propertyName)
        {
            if (mat.shaderassign.options.ContainsKey(propertyName))
            {
                float value = float.Parse(mat.shaderassign.options[propertyName]);
                shader.SetFloat(propertyName, value);
            }

            Dictionary <string, BfresShaderParam> matParams = mat.matparam;

            if (mat.animatedMatParams.ContainsKey(propertyName))
            {
                matParams = mat.animatedMatParams;
            }

            if (matParams.ContainsKey(propertyName))
            {
                if (matParams[propertyName].Type == ShaderParamType.Float)
                {
                    if (mat.anims.ContainsKey(propertyName))
                    {
                        matParams[propertyName].ValueFloat[0] = mat.anims[propertyName][0];
                    }
                    shader.SetFloat(propertyName, matParams[propertyName].ValueFloat[0]);
                }

                if (matParams[propertyName].Type == ShaderParamType.Float2)
                {
                    if (mat.anims.ContainsKey(propertyName))
                    {
                        matParams[propertyName].ValueFloat = new float[2] {
                            mat.anims[propertyName][0], mat.anims[propertyName][1]
                        };
                    }

                    shader.SetVector2(propertyName, Utils.ToVec2(matParams[propertyName].ValueFloat));
                }

                if (matParams[propertyName].Type == ShaderParamType.Float3)
                {
                    if (mat.anims.ContainsKey(propertyName))
                    {
                        matParams[propertyName].ValueFloat = new float[3] {
                            mat.anims[propertyName][0],
                            mat.anims[propertyName][1],
                            mat.anims[propertyName][2]
                        };
                    }

                    shader.SetVector3(propertyName, Utils.ToVec3(matParams[propertyName].ValueFloat));
                }
                if (matParams[propertyName].Type == ShaderParamType.Float4)
                {
                    if (mat.anims.ContainsKey(propertyName))
                    {
                        matParams[propertyName].ValueFloat = new float[4] {
                            mat.anims[propertyName][0], mat.anims[propertyName][1],
                            mat.anims[propertyName][2], mat.anims[propertyName][3]
                        };
                    }

                    shader.SetVector4(propertyName, Utils.ToVec4(matParams[propertyName].ValueFloat));
                }
                if (matParams[propertyName].Type == ShaderParamType.TexSrt)
                {
                    // Vector 2 Scale
                    // 1 roation float
                    // Vector2 translate
                    TexSrt texSRT = matParams[propertyName].ValueTexSrt;

                    shader.SetVector2("SRT_Scale", Utils.ToVec2(texSRT.Scaling));
                    shader.SetFloat("SRT_Rotate", texSRT.Rotation);
                    shader.SetVector2("SRT_Translate", Utils.ToVec2(texSRT.Translation));
                }
                if (matParams[propertyName].Type == ShaderParamType.TexSrtEx)
                {
                    // Vector 2 Scale
                    // 1 roation float
                    // Vector2 translate
                    TexSrtEx texSRT = matParams[propertyName].ValueTexSrtEx;

                    shader.SetVector2("SRT_Scale", Utils.ToVec2(texSRT.Scaling));
                    shader.SetFloat("SRT_Rotate", texSRT.Rotation);
                    shader.SetVector2("SRT_Translate", Utils.ToVec2(texSRT.Translation));
                }

                //MTA SRT
                if (propertyName == "texsrt0" && mat.shaderassign.ShaderArchive == "ssg")
                {
                    TexSrt texSRT = matParams[propertyName].ValueTexSrt;

                    shader.SetVector2("SRT_Scale", Utils.ToVec2(texSRT.Scaling));
                    shader.SetFloat("SRT_Rotate", texSRT.Rotation);
                    shader.SetVector2("SRT_Translate", Utils.ToVec2(texSRT.Translation));
                }
            }
        }
Example #4
0
        private void DrawBfres(GL_ControlModern control, Pass pass)
        {
            if (!Runtime.OpenTKInitialized || pass == Pass.TRANSPARENT || Disposing)
            {
                return;
            }

            bool buffersWereInitialized = ibo_elements != 0 && vbo_position != 0;

            if (!buffersWereInitialized)
            {
                GenerateBuffers();
            }

            if (Hovered == true)
            {
                throw new Exception("model selected");
            }

            //Temporarily revert to using this shader system as it is easy to port back
            //This is much quicker. Will change after shaders are handled faster
            SF.Shader shader = OpenTKSharedResources.shaders["BFRES"];

            if (Runtime.EnablePBR)
            {
                shader = OpenTKSharedResources.shaders["BFRES_PBR"];
            }

            if (models.Count > 0)
            {
                if (models[0].shapes.Count > 0)
                {
                    if (models[0].shapes[0].GetFMAT().shaderassign.ShaderModel == "uking_mat")
                    {
                        shader = OpenTKSharedResources.shaders["BFRES_Botw"];

                        //Botw uses small models so lower the bone size
                        Runtime.bonePointSize = 0.040f;
                    }
                }
            }

            if (Runtime.viewportShading != Runtime.ViewportShading.Default)
            {
                shader = OpenTKSharedResources.shaders["BFRES_Debug"];
            }

            if (Runtime.viewportShading == Runtime.ViewportShading.Lighting && Runtime.EnablePBR)
            {
                shader = OpenTKSharedResources.shaders["BFRES_PBR"];
            }

            shader.UseProgram();
            control.UpdateModelMatrix(ModelTransform * Matrix4.CreateScale(Runtime.previewScale));

            Matrix4 camMat         = control.CameraMatrix;
            Matrix4 mdlMat         = control.ModelMatrix;
            Matrix4 projMat        = control.ProjectionMatrix;
            Matrix4 computedCamMtx = camMat * projMat;
            Matrix4 mvpMat         = control.ModelMatrix * control.CameraMatrix * control.ProjectionMatrix;

            Matrix4 sphereMatrix = mvpMat;

            Matrix4 invertedCamera = Matrix4.Identity;

            //   invertedCamera = mvpMat.Inverted();
            //  if (invertedCamera.Determinant == 0)
            //      invertedCamera = Matrix4.Identity;

            sphereMatrix = invertedCamera;
            sphereMatrix.Transpose();

            invertedCamera = mvpMat.Inverted();
            Vector3 lightDirection = new Vector3(0f, 0f, -1f);

            shader.SetVector3("specLightDirection", Vector3.TransformNormal(lightDirection, invertedCamera).Normalized());
            shader.SetVector3("difLightDirection", Vector3.TransformNormal(lightDirection, invertedCamera).Normalized());

            shader.SetMatrix4x4("sphereMatrix", ref sphereMatrix);

            shader.SetMatrix4x4("mtxCam", ref computedCamMtx);
            shader.SetMatrix4x4("mtxMdl", ref mdlMat);
            shader.SetVector3("cameraPosition", control.CameraPosition);

            Vector4 pickingColor = control.NextPickingColor();

            shader.SetVector3("difLightColor", new Vector3(1));
            shader.SetVector3("ambLightColor", new Vector3(1));

            GL.Enable(EnableCap.AlphaTest);
            GL.AlphaFunc(AlphaFunction.Gequal, 0.1f);

            DrawModels(shader, control);

            if (Runtime.renderNormalsPoints)
            {
                shader = OpenTKSharedResources.shaders["BFRES_Normals"];
                shader.UseProgram();

                shader.SetMatrix4x4("camMtx", ref camMat);
                shader.SetMatrix4x4("mtxProj", ref projMat);
                shader.SetMatrix4x4("mtxCam", ref computedCamMtx);
                shader.SetMatrix4x4("mtxMdl", ref mdlMat);

                shader.SetFloat("normalsLength", Runtime.normalsLineLength);

                DrawModels(shader, control);
            }

            GL.UseProgram(0);
            GL.Disable(EnableCap.DepthTest);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);
        }