Пример #1
0
        public static void SetMaterialPropertyUniforms(UniformBlock uniformBlock, Shader shader, Nud.Material mat)
        {
            // Skip expensive buffer updates for redundant value updates.
            if (mat.ShouldUpdateRendering)
            {
                foreach (var property in defaultValueByProperty)
                {
                    MatPropertyShaderUniform(uniformBlock, mat, property.Key, property.Value);
                }
                mat.ShouldUpdateRendering = false;
            }

            // Always bind the uniform block because each polygon has its own uniform block.
            uniformBlock.BindBlock(shader, "MaterialProperties");

            // Create some conditionals rather than using different shaders.
            var genericMaterial = new GenericMaterial();

            HasMatPropertyShaderUniform(genericMaterial, mat, "NU_softLightingParams", "hasSoftLight");
            HasMatPropertyShaderUniform(genericMaterial, mat, "NU_customSoftLightParams", "hasCustomSoftLight");
            HasMatPropertyShaderUniform(genericMaterial, mat, "NU_specularParams", "hasSpecularParams");
            HasMatPropertyShaderUniform(genericMaterial, mat, "NU_dualNormalScrollParams", "hasDualNormal");
            HasMatPropertyShaderUniform(genericMaterial, mat, "NU_normalSamplerAUV", "hasNrmSamplerAUV");
            HasMatPropertyShaderUniform(genericMaterial, mat, "NU_normalSamplerBUV", "hasNrmSamplerBUV");
            HasMatPropertyShaderUniform(genericMaterial, mat, "NU_finalColorGain", "hasFinalColorGain");
            HasMatPropertyShaderUniform(genericMaterial, mat, "NU_effUniverseParam", "hasUniverseParam");

            genericMaterial.SetShaderUniforms(shader);
        }
Пример #2
0
        public static void SetTextureUniformsNudMatSphere(Shader shader, Nud.Material mat, Dictionary <NudEnums.DummyTexture, Texture> dummyTextures)
        {
            SetHasTextureUniforms(shader, mat);
            SetRenderModeTextureUniforms(shader);

            // The material shader just uses predefined textures from the Resources folder.
            Nud.MatTexture diffuse     = new Nud.MatTexture((int)NudEnums.DummyTexture.DummyRamp);
            Nud.MatTexture cubeMapHigh = new Nud.MatTexture((int)NudEnums.DummyTexture.StageMapHigh);

            SetHasTextureUniforms(shader, mat);
            SetRenderModeTextureUniforms(shader);

            // The type of texture can be partially determined by texture order.
            GenericMaterial textures = new GenericMaterial(nutTextureUnitOffset);

            textures.AddTexture("dif", GetSphereTexture("dif", dummyTextures));
            textures.AddTexture("spheremap", GetSphereTexture("spheremap", dummyTextures));
            textures.AddTexture("dif2", GetSphereTexture("dif2", dummyTextures));
            textures.AddTexture("dif3", GetSphereTexture("dif3", dummyTextures));
            textures.AddTexture("stagecube", GetSphereTexture("stagecube", dummyTextures));
            textures.AddTexture("cube", GetSphereTexture("cube", dummyTextures));
            textures.AddTexture("ao", GetSphereTexture("ao", dummyTextures));
            textures.AddTexture("normalMap", GetSphereTexture("normalMap", dummyTextures));
            textures.AddTexture("ramp", GetSphereTexture("ramp", dummyTextures));
            textures.AddTexture("dummyRamp", GetSphereTexture("dummyRamp", dummyTextures));

            textures.SetShaderUniforms(shader);
        }
Пример #3
0
        public void SetMaterialUniforms(Shader shader, Material previousMaterial)
        {
            // TODO: This code could be moved to the constructor.
            if (genericMaterial == null || shouldUpdateTextures)
            {
                genericMaterial      = CreateGenericMaterial();
                shouldUpdateTextures = true;
            }

            if (uniformBlock == null)
            {
                uniformBlock = new UniformBlock(shader, "MaterialParams")
                {
                    BlockBinding = 1
                };
                SetMaterialParams(uniformBlock);
            }

            if (shouldUpdateUniformBlock)
            {
                SetMaterialParams(uniformBlock);
                shouldUpdateUniformBlock = false;
            }

            // This needs to be updated more than once.
            AddDebugParams(uniformBlock);

            // Update the uniform values.
            genericMaterial.SetShaderUniforms(shader, previousMaterial?.genericMaterial);
            uniformBlock.BindBlock(shader);
        }
Пример #4
0
        public void SetMaterialValues(NUD.Material nudMaterial, SFGraphics.GLObjects.Shaders.Shader shader)
        {
            var material = new GenericMaterial();

            NudUniforms.SetMaterialPropertyUniforms(material, nudMaterial);

            material.SetShaderUniforms(shader);
        }
Пример #5
0
        public static void SetTextureUniforms(Shader shader, Nud.Material mat, Dictionary <NudEnums.DummyTexture, Texture> dummyTextures)
        {
            SetHasTextureUniforms(shader, mat);
            SetRenderModeTextureUniforms(shader);

            int textureIndex = 0;

            // The type of texture can be partially determined by texture order.
            GenericMaterial textures = new GenericMaterial(nutTextureUnitOffset);

            textures.AddTexture("dif", GetTextureAndSetTexId(mat, mat.HasDiffuse, "dif", ref textureIndex, dummyTextures));
            textures.AddTexture("spheremap", GetTextureAndSetTexId(mat, mat.HasSphereMap, "spheremap", ref textureIndex, dummyTextures));
            textures.AddTexture("dif2", GetTextureAndSetTexId(mat, mat.HasDiffuse2, "dif2", ref textureIndex, dummyTextures));
            textures.AddTexture("dif3", GetTextureAndSetTexId(mat, mat.HasDiffuse3, "dif3", ref textureIndex, dummyTextures));
            textures.AddTexture("stagecube", GetTextureAndSetTexId(mat, mat.HasStageMap, "stagecube", ref textureIndex, dummyTextures));
            textures.AddTexture("cube", GetTextureAndSetTexId(mat, mat.HasCubeMap, "cube", ref textureIndex, dummyTextures));
            textures.AddTexture("ao", GetTextureAndSetTexId(mat, mat.HasAoMap, "ao", ref textureIndex, dummyTextures));
            textures.AddTexture("normalMap", GetTextureAndSetTexId(mat, mat.HasNormalMap, "normalMap", ref textureIndex, dummyTextures));
            textures.AddTexture("ramp", GetTextureAndSetTexId(mat, mat.HasRamp, "ramp", ref textureIndex, dummyTextures));
            textures.AddTexture("dummyRamp", GetTextureAndSetTexId(mat, mat.HasDummyRamp, "dummyRamp", ref textureIndex, dummyTextures));

            textures.SetShaderUniforms(shader);
        }
Пример #6
0
 private void SetMaterialUniforms(Shader shader, GenericMaterial material)
 {
     material.SetShaderUniforms(shader);
 }