示例#1
0
        private static void ApplyTransformFix(FMDL fmdl, FSHP m, SF.Shader shader)
        {
            Matrix4 idenity = Matrix4.Identity;

            shader.SetInt("NoSkinning", 0);
            shader.SetInt("RigidSkinning", 0);
            shader.SetInt("SingleBoneIndex", m.BoneIndex);

            shader.SetMatrix4x4("SingleBoneBindTransform", ref idenity);
            //Some objects will have no weights or indices. These will weigh to the bone index in the shape section.

            if (m.VertexSkinCount == 1)
            {
                shader.SetInt("RigidSkinning", 1);
            }
            if (m.VertexSkinCount == 0)
            {
                if (fmdl.Skeleton.bones.Count > 0)
                {
                    Matrix4 transform = fmdl.Skeleton.bones[m.BoneIndex].invert * fmdl.Skeleton.bones[m.BoneIndex].Transform;

                    shader.SetMatrix4x4("SingleBoneBindTransform", ref transform);
                    shader.SetInt("NoSkinning", 1);
                }
            }
        }
示例#2
0
        private static void BindGLTexture(MatTexture tex, SF.Shader shader, STGenericTexture texture)
        {
            //If the texture is still not initialized then return
            if (!texture.RenderableTex.GLInitialized)
            {
                return;
            }

            if (tex.Type == STGenericMatTexture.TextureType.Diffuse)
            {
                shader.SetInt("RedChannel", (int)texture.RedChannel);
                shader.SetInt("GreenChannel", (int)texture.GreenChannel);
                shader.SetInt("BlueChannel", (int)texture.BlueChannel);
                shader.SetInt("AlphaChannel", (int)texture.AlphaChannel);
            }


            //     GL.ActiveTexture(TextureUnit.Texture0 + texid);
            GL.BindTexture(TextureTarget.Texture2D, texture.RenderableTex.TexID);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)MatTexture.wrapmode[tex.WrapModeS]);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)MatTexture.wrapmode[tex.WrapModeT]);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)MatTexture.minfilter[tex.MinFilter]);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)MatTexture.magfilter[tex.MagFilter]);
            GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)ExtTextureFilterAnisotropic.TextureMaxAnisotropyExt, 0.0f);
        }
示例#3
0
 private static void DrawModelWireframe(STGenericObject p, SF.Shader shader)
 {
     // use vertex color for wireframe color
     shader.SetInt("colorOverride", 1);
     GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
     GL.Enable(EnableCap.LineSmooth);
     GL.LineWidth(1.5f);
     GL.DrawElements(PrimitiveType.Triangles, p.lodMeshes[p.DisplayLODIndex].displayFaceSize, DrawElementsType.UnsignedInt, p.Offset);
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
     shader.SetInt("colorOverride", 0);
 }
示例#4
0
        private void SetRenderSettings(SF.Shader shader, bool useVertexColors)
        {
            shader.SetBoolToInt("renderVertColor", Runtime.renderVertColor && useVertexColors);
            shader.SetBoolToInt("useNormalMap", Runtime.useNormalMap);
            shader.SetBoolToInt("renderR", Runtime.renderR);
            shader.SetBoolToInt("renderG", Runtime.renderG);
            shader.SetBoolToInt("renderB", Runtime.renderB);
            shader.SetBoolToInt("renderAlpha", Runtime.renderAlpha);

            shader.SetInt("renderType", (int)Runtime.viewportShading);
            shader.SetInt("uvChannel", (int)Runtime.uvChannel);

            shader.SetBoolToInt("renderFog", Runtime.renderFog);

            shader.SetBoolToInt("renderDiffuse", Runtime.renderDiffuse);
            shader.SetBoolToInt("renderSpecular", Runtime.renderSpecular);
            shader.SetBoolToInt("renderFresnel", Runtime.renderFresnel);
        }
