当前位置: 首页>>代码示例>>C#>>正文


C# ShadingState.faceforward方法代码示例

本文整理汇总了C#中ShadingState.faceforward方法的典型用法代码示例。如果您正苦于以下问题:C# ShadingState.faceforward方法的具体用法?C# ShadingState.faceforward怎么用?C# ShadingState.faceforward使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ShadingState的用法示例。


在下文中一共展示了ShadingState.faceforward方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetRadiance

        public Color GetRadiance(ShadingState state)
        {
            // make sure we are on the right side of the material
            state.faceforward();
            // direct lighting
            state.initLightSamples();
            state.initCausticSamples();
            Color d = getDiffuse(state);
            Color lr = state.diffuse(d);
            if (!state.includeSpecular)
                return lr;
            if (glossyness == 0)
            {
                float cos = state.getCosND();
                float dn = 2 * cos;
                Vector3 refDir = new Vector3();
                refDir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x;
                refDir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y;
                refDir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z;
                Ray refRay = new Ray(state.getPoint(), refDir);
                // compute Fresnel term
                cos = 1 - cos;
                float cos2 = cos * cos;
                float cos5 = cos2 * cos2 * cos;

                Color spec = getSpecular(state);
                Color ret = Color.white();
                ret.sub(spec);
                ret.mul(cos5);
                ret.add(spec);
                return lr.add(ret.mul(state.traceReflection(refRay, 0)));
            }
            else
                return lr.add(state.specularPhong(getSpecular(state), 2 / glossyness, numSamples));
        }
开发者ID:,项目名称:,代码行数:35,代码来源:

