コード例 #1
0
        public void Update(
            Matrix transformation,
            Color4 color,
            string texturePath,
            BlendMode blendMode = BlendMode.Blend,
            ShadingType shading = ShadingType.Constant,
            IReadOnlyCollection <Matrix> instanceTransformations = null,
            IReadOnlyCollection <Color4> instanceColors          = null)
        {
            Transformation = transformation;
            Color          = color;
            TexturePath    = texturePath;
            Blending       = blendMode;
            Shading        = shading;
            Space          = TransformationSpace.World; //always set default, can be changed by Within node

            if (instanceColors == null || instanceColors.Count == 0)
            {
                instanceColors = White;
            }

            if (instanceTransformations == null || instanceTransformations.Count == 0)
            {
                instanceTransformations = Identity;
            }

            InstanceTransformations = instanceTransformations;
            InstanceColors          = instanceColors;
            InstanceCount           = Math.Max(Math.Max(instanceTransformations.Count, instanceColors.Count), 1);
        }
コード例 #2
0
 public DrawGeometryDescription(GeometryDescriptor geometryDescriptor,
                                Matrix transformation,
                                Color4 color,
                                string texturePath,
                                BlendMode blendMode,
                                ShadingType shading,
                                IReadOnlyCollection <Matrix> instanceTransformations,
                                IReadOnlyCollection <Color4> instanceColors)
     : this(geometryDescriptor)
 {
     Update(transformation, color, texturePath, blendMode, shading, instanceTransformations, instanceColors);
 }
コード例 #3
0
 public static Shader GetShader(ShadingType stype)
 {
     if (ShaderDict == null)
     {
         ShaderDict = new Dictionary <ShadingType, Shader>();
         ShaderDict[ShadingType.Flat2D]       = new Shader(Resources.VertShader2DFlat, Resources.FragShaderFlat);
         ShaderDict[ShadingType.MultiColor2D] = new Shader(Resources.VertShader2DColor, Resources.FragShaderColor);
         ShaderDict[ShadingType.Textured3D]   = new Shader(Resources.VertShader3DText, Resources.FragShaderText);
         ShaderDict[ShadingType.Flat3D]       = new Shader(Resources.VertShader3DFlat, Resources.FragShaderFlat);
         ShaderDict[ShadingType.Wire3D]       = new Shader(Resources.VertShader3DWire, Resources.FragShaderWire);
         ShaderDict[ShadingType.FlatNorm3D]   = new Shader(Resources.VertShader3DNorm, Resources.FragShaderNorm);
         ShaderDict[ShadingType.Line3D]       = new Shader(Resources.VertShader3DLine, Resources.FragShaderLine);
         ShaderDict[ShadingType.Textured2D]   = new Shader(Resources.VertShader2DText, Resources.FragShaderText);
     }
     return(ShaderDict[stype]);
 }
コード例 #4
0
ファイル: Shader.cs プロジェクト: TomCrypto/AntTweakBar.NET
        /// <summary>
        /// Gets the fragment shader.
        /// </summary>
        public static String FragShader(Polynomial poly, ShadingType type, AAQuality aa, bool hardcodePoly, int iterations, float threshold)
        {
            var shader = String.Join("\n", new[]
            {
                "#version 120\n",
                "/* DO NOT EDIT - AUTOGENERATED */\n",
                FragArithmetic(),
                FragPolyRoots(poly, "poly", hardcodePoly),
                FragPolyRoots(Polynomial.Derivative(poly), "derv", hardcodePoly),
                FragIterate(iterations, threshold),
                FragColorize(type),
                FragShade(iterations),
                FragMainSampler(aa)
            });

            WriteToFile("shader.fs", shader);

            return shader;
        }
コード例 #5
0
ファイル: Shader.cs プロジェクト: TomCrypto/AntTweakBar.NET
        private static String FragColorize(ShadingType type)
        {
            var str = new StringBuilder();

            str.AppendLine("uniform vec4 palette;");
            str.AppendLine();
            str.AppendLine("vec3 colorize(vec2 z, vec2 r, float speed, float t)");
            str.AppendLine("{");

            switch (type)
            {
                case ShadingType.Standard:
                    str.AppendLine("    speed *= speed * 0.05;");
                    str.AppendLine("    vec3 retval = (sin(vec3(r.x) * palette.xyz) + sin(vec3(r.y) * palette.xyz) + 2) * speed;");
                    str.AppendLine("    return retval / (retval + vec3(1));");
                    break;
                case ShadingType.Negative:
                    str.AppendLine("    if (speed == 0) return vec3(1);");
                    str.AppendLine("    vec3 retval = (sin(vec3(r.x) * palette.xyz) + sin(vec3(r.y) * palette.xyz) + 2) / speed;");
                    str.AppendLine("    return retval / (retval + vec3(1));");
                    break;
                case ShadingType.Flat:
                    str.AppendLine("    return (sin(vec3(r.x) * palette.xyz) + sin(vec3(r.y) * palette.xyz) + 2) * t * 2;");
                    break;
                default:
                    str.AppendLine("    return vec3(0.87, 0, 1);");
                    break;
            }

            str.AppendLine("}");

            return str.ToString();
        }
