Esempio n. 1
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);
        }
Esempio n. 2
0
        private static void RenderPresetsToFiles()
        {
            using (GameWindow gameWindow = OpenTkSharedResources.CreateGameWindowContext(width, height))
            {
                // Resource creation.
                screenTriangle = ScreenDrawing.CreateScreenTriangle();
                shader         = OpenTkSharedResources.shaders["NudSphere"];

                // Skip thumbnail generation if the shader didn't compile.
                if (!shader.LinkStatusIsOk)
                {
                    return;
                }

                // HACK: This isn't a very clean way to pass resources around.
                NudMatSphereDrawing.LoadMaterialSphereTextures();
                Dictionary <NudEnums.DummyTexture, Texture> dummyTextures = RenderTools.CreateNudDummyTextures();

                CreateNudSphereShader();

                foreach (string file in Directory.EnumerateFiles(MainForm.executableDir + "\\materials", "*.nmt", SearchOption.AllDirectories))
                {
                    Nud.Material material   = NudMaterialEditor.ReadMaterialListFromPreset(file)[0];
                    string       presetName = Path.GetFileNameWithoutExtension(file);
                    RenderMaterialPresetToFile(presetName, material, dummyTextures);
                }
            }
        }
Esempio n. 3
0
        private static void MatPropertyShaderUniform(UniformBlock uniformBlock, Nud.Material mat, string propertyName,
                                                     Vector4 defaultValue)
        {
            // Attempt to get the values from the material.
            var newValues = GetValues(mat, propertyName, defaultValue);

            string uniformName = propertyName.Replace("NU_", "");

            uniformBlock.SetValue(uniformName, new Vector4(newValues[0], newValues[1], newValues[2], newValues[3]));
        }
Esempio n. 4
0
 public static void SetHasTextureUniforms(Shader shader, Nud.Material mat)
 {
     shader.SetBoolToInt("hasDif", mat.HasDiffuse);
     shader.SetBoolToInt("hasDif2", mat.HasDiffuse2);
     shader.SetBoolToInt("hasDif3", mat.HasDiffuse3);
     shader.SetBoolToInt("hasStage", mat.HasStageMap);
     shader.SetBoolToInt("hasCube", mat.HasCubeMap);
     shader.SetBoolToInt("hasAo", mat.HasAoMap);
     shader.SetBoolToInt("hasNrm", mat.HasNormalMap);
     shader.SetBoolToInt("hasRamp", mat.HasRamp);
     shader.SetBoolToInt("hasDummyRamp", mat.HasDummyRamp);
     shader.SetBoolToInt("hasColorGainOffset", mat.UseColorGainOffset);
     shader.SetBoolToInt("useDiffuseBlend", mat.UseDiffuseBlend);
     shader.SetBoolToInt("hasSphereMap", mat.HasSphereMap);
     shader.SetBoolToInt("hasBayoHair", mat.HasBayoHair);
     shader.SetBoolToInt("useDifRefMask", mat.UseReflectionMask);
     shader.SetBoolToInt("softLightBrighten", mat.SoftLightBrighten);
 }
