コード例 #1
0
        private void SetTextureUniforms(Shader shader, GenericMaterial previousMaterial)
        {
            int textureIndex = InitialTextureUnit;

            for (int i = 0; i < textureUniformNames.Count; i++)
            {
                var name  = textureUniformNames[i];
                var value = textureValues[i];

                // If the same texture is bound to this texture unit, we don't need to set it again.
                bool shouldSkipTextureSet = previousMaterial != null &&
                                            i < previousMaterial.textureUniformNames.Count &&
                                            previousMaterial.textureUniformNames[i] == name &&
                                            previousMaterial.textureValues[i] == value;

                if (!shouldSkipTextureSet)
                {
                    shader.SetTexture(name, value, textureIndex);
                }

                // Even if the textures are the same, the bound sampler may be different.
                if (samplerValues[i] != null)
                {
                    samplerValues[i].Bind(textureIndex);
                }

                textureIndex++;
            }
        }
コード例 #2
0
ファイル: RMesh.cs プロジェクト: Struggleton/SSBHLib
        public void SetMaterialUniforms(Shader shader, GenericMaterial previousMaterial)
        {
            // TODO: Rework default texture creation.
            if (defaultTextures == null)
            {
                defaultTextures = new Resources.DefaultTextures();
            }

            if (genericMaterial == null)
            {
                genericMaterial = Material.CreateGenericMaterial();
            }
            genericMaterial.SetShaderUniforms(shader, previousMaterial);

            if (uniformBlock == null)
            {
                uniformBlock = new UniformBlock(shader, "MaterialParams")
                {
                    BlockBinding = 1
                };
                Material.AddMaterialParams(uniformBlock);
            }
            // This needs to be updated more than once.
            Material.AddDebugParams(uniformBlock);

            uniformBlock.BindBlock(shader);
        }
コード例 #3
0
 /// <summary>
 /// Sets uniform values for all the added uniform values.
 /// Redundant setting of texture uniform is skipped to improve performance.
 /// </summary>
 /// <param name="shader">The shader whose uniforms will be set</param>
 /// <param name="previousMaterial">The previous material used to set this shader's uniforms</param>
 public void SetShaderUniforms(Shader shader, GenericMaterial previousMaterial = null)
 {
     SetIntUniforms(shader);
     SetFloatUniforms(shader);
     SetVec2Uniforms(shader);
     SetVec3Uniforms(shader);
     SetVec4Uniforms(shader);
     SetMat4Uniforms(shader);
     SetTextureUniforms(shader, previousMaterial);
 }