コード例 #6
0
        public Color Shade(Material material, SamplerBase sampler, Ray ray, RayCastHit hit)
        {
            if (hit.depth > m_PathTracer.tracingTimes)
            {
                if (material.IsEmissive() && m_PathTracer.sampleDirectLight && ray.isDiffuseRay)
                {
                    return(Color.black);
                }
                return(material.GetEmissive(hit));
            }
            if (material.IsEmissive())
            {
                if (m_PathTracer.sampleDirectLight && hit.depth != 0 && ray.isDiffuseRay)
                {
                    return(Color.black);
                }
                return(material.GetEmissive(hit));
            }

            float   refractive  = material.GetRefractive(hit);
            float   metallic    = material.GetMetallic(hit);
            float   roughness   = material.GetRoughness(hit);
            float   opacity     = material.GetOpacity(hit);
            Color   albedo      = material.GetAlbedo(hit);
            Vector3 worldNormal = material.GetWorldNormal(hit);

            float ndv = (float)Math.Max(0.0f, Vector3.Dot(worldNormal, -1.0 * ray.direction));

            if (hit.isBackFace)
            {
                refractive = 1.0f / refractive;
            }

            float F0 = (1.0f - refractive) / (1.0f + refractive);

            F0 = F0 * F0;
            if (F0 > 0.04f)
            {
                F0 = 0.04f;
            }
            Color F0Col = Color.Lerp(new Color(F0, F0, F0), albedo, metallic);

            Color fresnel = Fresnel.FresnelSchlick(ndv, F0Col, roughness);

            float fl = fresnel.Average();

            ShadingType shadingType = ShadingType.Reflect;

            double russianRoulette = sampler.GetRandom();

            if (fl > russianRoulette)
            {
                shadingType = ShadingType.Reflect;
            }
            else if (fl + (1.0f - fl) * (1.0f - opacity) > russianRoulette)
            {
                shadingType = ShadingType.Refract;
            }
            else
            {
                shadingType = ShadingType.Diffuse;
            }

            if (shadingType == ShadingType.Diffuse)
            {
                if (1.0f - metallic < float.Epsilon)
                {
                    return(Color.black);
                }

                if (albedo.IsCloseToZero())
                {
                    return(Color.black);
                }

                Vector3 sp  = sampler.SampleHemiSphere();
                Vector3 wi  = Vector3.ONB(worldNormal, sp);
                float   pdf = (float)(sp.z / Math.PI);

                double ndl = Vector3.Dot(worldNormal, wi);

                if (ndl <= 0.0)
                {
                    return(Color.black);
                }

                float brdf = (roughness < float.Epsilon ? m_LambertaianBRDF : m_DisneyDiffuseBRDF).SampleBRDF(sampler, ray.direction * -1.0, wi, hit.hit, worldNormal, roughness);

                if (brdf < float.Epsilon)
                {
                    return(Color.black);
                }

                Ray diffuseRay = new Ray(hit.hit, wi, true);

                Color L = m_PathTracer.PathTracing(diffuseRay, sampler, hit.depth + 1);

                return(albedo * L * brdf * (1.0f - metallic) * (float)ndl / pdf);
            }
            if (shadingType == ShadingType.Reflect)
            {
                if (albedo.IsCloseToZero())
                {
                    return(Color.black);
                }

                Vector3 sp       = sampler.SampleHemiSphere(roughness);
                Vector3 spnormal = Vector3.ONB(worldNormal, sp);
                Vector3 wo       = ray.direction * -1.0;
                Vector3 wi       = Vector3.Reflect(wo, spnormal);
                float   pdf      = (float)(sp.z / Math.PI);

                double ndl = Vector3.Dot(worldNormal, wi);

                if (ndl <= 0.0)
                {
                    return(Color.black);
                }

                float brdf = m_CookTorranceBRDF.SampleBRDF(sampler, wo, wi, hit.hit, worldNormal, roughness);

                if (brdf < float.Epsilon)
                {
                    return(Color.black);
                }

                Ray specularRay = new Ray(hit.hit, wi, false);

                Color L = m_PathTracer.PathTracing(specularRay, sampler, hit.depth + 1);

                return(Color.Lerp(Color.white, fresnel, metallic) * L * brdf * (float)ndl / pdf);
            }
            if (shadingType == ShadingType.Refract)
            {
            }
            return(Color.black);

            //MaterialProperty property;

            //property.worldNormal = material.GetWorldNormal(hit);
            //property.opacity = material.GetOpacity(hit);
            //property.metallic = material.GetMetallic(hit);
            //property.roughness = material.GetRoughness(hit);
            //property.albedo = material.GetAlbedo(hit);

            //if (m_PathTracer.sampleDirectLight)
            //    result += ShadeDirectLights(property, sampler, ray, hit);

            //result += material.GetOcclusion(hit) * ShadeAmbientLight(property, sampler, ray, hit);

            //return result + material.GetEmissive(hit);
        }
コード例 #7
0
ファイル: Fractal.cs プロジェクト: TomCrypto/AntTweakBar.NET
        private void SetupOptions()
        {
            zoom = 2.4f;
            offset = Vector2.Zero;
            iterations = 128;
            aCoeff = Complex.One;
            kCoeff = Complex.Zero;
            aa = AAQuality.AAx1;
            hardcodePolynomial = true;

            intensity = 1;
            threshold = 3;
            palette = Color4.Red;
            shading = ShadingType.Standard;

            polynomial = Polynomial.Parse(DefaultPolynomial, new Dictionary<String, Double>());
        }
コード例 #8
0
ファイル: PdfShading.cs プロジェクト: Daoting/dt
 /// <summary>
 /// Initializes a new instance of the <see cref="T:PdfShading" /> class.
 /// </summary>
 /// <param name="type">The type.</param>
 protected PdfShading(ShadingType type)
 {
     this.type = type;
 }