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


C# ShadingState类代码示例

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


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

示例1: scatterPhoton

 public void scatterPhoton(ShadingState state, Color power)
 {
     Color diffuse;
     // make sure we are on the right side of the material
     if (Vector3.dot(state.getNormal(), state.getRay().getDirection()) > 0.0)
     {
         state.getNormal().negate();
         state.getGeoNormal().negate();
     }
     diffuse = getDiffuse(state);
     state.storePhoton(state.getRay().getDirection(), power, diffuse);
     float avg = diffuse.getAverage();
     double rnd = state.getRandom(0, 0, 1);
     if (rnd < avg)
     {
         // photon is scattered
         power.mul(diffuse).mul(1.0f / avg);
         OrthoNormalBasis onb = state.getBasis();
         double u = 2 * Math.PI * rnd / avg;
         double v = state.getRandom(0, 1, 1);
         float s = (float)Math.Sqrt(v);
         float s1 = (float)Math.Sqrt(1.0 - 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);
     }
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:27,代码来源:DiffuseShader.cs

示例2: prepareShadingState

        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Instance parent = state.getInstance();
            Point3 localPoint = parent.transformWorldToObject(state.getPoint());
            state.getNormal().set(localPoint.x, localPoint.y, localPoint.z);
            state.getNormal().normalize();

            float phi = (float)Math.Atan2(state.getNormal().y, state.getNormal().x);
            if (phi < 0)
                phi += (float)(2 * Math.PI);
            float theta = (float)Math.Acos(state.getNormal().z);
            state.getUV().y = theta / (float)Math.PI;
            state.getUV().x = phi / (float)(2 * Math.PI);
            Vector3 v = new Vector3();
            v.x = -2 * (float)Math.PI * state.getNormal().y;
            v.y = 2 * (float)Math.PI * state.getNormal().x;
            v.z = 0;
            state.setShader(parent.getShader(0));
            state.setModifier(parent.getModifier(0));
            // into world space
            Vector3 worldNormal = parent.transformNormalObjectToWorld(state.getNormal());
            v = parent.transformVectorObjectToWorld(v);
            state.getNormal().set(worldNormal);
            state.getNormal().normalize();
            state.getGeoNormal().set(state.getNormal());
            // compute basis in world space
            state.setBasis(OrthoNormalBasis.makeFromWV(state.getNormal(), v));
        }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:30,代码来源:Sphere.cs

