private static void DrawMdoelHoverSelection(STGenericObject p, SF.Shader shader, bool IsSelected, bool IsHovered) { if (IsHovered && IsSelected) { shader.SetVector4("pickingColor", hoverColor); } else if (IsHovered || IsSelected) { shader.SetVector4("pickingColor", selectColor); } else { shader.SetVector4("pickingColor", new Vector4(1)); } }
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); }
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)); } } }
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"); }