Inheritance: IDisposable
Ejemplo n.º 1
0
        /// <summary>
        /// Calculate the shader selector value based on the original shader ID, the render batch and general
        /// information from the model.
        /// </summary>
        /// <param name="baseShaderID">The original shader ID. Typically 0.</param>
        /// <param name="renderBatch">The render batch to which the ID belongs.</param>
        /// <param name="model">The model to which the batch belongs.</param>
        /// <returns>A new shader selector value.</returns>
        public static ushort GetRuntimeShaderID(ushort baseShaderID, MDXRenderBatch renderBatch, Warcraft.MDX.MDX model)
        {
            // The shader ID is already "modernized", so there's nothing to do.
            if ((baseShaderID & 0x8000) > 0)
            {
                return(baseShaderID);
            }

            var operationCount = renderBatch.TextureCount;
            var material       = model.Materials[renderBatch.MaterialIndex];

            ushort newShaderID = 0;

            if (!model.GlobalModelFlags.HasFlag(ModelObjectFlags.HasBlendModeOverrides))
            {
                var  textureMapping        = model.TextureMappingLookupTable[renderBatch.TextureMappingLookupTableIndex];
                bool isEnvMapped           = textureMapping == EMDXTextureMappingType.Environment;
                bool nonOpaqueBlendingMode = material.BlendMode != BlendingMode.Opaque;

                if (nonOpaqueBlendingMode)
                {
                    newShaderID = 1;
                    if (isEnvMapped)
                    {
                        newShaderID |= 8;
                    }
                }

                newShaderID *= 16;

                if (textureMapping == EMDXTextureMappingType.T2)
                {
                    newShaderID |= 0x4000;
                }

                return(newShaderID);
            }

            if (operationCount == 0)
            {
                return(baseShaderID);
            }

            var v19 = new short[] { 0, 0 };

            for (int opIndex = 0; opIndex < operationCount; ++opIndex)
            {
                int blendingOverrideIndex = baseShaderID + opIndex;
                var blendingOverride      = model.BlendMapOverrides[blendingOverrideIndex];

                if (opIndex == 0 && material.BlendMode == BlendingMode.Opaque)
                {
                    blendingOverride = BlendingMode.Opaque;
                }

                int textureMappingOverrideIndex            = renderBatch.TextureMappingLookupTableIndex + opIndex;
                EMDXTextureMappingType textureSlotOverride = model.TextureMappingLookupTable[textureMappingOverrideIndex];
                bool isEnvMapped = textureSlotOverride == EMDXTextureMappingType.Environment;

                if (isEnvMapped)
                {
                    v19[opIndex] = (short)((short)blendingOverride | 8);
                }
                else
                {
                    v19[opIndex] = (short)blendingOverride;
                }

                if (textureSlotOverride == EMDXTextureMappingType.Environment && (opIndex + 1) == operationCount)
                {
                    newShaderID |= 0x4000;
                }
            }

            newShaderID |= (ushort)(v19[1] | (v19[0] * 16));

            return(newShaderID);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculate the shader selector value based on the original shader ID, the render batch and general
        /// information from the model.
        /// </summary>
        /// <param name="baseShaderID">The original shader ID. Typically 0.</param>
        /// <param name="renderBatch">The render batch to which the ID belongs.</param>
        /// <param name="model">The model to which the batch belongs.</param>
        /// <returns>A new shader selector value.</returns>
        public static ushort GetRuntimeShaderID(ushort baseShaderID, MDXRenderBatch renderBatch, Warcraft.MDX.MDX model)
        {
            // The shader ID is already "modernized", so there's nothing to do.
            if ((baseShaderID & 0x8000) > 0)
            {
                return(baseShaderID);
            }

            var operationCount = renderBatch.TextureCount;
            var material       = model.Materials ![renderBatch.MaterialIndex];