コード例 #1
0
ファイル: Shader.cs プロジェクト: zifux/AssetStudio
        public SerializedPass(ObjectReader reader)
        {
            var version = reader.version;

            int numIndices = reader.ReadInt32();

            m_NameIndices = new KeyValuePair <string, int> [numIndices];
            for (int i = 0; i < numIndices; i++)
            {
                m_NameIndices[i] = new KeyValuePair <string, int>(reader.ReadAlignedString(), reader.ReadInt32());
            }

            m_Type                 = (PassType)reader.ReadInt32();
            m_State                = new SerializedShaderState(reader);
            m_ProgramMask          = reader.ReadUInt32();
            progVertex             = new SerializedProgram(reader);
            progFragment           = new SerializedProgram(reader);
            progGeometry           = new SerializedProgram(reader);
            progHull               = new SerializedProgram(reader);
            progDomain             = new SerializedProgram(reader);
            m_HasInstancingVariant = reader.ReadBoolean();
            if (version[0] >= 2018) //2018 and up
            {
                var m_HasProceduralInstancingVariant = reader.ReadBoolean();
            }
            reader.AlignStream();
            m_UseName     = reader.ReadAlignedString();
            m_Name        = reader.ReadAlignedString();
            m_TextureName = reader.ReadAlignedString();
            m_Tags        = new SerializedTagMap(reader);
        }
コード例 #2
0
ファイル: Shader.cs プロジェクト: zbx911/AssetStudio
        public SerializedPass(ObjectReader reader)
        {
            var version = reader.version;

            if (version[0] > 2020 || (version[0] == 2020 && version[1] >= 2)) //2020.2 and up
            {
                int numEditorDataHash = reader.ReadInt32();
                m_EditorDataHash = new Hash128[numEditorDataHash];
                for (int i = 0; i < numEditorDataHash; i++)
                {
                    m_EditorDataHash[i] = new Hash128(reader);
                }
                reader.AlignStream();
                m_Platforms = reader.ReadUInt8Array();
                reader.AlignStream();
                if (version[0] < 2021 || (version[0] == 2021 && version[1] < 2)) //2021.1 and down
                {
                    m_LocalKeywordMask = reader.ReadUInt16Array();
                    reader.AlignStream();
                    m_GlobalKeywordMask = reader.ReadUInt16Array();
                    reader.AlignStream();
                }
            }

            int numIndices = reader.ReadInt32();

            m_NameIndices = new KeyValuePair <string, int> [numIndices];
            for (int i = 0; i < numIndices; i++)
            {
                m_NameIndices[i] = new KeyValuePair <string, int>(reader.ReadAlignedString(), reader.ReadInt32());
            }

            m_Type        = (PassType)reader.ReadInt32();
            m_State       = new SerializedShaderState(reader);
            m_ProgramMask = reader.ReadUInt32();
            progVertex    = new SerializedProgram(reader);
            progFragment  = new SerializedProgram(reader);
            progGeometry  = new SerializedProgram(reader);
            progHull      = new SerializedProgram(reader);
            progDomain    = new SerializedProgram(reader);
            if (version[0] > 2019 || (version[0] == 2019 && version[1] >= 3)) //2019.3 and up
            {
                progRayTracing = new SerializedProgram(reader);
            }
            m_HasInstancingVariant = reader.ReadBoolean();
            if (version[0] >= 2018) //2018 and up
            {
                var m_HasProceduralInstancingVariant = reader.ReadBoolean();
            }
            reader.AlignStream();
            m_UseName     = reader.ReadAlignedString();
            m_Name        = reader.ReadAlignedString();
            m_TextureName = reader.ReadAlignedString();
            m_Tags        = new SerializedTagMap(reader);
            if (version[0] > 2021 || (version[0] == 2021 && version[1] >= 2)) //2021.2 and up
            {
                m_SerializedKeywordStateMask = reader.ReadUInt16Array();
                reader.AlignStream();
            }
        }