Esempio n. 5
0
        public static void DrawNudMaterialSphere(Shader shader, Nud.Material material, Mesh3D screenTriangle, Dictionary <NudEnums.DummyTexture, Texture> dummyTextures)
        {
            if (!shader.LinkStatusIsOk)
            {
                return;
            }

            shader.UseProgram();

            // Use the same uniforms as the NUD shader.
            var uniformBlock = new UniformBlock(shader, "MaterialProperties")
            {
                BlockBinding = 1
            };

            NudUniforms.SetMaterialPropertyUniforms(uniformBlock, shader, material);

            Nud.SetStageLightingUniforms(shader, 0);
            ModelContainer.SetRenderSettingsUniforms(shader);

            ModelContainer.SetLightingUniforms(shader, nudSphereCamera);
            ModelContainer.SetCameraMatrixUniforms(nudSphereCamera, shader);

            // Use default textures rather than textures from the NUT.
            NudUniforms.SetTextureUniformsNudMatSphere(shader, material, dummyTextures);

            // These values aren't needed in the shader currently.
            shader.SetVector3("cameraPosition", 0, 0, 0);
            shader.SetFloat("zBufferOffset", 0);
            shader.SetFloat("bloomThreshold", Runtime.bloomThreshold);

            bool isTransparent = (material.SrcFactor > 0) || (material.DstFactor > 0) || (material.AlphaFunction > 0) || (material.AlphaTest > 0);

            shader.SetBoolToInt("isTransparent", isTransparent);

            // Set texture uniforms for the mesh attributes.
            shader.SetTexture("normalTex", sphereNrmTex, 15);
            shader.SetTexture("uvTex", sphereUvTex, 16);
            shader.SetTexture("tanTex", sphereTanTex, 17);
            shader.SetTexture("bitanTex", sphereBitanTex, 18);

            // Draw full screen "quad" (big triangle)
            ScreenDrawing.DrawScreenTriangle(shader, screenTriangle);
        }
Esempio n. 6
0
        private static void RenderMaterialPresetToFile(string presetName, Nud.Material material, Dictionary <NudEnums.DummyTexture, Texture> dummyTextures)
        {
            // Setup new dimensions.
            GL.Viewport(0, 0, width, height);

            Framebuffer framebuffer = new Framebuffer(FramebufferTarget.Framebuffer, width, height, PixelInternalFormat.Rgba);

            framebuffer.Bind();

            // Draw the material to a textured quad.
            NudMatSphereDrawing.DrawNudMaterialSphere(shader, material, screenTriangle, dummyTextures);

            // Save output.
            using (Bitmap image = framebuffer.ReadImagePixels(true))
            {
                string outputPath = String.Format("{0}\\Preview Images\\{1}.png", MainForm.executableDir, presetName);
                image.Save(outputPath);
            }
        }
Esempio n. 7
0
        private static float[] GetValues(Nud.Material mat, string propertyName, Vector4 defaultValue)
        {
            float[] values = null;

            if (mat.HasPropertyAnim(propertyName))
            {
                values = mat.GetPropertyValuesAnim(propertyName);
            }
            else if (mat.HasProperty(propertyName))
            {
                values = mat.GetPropertyValues(propertyName);
            }

            if (values == null || values.Length != 4)
            {
                values = new float[] { defaultValue.X, defaultValue.Y, defaultValue.Z, defaultValue.W }
            }
            ;

            return(values);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        public static Texture GetTextureAndSetTexId(Nud.Material mat, bool hasTex, string name, ref int textureIndex, Dictionary <NudEnums.DummyTexture, Texture> dummyTextures)
        {
            Texture texture;

            if (hasTex && textureIndex < mat.textures.Count)
            {
                // We won't know what type a texture is used for until we iterate through the textures.
                texture = GetTexture(mat.textures[textureIndex].hash, mat.textures[textureIndex], textureIndex, dummyTextures);
                textureIndex++;
            }
            else
            {
                if (name.ToLower().Contains("cube"))
                {
                    texture = dummyTextures[NudEnums.DummyTexture.StageMapHigh];
                }
                else
                {
                    texture = RenderTools.defaultTex;
                }
            }

            return(texture);
        }
Esempio n. 10
0
        private static void HasMatPropertyShaderUniform(GenericMaterial genericMaterial, Nud.Material mat, string propertyName, string uniformName)
        {
            bool hasValue = mat.HasProperty(propertyName) || mat.HasPropertyAnim(propertyName);

            if (hasValue)
            {
                genericMaterial.AddInt(uniformName, 1);
            }
            else
            {
                genericMaterial.AddInt(uniformName, 0);
            }
        }
Esempio n. 11
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);
        }