示例2: getRadiance

 public Color getRadiance(ShadingState state)
 {
     if (!state.includeLights)
         return Color.BLACK;
     state.faceforward();
     // emit constant radiance
     return state.isBehind() ? Color.BLACK : radiance;
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:8,代码来源:TriangleMeshLight.cs

示例3: getRadiance

 public Color getRadiance(ShadingState state)
 {
     // make sure we are on the right side of the material
     state.faceforward();
     // setup lighting
     state.initLightSamples();
     state.initCausticSamples();
     return state.diffuse(getDiffuse(state));
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:9,代码来源:DiffuseShader.cs

示例4: getRadiance

 public Color getRadiance(ShadingState state)
 {
     state.faceforward();
     state.initCausticSamples();
     // integrate a diffuse function
     Color lr = Color.black();
     foreach (LightSample sample in state)
         lr.madd(sample.dot(state.getNormal()), sample.getDiffuseRadiance());
     return lr.mul(1.0f / (float)Math.PI);
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:10,代码来源:ViewCausticsShader.cs

示例5: getRadiance

 public Color getRadiance(ShadingState state)
 {
     // make sure we are on the right side of the material
     state.faceforward();
     // setup lighting
     state.initLightSamples();
     state.initCausticSamples();
     // execute shader
     return state.diffuse(getDiffuse(state)).add(state.specularPhong(spec, power, numRays));
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:10,代码来源:PhongShader.cs

示例6: ScatterPhoton

 public void ScatterPhoton(ShadingState state, Color power)
 {
     float avg = color.getAverage();
     double rnd = state.getRandom(0, 0, 1);
     if (rnd >= avg)
         return;
     state.faceforward();
     float cos = state.getCosND();
     power.mul(color).mul(1.0f / avg);
     // photon is reflected
     float dn = 2 * cos;
     Vector3 dir = new Vector3();
     dir.x = (dn * state.getNormal().x) + state.getRay().getDirection().x;
     dir.y = (dn * state.getNormal().y) + state.getRay().getDirection().y;
     dir.z = (dn * state.getNormal().z) + state.getRay().getDirection().z;
     state.traceReflectionPhoton(new Ray(state.getPoint(), dir), power);
 }
开发者ID:,项目名称:,代码行数:17,代码来源:

示例7: scatterPhoton

 public void scatterPhoton(ShadingState state, Color power)
 {
     // make sure we are on the right side of the material
     state.faceforward();
     Color d = getDiffuse(state);
     state.storePhoton(state.getRay().getDirection(), power, d);
     float avgD = d.getAverage();
     float avgS = spec.getAverage();
     double rnd = state.getRandom(0, 0, 1);
     if (rnd < avgD)
     {
         // photon is scattered diffusely
         power.mul(d).mul(1.0f / avgD);
         OrthoNormalBasis onb = state.getBasis();
         double u = 2 * Math.PI * rnd / avgD;
         double v = state.getRandom(0, 1, 1);
         float s = (float)Math.Sqrt(v);
         float s1 = (float)Math.Sqrt(1.0f - v);
         Vector3 w = new Vector3((float)Math.Cos(u) * s, (float)Math.Sin(u) * s, s1);
         w = onb.transform(w, new Vector3());
         state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
     }
     else if (rnd < avgD + avgS)
     {
         // photon is scattered specularly
         float dn = 2.0f * state.getCosND();
         // reflected direction
         Vector3 refDir = new Vector3();
         refDir.x = (dn * state.getNormal().x) + state.getRay().dx;
         refDir.y = (dn * state.getNormal().y) + state.getRay().dy;
         refDir.z = (dn * state.getNormal().z) + state.getRay().dz;
         power.mul(spec).mul(1.0f / avgS);
         OrthoNormalBasis onb = state.getBasis();
         double u = 2 * Math.PI * (rnd - avgD) / avgS;
         double v = state.getRandom(0, 1, 1);
         float s = (float)Math.Pow(v, 1 / (this.power + 1));
         float s1 = (float)Math.Sqrt(1 - s * s);
         Vector3 w = new Vector3((float)Math.Cos(u) * s1, (float)Math.Sin(u) * s1, s);
         w = onb.transform(w, new Vector3());
         state.traceReflectionPhoton(new Ray(state.getPoint(), w), power);
     }
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:42,代码来源:PhongShader.cs

示例8: getRadiance

        public Color getRadiance(ShadingState state)
        {
            // make sure we are on the right side of the material
            state.faceforward();
            OrthoNormalBasis onb = state.getBasis();
            // direct lighting and caustics
            state.initLightSamples();
            state.initCausticSamples();
            Color lr = Color.black();
            // compute specular contribution
            if (state.includeSpecular)
            {
                Vector3 inv = state.getRay().getDirection().negate(new Vector3());
                foreach (LightSample sample in state)
                {
                    float cosNL = sample.dot(state.getNormal());
                    float fr = brdf(inv, sample.getShadowRay().getDirection(), onb);
                    lr.madd(cosNL * fr, sample.getSpecularRadiance());
                }

                // indirect lighting - specular
                if (numRays > 0)
                {
                    int n = state.getDepth() == 0 ? numRays : 1;
                    for (int i = 0; i < n; i++)
                    {
                        // specular indirect lighting
                        double r1 = state.getRandom(i, 0, n);
                        double r2 = state.getRandom(i, 1, n);

                        float alphaRatio = alphaY / alphaX;
                        float phi = 0;
                        if (r1 < 0.25)
                        {
                            double val = 4 * r1;
                            phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val));
                        }
                        else if (r1 < 0.5)
                        {
                            double val = 1 - 4 * (0.5 - r1);
                            phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val));
                            phi = (float)Math.PI - phi;
                        }
                        else if (r1 < 0.75)
                        {
                            double val = 4 * (r1 - 0.5);
                            phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val));
                            phi += (float)Math.PI;
                        }
                        else
                        {
                            double val = 1 - 4 * (1 - r1);
                            phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val));
                            phi = 2 * (float)Math.PI - phi;
                        }

                        float cosPhi = (float)Math.Cos(phi);
                        float sinPhi = (float)Math.Sin(phi);

                        float denom = (cosPhi * cosPhi) / (alphaX * alphaX) + (sinPhi * sinPhi) / (alphaY * alphaY);
                        float theta = (float)Math.Atan(Math.Sqrt(-Math.Log(1 - r2) / denom));

                        float sinTheta = (float)Math.Sin(theta);
                        float cosTheta = (float)Math.Cos(theta);

                        Vector3 h = new Vector3();
                        h.x = sinTheta * cosPhi;
                        h.y = sinTheta * sinPhi;
                        h.z = cosTheta;
                        onb.transform(h);

                        Vector3 o = new Vector3();
                        float ih = Vector3.dot(h, inv);
                        o.x = 2 * ih * h.x - inv.x;
                        o.y = 2 * ih * h.y - inv.y;
                        o.z = 2 * ih * h.z - inv.z;

                        float no = onb.untransformZ(o);
                        float ni = onb.untransformZ(inv);
                        float w = ih * cosTheta * cosTheta * cosTheta * (float)Math.Sqrt(Math.Abs(no / ni));

                        Ray r = new Ray(state.getPoint(), o);
                        lr.madd(w / n, state.traceGlossy(r, i));
                    }
                }
                lr.mul(rhoS);
            }
            // add diffuse contribution
            lr.add(state.diffuse(getDiffuse(state)));
            return lr;
        }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:91,代码来源:AnisotropicWardShader.cs