コード例 #3
0
        private static string ConvertSerializedShaderState(SerializedShaderState m_State)
        {
            var sb = new StringBuilder();

            if (!string.IsNullOrEmpty(m_State.m_Name))
            {
                sb.Append($"  Name \"{m_State.m_Name}\"\n");
            }
            if (m_State.m_LOD != 0)
            {
                sb.Append($"  LOD {m_State.m_LOD}\n");
            }

            sb.Append(ConvertSerializedTagMap(m_State.m_Tags, 2));

            sb.Append(ConvertSerializedShaderRTBlendState(m_State.rtBlend));

            if (m_State.alphaToMask.val > 0f)
            {
                sb.Append("  AlphaToMask On\n");
            }

            if (m_State.zClip?.val != 1f) //ZClip On
            {
                sb.Append("  ZClip Off\n");
            }

            if (m_State.zTest.val != 4f) //ZTest LEqual
            {
                sb.Append("  ZTest ");
                switch (m_State.zTest.val) //enum CompareFunction
                {
                case 0f:                   //kFuncDisabled
                    sb.Append("Off");
                    break;

                case 1f:     //kFuncNever
                    sb.Append("Never");
                    break;

                case 2f:     //kFuncLess
                    sb.Append("Less");
                    break;

                case 3f:     //kFuncEqual
                    sb.Append("Equal");
                    break;

                case 5f:     //kFuncGreater
                    sb.Append("Greater");
                    break;

                case 6f:     //kFuncNotEqual
                    sb.Append("NotEqual");
                    break;

                case 7f:     //kFuncGEqual
                    sb.Append("GEqual");
                    break;

                case 8f:     //kFuncAlways
                    sb.Append("Always");
                    break;
                }

                sb.Append("\n");
            }

            if (m_State.zWrite.val != 1f) //ZWrite On
            {
                sb.Append("  ZWrite Off\n");
            }

            if (m_State.culling.val != 2f) //Cull Back
            {
                sb.Append("  Cull ");
                switch (m_State.culling.val) //enum CullMode
                {
                case 0f:                     //kCullOff
                    sb.Append("Off");
                    break;

                case 1f:     //kCullFront
                    sb.Append("Front");
                    break;
                }
                sb.Append("\n");
            }

            if (m_State.offsetFactor.val != 0f || m_State.offsetUnits.val != 0f)
            {
                sb.Append($"  Offset {m_State.offsetFactor.val}, {m_State.offsetUnits.val}\n");
            }

            //TODO Stencil

            //TODO Fog

            if (m_State.lighting)
            {
                sb.Append($"  Lighting {(m_State.lighting ? "On" : "Off")}\n");
            }

            sb.Append($"  GpuProgramID {m_State.gpuProgramID}\n");

            return(sb.ToString());
        }
