Esempio n. 1
0
        public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
        {
            // We may need ConvertEvToLuminance() so we include CommonLighting.hlsl
            registry.RequiresIncludePath("Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl");

            registry.ProvideFunction(GetFunctionName(), s =>
            {
                s.AppendLine("$precision3 {0}($precision3 ldrColor, {1} luminanceIntensity, {1} exposureWeight)",
                             GetFunctionName(),
                             intensitySlot.concreteValueType.ToShaderString());
                using (s.BlockScope())
                {
                    if (normalizeColor.isOn)
                    {
                        s.AppendLine("ldrColor = ldrColor * rcp(max(Luminance(ldrColor), 1e-6));");
                    }
                    s.AppendLine("$precision3 hdrColor = ldrColor * luminanceIntensity;");
                    s.AppendNewLine();
                    s.AppendLine("#ifdef SHADERGRAPH_PREVIEW");
                    s.AppendLine($"$precision inverseExposureMultiplier = 1.0;");
                    s.AppendLine("#else");
                    s.AppendLine($"$precision inverseExposureMultiplier = GetInverseCurrentExposureMultiplier();");
                    s.AppendLine("#endif");
                    s.AppendNewLine();

                    s.AppendLine("// Inverse pre-expose using _EmissiveExposureWeight weight");
                    s.AppendLine("hdrColor = lerp(hdrColor * inverseExposureMultiplier, hdrColor, exposureWeight);");
                    s.AppendLine("return hdrColor;");
                }
            });
        }
Esempio n. 2
0
        public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
        {
            registry.RequiresIncludePath("Packages/com.unity.render-pipelines.core/ShaderLibrary/BSDF.hlsl");

            string resultType = GetResultType();

            registry.ProvideFunction(GetFunctionName(), s =>
            {
                if (m_FresnelEquationMode == FresnelEquationMode.Schlick)
                {
                    s.AppendLine("void {0}(out {1} FresnelValue, $precision cos0, {1} f0)", GetFunctionName(), resultType, resultType);
                }
                else if (m_FresnelEquationMode == FresnelEquationMode.Dielectric)
                {
                    s.AppendLine("void {0}(out {1} FresnelValue, $precision cos0, {2} iorSource, {3} iorMedium)",
                                 GetFunctionName(),
                                 resultType,
                                 iorSourceInputSlot.concreteValueType.ToShaderString(),
                                 iorMediumInputSlot.concreteValueType.ToShaderString());
                }
                else //if (m_FresnelEquationMode == FresnelEquationMode.DielectricGeneric)
                {
                    s.AppendLine("void {0}(out {1} FresnelValue, $precision cos0, {2} iorSource, {3} iorMedium, {4} iorMediumK)",
                                 GetFunctionName(),
                                 resultType,
                                 iorSourceInputSlot.concreteValueType.ToShaderString(),
                                 iorMediumInputSlot.concreteValueType.ToShaderString(),
                                 iorMediumKInputSlot.concreteValueType.ToShaderString());
                }
                using (s.BlockScope())
                {
                    if (m_FresnelEquationMode == FresnelEquationMode.Schlick)
                    {
                        s.AppendLine("FresnelValue = F_Schlick(f0, cos0);");
                    }
                    else if (m_FresnelEquationMode == FresnelEquationMode.Dielectric)
                    {
                        s.AppendLine("FresnelValue = F_FresnelDielectric(iorMedium/iorSource, cos0);");
                    }
                    else //if (m_FresnelEquationMode == FresnelEquationMode.DielectricGeneric)
                    {
                        s.AppendLine("FresnelValue = F_FresnelConductor(iorMedium/iorSource, iorMediumK/iorSource, cos0);");
                    }
                }
            });
        }
Esempio n. 3
0
        public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
        {
            registry.RequiresIncludePath("Packages/com.unity.render-pipelines.core/ShaderLibrary/BSDF.hlsl");

            registry.ProvideFunction(GetFunctionName(), s =>
            {
                s.AppendLine("void {0}(out $precision3 Refracted, out $precision3 Intensity, $precision3 Incident, $precision3 Normal, $precision IORSource, $precision IORMedium)", GetFunctionName());
                using (s.BlockScope())
                {
                    s.AppendLine("$precision internalIORSource = max(IORSource, 1.0);");
                    s.AppendLine("$precision internalIORMedium = max(IORMedium, 1.0);");
                    s.AppendLine("$precision eta = internalIORSource/internalIORMedium;");
                    s.AppendLine("$precision cos0 = dot(Incident, Normal);");
                    s.AppendLine("$precision k = 1.0 - eta*eta*(1.0 - cos0*cos0);");
                    if (m_RefractMode == RefractMode.Safe)
                    {
                        s.AppendLine("Refracted = eta*Incident - (eta*cos0 + sqrt(max(k, 0.0)))*Normal;");
                    }
                    else
                    {
                        s.AppendLine("Refracted = k >= 0.0 ? eta*Incident - (eta*cos0 + sqrt(k))*Normal : reflect(Incident, Normal);");
                    }
                    s.AppendLine("Intensity = internalIORSource <= internalIORMedium ?");
                    s.AppendLine("    saturate(F_Transm_Schlick(IorToFresnel0(internalIORMedium, internalIORSource), -cos0)) :");
                    s.AppendLine("    (k >= 0.0 ? F_FresnelDielectric(internalIORMedium/internalIORSource, -cos0) : ");
                    if (m_RefractMode == RefractMode.Safe)
                    {
                        s.Append("0.0);");
                    }
                    else
                    {
                        s.Append("1.0);");
                    }
                }
            });
        }