示例9: scatterPhoton

        public void scatterPhoton(ShadingState state, Color power)
        {
            // make sure we are on the right side of the material
            state.faceforward();
            Color d = getDiffuse(state);
            state.storePhoton(state.getRay().getDirection(), power, d);
            float avgD = d.getAverage();
            float avgS = rhoS.getAverage();
            double rnd = state.getRandom(0, 0, 1);
            if (rnd < avgD)
            {
                // photon is scattered diffusely
                power.mul(d).mul(1.0f / avgD);
                OrthoNormalBasis onb = state.getBasis();
                double u = 2 * Math.PI * rnd / avgD;
                double v = state.getRandom(0, 1, 1);
                float s = (float)Math.Sqrt(v);
                float s1 = (float)Math.Sqrt(1.0f - v);
                Vector3 w = new Vector3((float)Math.Cos(u) * s, (float)Math.Sin(u) * s, s1);
                w = onb.transform(w, new Vector3());
                state.traceDiffusePhoton(new Ray(state.getPoint(), w), power);
            }
            else if (rnd < avgD + avgS)
            {
                // photon is scattered specularly
                power.mul(rhoS).mul(1 / avgS);
                OrthoNormalBasis basis = state.getBasis();
                Vector3 inv = state.getRay().getDirection().negate(new Vector3());
                double r1 = rnd / avgS;
                double r2 = state.getRandom(0, 1, 1);

                float alphaRatio = alphaY / alphaX;
                float phi = 0;
                if (r1 < 0.25)
                {
                    double val = 4 * r1;
                    phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val));
                }
                else if (r1 < 0.5)
                {
                    double val = 1 - 4 * (0.5 - r1);
                    phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val));
                    phi = (float)Math.PI - phi;
                }
                else if (r1 < 0.75)
                {
                    double val = 4 * (r1 - 0.5);
                    phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val));
                    phi += (float)Math.PI;
                }
                else
                {
                    double val = 1 - 4 * (1 - r1);
                    phi = (float)Math.Atan(alphaRatio * Math.Tan(Math.PI / 2 * val));
                    phi = 2 * (float)Math.PI - phi;
                }

                float cosPhi = (float)Math.Cos(phi);
                float sinPhi = (float)Math.Sin(phi);

                float denom = (cosPhi * cosPhi) / (alphaX * alphaX) + (sinPhi * sinPhi) / (alphaY * alphaY);
                float theta = (float)Math.Atan(Math.Sqrt(-Math.Log(1 - r2) / denom));

                float sinTheta = (float)Math.Sin(theta);
                float cosTheta = (float)Math.Cos(theta);

                Vector3 h = new Vector3();
                h.x = sinTheta * cosPhi;
                h.y = sinTheta * sinPhi;
                h.z = cosTheta;
                basis.transform(h);

                Vector3 o = new Vector3();
                float ih = Vector3.dot(h, inv);
                o.x = 2 * ih * h.x - inv.x;
                o.y = 2 * ih * h.y - inv.y;
                o.z = 2 * ih * h.z - inv.z;

                Ray r = new Ray(state.getPoint(), o);
                state.traceReflectionPhoton(r, power);
            }
        }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:82,代码来源:AnisotropicWardShader.cs

示例10: store

 public void store(ShadingState state, Vector3 dir, Color power, Color diffuse)
 {
     state.faceforward();
     PointLight vpl = new PointLight();
     vpl.p = state.getPoint();
     vpl.n = state.getNormal();
     vpl.power = power;
     lock (lockObj)
     {
         virtualLights.Add(vpl);
     }
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:12,代码来源:InstantGI.cs

示例11: getRadiance

 public Color getRadiance(ShadingState state)
 {
     state.faceforward();
     return state.getGlobalRadiance();
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:5,代码来源:ViewGlobalPhotonsShader.cs


注:本文中的ShadingState.faceforward方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。