コード例 #4
0
        private static string ConvertSerializedShaderState(SerializedShaderState m_State)
        {
            var sb = new StringBuilder();

            if (!string.IsNullOrEmpty(m_State.m_Name))
            {
                sb.Append($"  Name \"{m_State.m_Name}\"\n");
            }
            if (m_State.m_LOD != 0)
            {
                sb.Append($"  LOD {m_State.m_LOD}\n");
            }

            sb.Append(ConvertSerializedTagMap(m_State.m_Tags, 2));

            sb.Append(ConvertSerializedShaderRTBlendState(m_State.rtBlend, m_State.rtSeparateBlend));

            if (m_State.alphaToMask.val > 0f)
            {
                sb.Append("  AlphaToMask On\n");
            }

            if (m_State.zClip?.val != 1f) //ZClip On
            {
                sb.Append("  ZClip Off\n");
            }

            if (m_State.zTest.val != 4f) //ZTest LEqual
            {
                sb.Append("  ZTest ");
                switch (m_State.zTest.val) //enum CompareFunction
                {
                case 0f:                   //kFuncDisabled
                    sb.Append("Off");
                    break;

                case 1f:     //kFuncNever
                    sb.Append("Never");
                    break;

                case 2f:     //kFuncLess
                    sb.Append("Less");
                    break;

                case 3f:     //kFuncEqual
                    sb.Append("Equal");
                    break;

                case 5f:     //kFuncGreater
                    sb.Append("Greater");
                    break;

                case 6f:     //kFuncNotEqual
                    sb.Append("NotEqual");
                    break;

                case 7f:     //kFuncGEqual
                    sb.Append("GEqual");
                    break;

                case 8f:     //kFuncAlways
                    sb.Append("Always");
                    break;
                }

                sb.Append("\n");
            }

            if (m_State.zWrite.val != 1f) //ZWrite On
            {
                sb.Append("  ZWrite Off\n");
            }

            if (m_State.culling.val != 2f) //Cull Back
            {
                sb.Append("  Cull ");
                switch (m_State.culling.val) //enum CullMode
                {
                case 0f:                     //kCullOff
                    sb.Append("Off");
                    break;

                case 1f:     //kCullFront
                    sb.Append("Front");
                    break;
                }
                sb.Append("\n");
            }

            if (m_State.offsetFactor.val != 0f || m_State.offsetUnits.val != 0f)
            {
                sb.Append($"  Offset {m_State.offsetFactor.val}, {m_State.offsetUnits.val}\n");
            }

            if (m_State.stencilRef.val != 0f ||
                m_State.stencilReadMask.val != 255f ||
                m_State.stencilWriteMask.val != 255f ||
                m_State.stencilOp.pass.val != 0f ||
                m_State.stencilOp.fail.val != 0f ||
                m_State.stencilOp.zFail.val != 0f ||
                m_State.stencilOp.comp.val != 8f ||
                m_State.stencilOpFront.pass.val != 0f ||
                m_State.stencilOpFront.fail.val != 0f ||
                m_State.stencilOpFront.zFail.val != 0f ||
                m_State.stencilOpFront.comp.val != 8f ||
                m_State.stencilOpBack.pass.val != 0f ||
                m_State.stencilOpBack.fail.val != 0f ||
                m_State.stencilOpBack.zFail.val != 0f ||
                m_State.stencilOpBack.comp.val != 8f)
            {
                sb.Append("  Stencil {\n");
                if (m_State.stencilRef.val != 0f)
                {
                    sb.Append($"   Ref {m_State.stencilRef.val}\n");
                }
                if (m_State.stencilReadMask.val != 255f)
                {
                    sb.Append($"   ReadMask {m_State.stencilReadMask.val}\n");
                }
                if (m_State.stencilWriteMask.val != 255f)
                {
                    sb.Append($"   WriteMask {m_State.stencilWriteMask.val}\n");
                }
                if (m_State.stencilOp.pass.val != 0f ||
                    m_State.stencilOp.fail.val != 0f ||
                    m_State.stencilOp.zFail.val != 0f ||
                    m_State.stencilOp.comp.val != 8f)
                {
                    sb.Append(ConvertSerializedStencilOp(m_State.stencilOp, ""));
                }
                if (m_State.stencilOpFront.pass.val != 0f ||
                    m_State.stencilOpFront.fail.val != 0f ||
                    m_State.stencilOpFront.zFail.val != 0f ||
                    m_State.stencilOpFront.comp.val != 8f)
                {
                    sb.Append(ConvertSerializedStencilOp(m_State.stencilOpFront, "Front"));
                }
                if (m_State.stencilOpBack.pass.val != 0f ||
                    m_State.stencilOpBack.fail.val != 0f ||
                    m_State.stencilOpBack.zFail.val != 0f ||
                    m_State.stencilOpBack.comp.val != 8f)
                {
                    sb.Append(ConvertSerializedStencilOp(m_State.stencilOpBack, "Back"));
                }
                sb.Append("  }\n");
            }

            if (m_State.fogMode != FogMode.kFogUnknown ||
                m_State.fogColor.x.val != 0f ||
                m_State.fogColor.y.val != 0f ||
                m_State.fogColor.z.val != 0f ||
                m_State.fogColor.w.val != 0f ||
                m_State.fogDensity.val != 0f ||
                m_State.fogStart.val != 0f ||
                m_State.fogEnd.val != 0f)
            {
                sb.Append("  Fog {\n");
                if (m_State.fogMode != FogMode.kFogUnknown)
                {
                    sb.Append("   Mode ");
                    switch (m_State.fogMode)
                    {
                    case FogMode.kFogDisabled:
                        sb.Append("Off");
                        break;

                    case FogMode.kFogLinear:
                        sb.Append("Linear");
                        break;

                    case FogMode.kFogExp:
                        sb.Append("Exp");
                        break;

                    case FogMode.kFogExp2:
                        sb.Append("Exp2");
                        break;
                    }
                    sb.Append("\n");
                }
                if (m_State.fogColor.x.val != 0f ||
                    m_State.fogColor.y.val != 0f ||
                    m_State.fogColor.z.val != 0f ||
                    m_State.fogColor.w.val != 0f)
                {
                    sb.AppendFormat("   Color ({0},{1},{2},{3})\n",
                                    m_State.fogColor.x.val.ToString(CultureInfo.InvariantCulture),
                                    m_State.fogColor.y.val.ToString(CultureInfo.InvariantCulture),
                                    m_State.fogColor.z.val.ToString(CultureInfo.InvariantCulture),
                                    m_State.fogColor.w.val.ToString(CultureInfo.InvariantCulture));
                }
                if (m_State.fogDensity.val != 0f)
                {
                    sb.Append($"   Density {m_State.fogDensity.val.ToString(CultureInfo.InvariantCulture)}\n");
                }
                if (m_State.fogStart.val != 0f ||
                    m_State.fogEnd.val != 0f)
                {
                    sb.Append($"   Range {m_State.fogStart.val.ToString(CultureInfo.InvariantCulture)}, {m_State.fogEnd.val.ToString(CultureInfo.InvariantCulture)}\n");
                }
                sb.Append("  }\n");
            }

            if (m_State.lighting)
            {
                sb.Append($"  Lighting {(m_State.lighting ? "On" : "Off")}\n");
            }

            sb.Append($"  GpuProgramID {m_State.gpuProgramID}\n");

            return(sb.ToString());
        }