예제 #1
0
        void IGeneratesFunction.GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
        {
            registry.RequiresIncludePath("Packages/com.unity.render-pipelines.core/ShaderLibrary/Hashes.hlsl");

            var hashType       = this.hashType;
            var hashTypeString = hashType.ToString();
            var HashFunction   = kHashFunctionPrefix[(int)hashType];

            registry.ProvideFunction($"Unity_GradientNoise_{hashTypeString}_Dir_$precision", s =>
            {
                s.AppendLine($"$precision2 Unity_GradientNoise_{hashTypeString}_Dir_$precision($precision2 p)");
                using (s.BlockScope())
                {
                    s.AppendLine($"$precision x; {HashFunction}$precision(p, x);");
                    s.AppendLine("return normalize($precision2(x - floor(x + 0.5), abs(x) - 0.5));");
                }
            });

            registry.ProvideFunction($"Unity_GradientNoise_{hashTypeString}_$precision", s =>
            {
                s.AppendLine($"void Unity_GradientNoise_{hashTypeString}_$precision ($precision2 UV, $precision3 Scale, out $precision Out)");
                using (s.BlockScope())
                {
                    s.AppendLine("$precision2 p = UV * Scale;");
                    s.AppendLine("$precision2 ip = floor(p);");
                    s.AppendLine("$precision2 fp = frac(p);");
                    s.AppendLine($"$precision d00 = dot(Unity_GradientNoise_{hashTypeString}_Dir_$precision(ip), fp);");
                    s.AppendLine($"$precision d01 = dot(Unity_GradientNoise_{hashTypeString}_Dir_$precision(ip + $precision2(0, 1)), fp - $precision2(0, 1));");
                    s.AppendLine($"$precision d10 = dot(Unity_GradientNoise_{hashTypeString}_Dir_$precision(ip + $precision2(1, 0)), fp - $precision2(1, 0));");
                    s.AppendLine($"$precision d11 = dot(Unity_GradientNoise_{hashTypeString}_Dir_$precision(ip + $precision2(1, 1)), fp - $precision2(1, 1));");
                    s.AppendLine("fp = fp * fp * fp * (fp * (fp * 6 - 15) + 10);");
                    s.AppendLine("Out = lerp(lerp(d00, d01, fp.y), lerp(d10, d11, fp.y), fp.x) + 0.5;");
                }
            });
        }
예제 #2
0
        void IGeneratesFunction.GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
        {
            registry.RequiresIncludePath("Packages/com.unity.render-pipelines.core/ShaderLibrary/Hashes.hlsl");

            var hashType       = this.hashType;
            var hashTypeString = hashType.ToString();
            var HashFunction   = kHashFunctionPrefix[(int)hashType];

            registry.ProvideFunction($"Unity_SimpleNoise_ValueNoise_{hashTypeString}_$precision", s =>
            {
                s.AppendLine($"$precision Unity_SimpleNoise_ValueNoise_{hashTypeString}_$precision ($precision2 uv)");
                using (s.BlockScope())
                {
                    s.AppendLine("$precision2 i = floor(uv);");
                    s.AppendLine("$precision2 f = frac(uv);");
                    s.AppendLine("f = f * f * (3.0 - 2.0 * f);");
                    s.AppendLine("uv = abs(frac(uv) - 0.5);");
                    s.AppendLine("$precision2 c0 = i + $precision2(0.0, 0.0);");
                    s.AppendLine("$precision2 c1 = i + $precision2(1.0, 0.0);");
                    s.AppendLine("$precision2 c2 = i + $precision2(0.0, 1.0);");
                    s.AppendLine("$precision2 c3 = i + $precision2(1.0, 1.0);");
                    s.AppendLine($"$precision r0; {HashFunction}$precision(c0, r0);");
                    s.AppendLine($"$precision r1; {HashFunction}$precision(c1, r1);");
                    s.AppendLine($"$precision r2; {HashFunction}$precision(c2, r2);");
                    s.AppendLine($"$precision r3; {HashFunction}$precision(c3, r3);");
                    s.AppendLine("$precision bottomOfGrid = lerp(r0, r1, f.x);");
                    s.AppendLine("$precision topOfGrid = lerp(r2, r3, f.x);");
                    s.AppendLine("$precision t = lerp(bottomOfGrid, topOfGrid, f.y);");
                    s.AppendLine("return t;");
                }
            });

            registry.ProvideFunction($"Unity_SimpleNoise_" + hashTypeString + "_$precision", s =>
            {
                s.AppendLine($"void Unity_SimpleNoise_{hashTypeString}_$precision($precision2 UV, $precision Scale, out $precision Out)");
                using (s.BlockScope())
                {
                    s.AppendLine("$precision freq, amp;");
                    s.AppendLine("Out = 0.0f;");
                    for (int octave = 0; octave < 3; octave++)
                    {
                        s.AppendLine($"freq = pow(2.0, $precision({octave}));");
                        s.AppendLine($"amp = pow(0.5, $precision(3-{octave}));");
                        s.AppendLine($"Out += Unity_SimpleNoise_ValueNoise_{hashTypeString}_$precision($precision2(UV.xy*(Scale/freq)))*amp;");
                    }
                }
            });
        }