示例#5
0
        private static void DrawModelSelection(STGenericObject p, SF.Shader shader)
        {
            //This part needs to be reworked for proper outline. Currently would make model disappear

            /*     GL.Enable(EnableCap.DepthTest);
             *   GL.StencilOp(StencilOp.Keep, StencilOp.Keep, StencilOp.Replace);
             *
             *   GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
             *
             *   GL.StencilMask(0x00);
             *
             *   GL.StencilFunc(StencilFunction.Always, 1, 0xFF); // all fragments should update the stencil buffer
             *   GL.StencilMask(0xFF); // enable writing to the stencil buffer
             *   GL.DrawElements(PrimitiveType.Triangles, p.lodMeshes[p.DisplayLODIndex].displayFaceSize, DrawElementsType.UnsignedInt, p.Offset);
             *
             *   GL.StencilFunc(StencilFunction.Notequal, 1, 0xFF);
             *   GL.StencilMask(0x00); // enable writing to the stencil buffer
             *   GL.Disable(EnableCap.DepthTest);
             *
             *   shader.SetInt("colorOverride", 1);
             *
             *   GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
             *   GL.LineWidth(2.0f);
             *   GL.DrawElements(PrimitiveType.Triangles, p.lodMeshes[p.DisplayLODIndex].displayFaceSize, DrawElementsType.UnsignedInt, p.Offset);
             *   GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
             *
             *   shader.SetInt("colorOverride", 0);
             *
             *   GL.StencilMask(0xFF);
             *   GL.Enable(EnableCap.DepthTest);*/

            // Override the model color with white in the shader.

            shader.SetInt("colorOverride", 1);
            GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
            GL.Enable(EnableCap.LineSmooth);
            GL.LineWidth(1.3f);
            GL.DrawElements(PrimitiveType.Triangles, p.lodMeshes[p.DisplayLODIndex].displayFaceSize, DrawElementsType.UnsignedInt, p.Offset);
            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
            shader.SetInt("colorOverride", 0);

            GL.DrawElements(PrimitiveType.Triangles, p.lodMeshes[p.DisplayLODIndex].displayFaceSize, DrawElementsType.UnsignedInt, p.Offset);
        }
示例#6
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);
        }
示例#7
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");
        }
示例#8
0
        private static void SetTextureUniforms(FMAT mat, FSHP m, SF.Shader shader)
        {
            GL.ActiveTexture(TextureUnit.Texture0 + 1);
            GL.BindTexture(TextureTarget.Texture2D, RenderTools.defaultTex.RenderableTex.TexID);

            GL.ActiveTexture(TextureUnit.Texture11);
            GL.Uniform1(shader.GetUniformLocation("weightRamp1"), 11);
            GL.BindTexture(TextureTarget.Texture2D, RenderTools.BoneWeightGradient.Id);

            GL.ActiveTexture(TextureUnit.Texture12);
            GL.Uniform1(shader.GetUniformLocation("weightRamp2"), 12);
            GL.BindTexture(TextureTarget.Texture2D, RenderTools.BoneWeightGradient2.Id);

            GL.Uniform1(shader.GetUniformLocation("debugOption"), 2);


            GL.ActiveTexture(TextureUnit.Texture10);
            GL.Uniform1(shader.GetUniformLocation("UVTestPattern"), 10);
            GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID);

            GL.Uniform1(shader.GetUniformLocation("normalMap"), 0);
            GL.Uniform1(shader.GetUniformLocation("BakeShadowMap"), 0);

            shader.SetInt("RedChannel", 0);
            shader.SetInt("GreenChannel", 1);
            shader.SetInt("BlueChannel", 2);
            shader.SetInt("AlphaChannel", 3);

            LoadPBRMaps(shader);

            for (int t = 0; t < mat.TextureMaps.Count; t++)
            {
                MatTexture matex = (MatTexture)mat.TextureMaps[t];

                if (matex.Type == MatTexture.TextureType.Diffuse)
                {
                    mat.HasDiffuseMap = TextureUniform(shader, mat, "DiffuseMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.Normal)
                {
                    mat.HasNormalMap = TextureUniform(shader, mat, "NormalMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.Emission)
                {
                    mat.HasEmissionMap = TextureUniform(shader, mat, "EmissionMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.Specular)
                {
                    mat.HasSpecularMap = TextureUniform(shader, mat, "SpecularMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.Shadow)
                {
                    mat.HasShadowMap = TextureUniform(shader, mat, "BakeShadowMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.Light)
                {
                    mat.HasLightMap = TextureUniform(shader, mat, "BakeLightMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.Metalness)
                {
                    mat.HasMetalnessMap = TextureUniform(shader, mat, "MetalnessMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.Roughness)
                {
                    mat.HasRoughnessMap = TextureUniform(shader, mat, "RoughnessMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.TeamColor)
                {
                    mat.HasTeamColorMap = TextureUniform(shader, mat, "TeamColorMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.Transparency)
                {
                    mat.HasTransparencyMap = TextureUniform(shader, mat, "TransparencyMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.DiffuseLayer2)
                {
                    mat.HasDiffuseLayer = TextureUniform(shader, mat, "DiffuseLayer", matex);
                }
                else if (matex.Type == MatTexture.TextureType.SphereMap)
                {
                    mat.HasSphereMap = mat.HasSphereMap = TextureUniform(shader, mat, "SphereMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.SubSurfaceScattering)
                {
                    mat.HasSubSurfaceScatteringMap = TextureUniform(shader, mat, "SubSurfaceScatteringMap", matex);
                }
                else if (matex.Type == MatTexture.TextureType.MRA)
                {
                    mat.HasMRA = TextureUniform(shader, mat, "MRA", matex);
                }
            }

            SetDefaultTextureAttributes(mat, shader);
        }