示例3: getRadiance

 public Color getRadiance(ShadingState state)
 {
     // don't use these - gather lights for sphere of directions
     // gather lights
     state.initLightSamples();
     state.initCausticSamples();
     Vector3 v = state.getRay().getDirection();
     v.negate();
     Vector3 h = new Vector3();
     Vector3 t = state.getBasis().transform(new Vector3(0, 1, 0));
     Color diff = Color.black();
     Color spec = Color.black();
     foreach (LightSample ls in state)
     {
         Vector3 l = ls.getShadowRay().getDirection();
         float dotTL = Vector3.dot(t, l);
         float sinTL = (float)Math.Sqrt(1 - dotTL * dotTL);
         // float dotVL = Vector3.dot(v, l);
         diff.madd(sinTL, ls.getDiffuseRadiance());
         Vector3.add(v, l, h);
         h.normalize();
         float dotTH = Vector3.dot(t, h);
         float sinTH = (float)Math.Sqrt(1 - dotTH * dotTH);
         float s = (float)Math.Pow(sinTH, 10.0f);
         spec.madd(s, ls.getSpecularRadiance());
     }
     Color c = Color.add(diff, spec, new Color());
     // transparency
     return Color.blend(c, state.traceTransparency(), state.getV(), new Color());
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:30,代码来源:Hair.cs

示例4: getSamples

 public void getSamples(ShadingState state)
 {
     if (Vector3.dot(dir, state.getGeoNormal()) < 0 && Vector3.dot(dir, state.getNormal()) < 0)
     {
         // project point onto source plane
         float x = state.getPoint().x - src.x;
         float y = state.getPoint().y - src.y;
         float z = state.getPoint().z - src.z;
         float t = ((x * dir.x) + (y * dir.y) + (z * dir.z));
         if (t >= 0.0)
         {
             x -= (t * dir.x);
             y -= (t * dir.y);
             z -= (t * dir.z);
             if (((x * x) + (y * y) + (z * z)) <= r2)
             {
                 Point3 p = new Point3();
                 p.x = src.x + x;
                 p.y = src.y + y;
                 p.z = src.z + z;
                 LightSample dest = new LightSample();
                 dest.setShadowRay(new Ray(state.getPoint(), p));
                 dest.setRadiance(radiance, radiance);
                 dest.traceShadow(state);
                 state.addSample(dest);
             }
         }
     }
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:29,代码来源:DirectionalSpotlight.cs

示例5: getSamples

        public void getSamples(ShadingState state)
        {
            if (samples == null)
            {
                int n = state.getDiffuseDepth() > 0 ? 1 : numSamples;
                for (int i = 0; i < n; i++)
                {
                    // random offset on unit square, we use the infinite version of
                    // getRandom because the light sampling is adaptive
                    double randX = state.getRandom(i, 0, n);
                    double randY = state.getRandom(i, 1, n);
                    int x = 0;
                    while (randX >= colHistogram[x] && x < colHistogram.Length - 1)
                        x++;
                    float[] rowHistogram = imageHistogram[x];
                    int y = 0;
                    while (randY >= rowHistogram[y] && y < rowHistogram.Length - 1)
                        y++;
                    // sample from (x, y)
                    float u = (float)((x == 0) ? (randX / colHistogram[0]) : ((randX - colHistogram[x - 1]) / (colHistogram[x] - colHistogram[x - 1])));
                    float v = (float)((y == 0) ? (randY / rowHistogram[0]) : ((randY - rowHistogram[y - 1]) / (rowHistogram[y] - rowHistogram[y - 1])));

                    float px = ((x == 0) ? colHistogram[0] : (colHistogram[x] - colHistogram[x - 1]));
                    float py = ((y == 0) ? rowHistogram[0] : (rowHistogram[y] - rowHistogram[y - 1]));

                    float su = (x + u) / colHistogram.Length;
                    float sv = (y + v) / rowHistogram.Length;
                    float invP = (float)Math.Sin(sv * Math.PI) * jacobian / (n * px * py);
                    Vector3 dir = getDirection(su, sv);
                    basis.transform(dir);
                    if (Vector3.dot(dir, state.getGeoNormal()) > 0)
                    {
                        LightSample dest = new LightSample();
                        dest.setShadowRay(new Ray(state.getPoint(), dir));
                        dest.getShadowRay().setMax(float.MaxValue);
                        Color radiance = texture.getPixel(su, sv);
                        dest.setRadiance(radiance, radiance);
                        dest.getDiffuseRadiance().mul(invP);
                        dest.getSpecularRadiance().mul(invP);
                        dest.traceShadow(state);
                        state.addSample(dest);
                    }
                }
            }
            else
            {
                for (int i = 0; i < numSamples; i++)
                {
                    if (Vector3.dot(samples[i], state.getGeoNormal()) > 0 && Vector3.dot(samples[i], state.getNormal()) > 0)
                    {
                        LightSample dest = new LightSample();
                        dest.setShadowRay(new Ray(state.getPoint(), samples[i]));
                        dest.getShadowRay().setMax(float.MaxValue);
                        dest.setRadiance(colors[i], colors[i]);
                        dest.traceShadow(state);
                        state.addSample(dest);
                    }
                }
            }
        }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:60,代码来源:ImageBasedLight.cs

示例6: 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,代码来源:

示例7: getIrradiance

 public Color getIrradiance(ShadingState state, Color diffuseReflectance)
 {
     if (samples <= 0)
         return Color.BLACK;
     // compute new sample
     Color irr = Color.black();
     OrthoNormalBasis onb = state.getBasis();
     Vector3 w = new Vector3();
     int n = state.getDiffuseDepth() == 0 ? samples : 1;
     for (int i = 0; i < n; i++)
     {
         float xi = (float)state.getRandom(i, 0, n);
         float xj = (float)state.getRandom(i, 1, n);
         float phi = (float)(xi * 2 * Math.PI);
         float cosPhi = (float)Math.Cos(phi);
         float sinPhi = (float)Math.Sin(phi);
         float sinTheta = (float)Math.Sqrt(xj);
         float cosTheta = (float)Math.Sqrt(1.0f - xj);
         w.x = cosPhi * sinTheta;
         w.y = sinPhi * sinTheta;
         w.z = cosTheta;
         onb.transform(w);
         ShadingState temp = state.traceFinalGather(new Ray(state.getPoint(), w), i);
         if (temp != null)
         {
             temp.getInstance().prepareShadingState(temp);
             if (temp.getShader() != null)
                 irr.add(temp.getShader().getRadiance(temp));
         }
     }
     irr.mul((float)Math.PI / n);
     return irr;
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:33,代码来源:PathTracingGIEngine.cs

示例8: getRadiance

 public Color getRadiance(ShadingState state)
 {
     Point3[] p = new Point3[3];
     if (!state.getTrianglePoints(p))
         return getFillColor(state);
     // transform points into camera space
     Point3 center = state.getPoint();
     Matrix4 w2c = state.getWorldToCamera();
     center = w2c.transformP(center);
     for (int i = 0; i < 3; i++)
         p[i] = w2c.transformP(state.getInstance().transformObjectToWorld(p[i]));
     float cn = 1.0f / (float)Math.Sqrt(center.x * center.x + center.y * center.y + center.z * center.z);
     for (int i = 0, i2 = 2; i < 3; i2 = i, i++)
     {
         // compute orthogonal projection of the shading point onto each
         // triangle edge as in:
         // http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
         float t = (center.x - p[i].x) * (p[i2].x - p[i].x);
         t += (center.y - p[i].y) * (p[i2].y - p[i].y);
         t += (center.z - p[i].z) * (p[i2].z - p[i].z);
         t /= p[i].distanceToSquared(p[i2]);
         float projx = (1 - t) * p[i].x + t * p[i2].x;
         float projy = (1 - t) * p[i].y + t * p[i2].y;
         float projz = (1 - t) * p[i].z + t * p[i2].z;
         float n = 1.0f / (float)Math.Sqrt(projx * projx + projy * projy + projz * projz);
         // check angular width
         float dot = projx * center.x + projy * center.y + projz * center.z;
         if (dot * n * cn >= cosWidth)
             return getLineColor(state);
     }
     return getFillColor(state);
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:32,代码来源:WireframeShader.cs

示例9: 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

示例10: ScatterPhoton

 public void ScatterPhoton(ShadingState state, Color power)
 {
     Color diffuse, specular;
     // make sure we are on the right side of the material
     state.faceforward();
     diffuse = getDiffuse(state);
     specular = getSpecular(state);
     state.storePhoton(state.getRay().getDirection(), power, diffuse);
     float d = diffuse.getAverage();
     float r = specular.getAverage();
     double rnd = state.getRandom(0, 0, 1);
     if (rnd < d)
     {
         // photon is scattered
         power.mul(diffuse).mul(1.0f / d);
         OrthoNormalBasis onb = state.getBasis();
         double u = 2 * Math.PI * rnd / d;
         double v = state.getRandom(0, 1, 1);
         float s = (float)Math.Sqrt(v);
         float s1 = (float)Math.Sqrt(1.0 - 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 < d + r)
     {
         if (glossyness == 0)
         {
             float cos = -Vector3.dot(state.getNormal(), state.getRay().getDirection());
             power.mul(diffuse).mul(1.0f / d);
             // 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);
         }
         else
         {
             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 / r);
             OrthoNormalBasis onb = state.getBasis();
             double u = 2 * Math.PI * (rnd - r) / r;
             double v = state.getRandom(0, 1, 1);
             float s = (float)Math.Pow(v, 1 / ((1.0f / glossyness) + 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:,项目名称:,代码行数:58,代码来源:

示例11: getSamples

        public void getSamples(ShadingState state)
        {
            if (getNumSamples() <= 0)
                return;
            Vector3 wc = Point3.sub(center, state.getPoint(), new Vector3());
            float l2 = wc.LengthSquared();
            if (l2 <= r2)
                return; // inside the sphere?
            // top of the sphere as viewed from the current shading point
            float topX = wc.x + state.getNormal().x * radius;
            float topY = wc.y + state.getNormal().y * radius;
            float topZ = wc.z + state.getNormal().z * radius;
            if (state.getNormal().dot(topX, topY, topZ) <= 0)
                return; // top of the sphere is below the horizon
            float cosThetaMax = (float)Math.Sqrt(Math.Max(0, 1 - r2 / Vector3.dot(wc, wc)));
            OrthoNormalBasis basis = OrthoNormalBasis.makeFromW(wc);
            int samples = state.getDiffuseDepth() > 0 ? 1 : getNumSamples();
            float scale = (float)(2 * Math.PI * (1 - cosThetaMax));
            Color c = Color.mul(scale / samples, radiance);
            for (int i = 0; i < samples; i++)
            {
                // random offset on unit square
                double randX = state.getRandom(i, 0, samples);
                double randY = state.getRandom(i, 1, samples);

                // cone sampling
                double cosTheta = (1 - randX) * cosThetaMax + randX;
                double sinTheta = Math.Sqrt(1 - cosTheta * cosTheta);
                double phi = randY * 2 * Math.PI;
                Vector3 dir = new Vector3((float)(Math.Cos(phi) * sinTheta), (float)(Math.Sin(phi) * sinTheta), (float)cosTheta);
                basis.transform(dir);

                // check that the direction of the sample is the same as the
                // normal
                float cosNx = Vector3.dot(dir, state.getNormal());
                if (cosNx <= 0)
                    continue;

                float ocx = state.getPoint().x - center.x;
                float ocy = state.getPoint().y - center.y;
                float ocz = state.getPoint().z - center.z;
                float qa = Vector3.dot(dir, dir);
                float qb = 2 * ((dir.x * ocx) + (dir.y * ocy) + (dir.z * ocz));
                float qc = ((ocx * ocx) + (ocy * ocy) + (ocz * ocz)) - r2;
                double[] t = Solvers.solveQuadric(qa, qb, qc);
                if (t == null)
                    continue;
                LightSample dest = new LightSample();
                // compute shadow ray to the sampled point
                dest.setShadowRay(new Ray(state.getPoint(), dir));
                // FIXME: arbitrary bias, should handle as in other places
                dest.getShadowRay().setMax((float)t[0] - 1e-3f);
                // prepare sample
                dest.setRadiance(c, c);
                dest.traceShadow(state);
                state.addSample(dest);
            }
        }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:58,代码来源:SphereLight.cs

示例12: 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

示例13: 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

示例14: getIrradiance

 public Color getIrradiance(ShadingState state, Color diffuseReflectance)
 {
     float cosTheta = Vector3.dot(up, state.getNormal());
     float sin2 = (1 - cosTheta * cosTheta);
     float sine = sin2 > 0 ? (float)Math.Sqrt(sin2) * 0.5f : 0;
     if (cosTheta > 0)
         return Color.blend(sky, ground, sine);
     else
         return Color.blend(ground, sky, sine);
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:10,代码来源:FakeGIEngine.cs

示例15: 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


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