예제 #3
0
        void IGeneratesFunction.GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
        {
            registry.RequiresIncludePath("Packages/com.unity.render-pipelines.core/ShaderLibrary/Hashes.hlsl");

            var hashType       = this.hashType;
            var hashTypeString = hashType.ToString();
            var HashFunction   = kHashFunctionPrefix[(int)hashType];

            registry.ProvideFunction($"Unity_Voronoi_RandomVector_{hashTypeString}_$precision", s =>
            {
                s.AppendLine($"$precision2 Unity_Voronoi_RandomVector_{hashTypeString}_$precision ($precision2 UV, $precision offset)");
                using (s.BlockScope())
                {
                    s.AppendLine($"{HashFunction}$precision(UV, UV);");
                    s.AppendLine("return $precision2(sin(UV.y * offset), cos(UV.x * offset)) * 0.5 + 0.5;");
                }
            });

            registry.ProvideFunction($"Unity_Voronoi_{hashTypeString}_$precision", s =>
            {
                s.AppendLine($"void Unity_Voronoi_{hashTypeString}_$precision($precision2 UV, $precision AngleOffset, $precision CellDensity, out $precision Out, out $precision Cells)");
                using (s.BlockScope())
                {
                    s.AppendLine("$precision2 g = floor(UV * CellDensity);");
                    s.AppendLine("$precision2 f = frac(UV * CellDensity);");
                    s.AppendLine("$precision t = 8.0;");
                    s.AppendLine("$precision3 res = $precision3(8.0, 0.0, 0.0);");
                    s.AppendLine("for (int y = -1; y <= 1; y++)");
                    using (s.BlockScope())
                    {
                        s.AppendLine("for (int x = -1; x <= 1; x++)");
                        using (s.BlockScope())
                        {
                            s.AppendLine("$precision2 lattice = $precision2(x, y);");
                            s.AppendLine($"$precision2 offset = Unity_Voronoi_RandomVector_{hashTypeString}_$precision(lattice + g, AngleOffset);");
                            s.AppendLine("$precision d = distance(lattice + offset, f);");
                            s.AppendLine("if (d < res.x)");
                            using (s.BlockScope())
                            {
                                s.AppendLine("res = $precision3(d, offset.x, offset.y);");
                                s.AppendLine("Out = res.x;");
                                s.AppendLine("Cells = res.y;");
                            }
                        }
                    }
                }
            });
        }
예제 #4
0
 public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode)
 {
     registry.RequiresIncludePath("Packages/com.unity.render-pipelines.core/ShaderLibrary/ParallaxMapping.hlsl");
 }