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


C# ShadingState.getPoint方法代码示例

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


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

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

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

示例3: getSamples

 public void getSamples(ShadingState state)
 {
     Vector3 d = Point3.sub(lightPoint, state.getPoint(), new Vector3());
     if (Vector3.dot(d, state.getNormal()) > 0 && Vector3.dot(d, state.getGeoNormal()) > 0)
     {
         LightSample dest = new LightSample();
         // prepare shadow ray
         dest.setShadowRay(new Ray(state.getPoint(), lightPoint));
         float scale = 1.0f / (float)(4 * Math.PI * lightPoint.distanceToSquared(state.getPoint()));
         dest.setRadiance(power, power);
         dest.getDiffuseRadiance().mul(scale);
         dest.getSpecularRadiance().mul(scale);
         dest.traceShadow(state);
         state.addSample(dest);
     }
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:16,代码来源:PointLight.cs

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

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

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

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

示例8: prepareShadingState

 public void prepareShadingState(ShadingState state)
 {
     state.init();
     state.getRay().getPoint(state.getPoint());
     Instance parent = state.getInstance();
     Point3 n = parent.transformWorldToObject(state.getPoint());
     state.getNormal().set(n.x * (2 * n.x * n.x - 1), n.y * (2 * n.y * n.y - 1), n.z * (2 * n.z * n.z - 1));
     state.getNormal().normalize();
     state.setShader(parent.getShader(0));
     state.setModifier(parent.getModifier(0));
     // into world space
     Vector3 worldNormal = parent.transformNormalObjectToWorld(state.getNormal());
     state.getNormal().set(worldNormal);
     state.getNormal().normalize();
     state.getGeoNormal().set(state.getNormal());
     // create basis in world space
     state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:18,代码来源:BanchoffSurface.cs

示例9: getGlobalRadiance

 public Color getGlobalRadiance(ShadingState state)
 {
     if (globalPhotonMap == null)
     {
         if (state.getShader() != null)
             return state.getShader().getRadiance(state);
         else
             return Color.BLACK;
     }
     else
         return globalPhotonMap.getRadiance(state.getPoint(), state.getNormal());
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:12,代码来源:IrradianceCacheGIEngine.cs

示例10: prepareShadingState

        public void prepareShadingState(ShadingState state)
        {
            state.init();
            state.getRay().getPoint(state.getPoint());
            Point3 localPoint = state.transformWorldToObject(state.getPoint());

            localPoint.x -= particles[3 * state.getPrimitiveID() + 0];
            localPoint.y -= particles[3 * state.getPrimitiveID() + 1];
            localPoint.z -= particles[3 * state.getPrimitiveID() + 2];

            state.getNormal().set(localPoint.x, localPoint.y, localPoint.z);
            state.getNormal().normalize();

            state.setShader(state.getInstance().getShader(0));
            state.setModifier(state.getInstance().getModifier(0));
            // into object space
            Vector3 worldNormal = state.transformNormalObjectToWorld(state.getNormal());
            state.getNormal().set(worldNormal);
            state.getNormal().normalize();
            state.getGeoNormal().set(state.getNormal());
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
        }
开发者ID:,项目名称:,代码行数:22,代码来源:

示例11: getSamples

 public void getSamples(ShadingState state)
 {
     if (storedPhotons == 0)
         return;
     NearestPhotons np = new NearestPhotons(state.getPoint(), gatherNum, gatherRadius * gatherRadius);
     locatePhotons(np);
     if (np.found < 8)
         return;
     Point3 ppos = new Point3();
     Vector3 pdir = new Vector3();
     Vector3 pvec = new Vector3();
     float invArea = 1.0f / ((float)Math.PI * np.dist2[0]);
     float maxNDist = np.dist2[0] * 0.05f;
     float f2r2 = 1.0f / (filterValue * filterValue * np.dist2[0]);
     float fInv = 1.0f / (1.0f - 2.0f / (3.0f * filterValue));
     for (int i = 1; i <= np.found; i++)
     {
         Photon phot = np.index[i];
         Vector3.decode(phot.dir, pdir);
         float cos = -Vector3.dot(pdir, state.getNormal());
         if (cos > 0.001)
         {
             ppos.set(phot.x, phot.y, phot.z);
             Point3.sub(ppos, state.getPoint(), pvec);
             float pcos = Vector3.dot(pvec, state.getNormal());
             if ((pcos < maxNDist) && (pcos > -maxNDist))
             {
                 LightSample sample = new LightSample();
                 sample.setShadowRay(new Ray(state.getPoint(), pdir.negate()));
                 sample.setRadiance(new Color().setRGBE(np.index[i].power).mul(invArea / cos), Color.BLACK);
                 sample.getDiffuseRadiance().mul((1.0f - (float)Math.Sqrt(np.dist2[i] * f2r2)) * fInv);
                 state.addSample(sample);
             }
         }
     }
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:36,代码来源:CausticPhotonMap.cs

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

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

示例14: modify

        public void modify(ShadingState state)
        {
            Point3 p = state.transformWorldToObject(state.getPoint());
            p.x *= size;
            p.y *= size;
            p.z *= size;
            Vector3 normal = state.transformNormalWorldToObject(state.getNormal());
            double f0 = f(p.x, p.y, p.z);
            double fx = f(p.x + .0001, p.y, p.z);
            double fy = f(p.x, p.y + .0001, p.z);
            double fz = f(p.x, p.y, p.z + .0001);

            normal.x -= scale * (float)((fx - f0) / .0001);
            normal.y -= scale * (float)((fy - f0) / .0001);
            normal.z -= scale * (float)((fz - f0) / .0001);
            normal.normalize();

            state.getNormal().set(state.transformNormalObjectToWorld(normal));
            state.getNormal().normalize();
            state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
        }
开发者ID:,项目名称:,代码行数:21,代码来源:

示例15: getGlobalRadiance

 public Color getGlobalRadiance(ShadingState state)
 {
     Point3 p = state.getPoint();
     Vector3 n = state.getNormal();
     int set = (int)(state.getRandom(0, 1, 1) * numSets);
     float maxAvgPow = 0;
     float minDist = 1;
     Color pow = null;
     foreach (PointLight vpl in virtualLights[set])
     {
         maxAvgPow = Math.Max(maxAvgPow, vpl.power.getAverage());
         if (Vector3.dot(n, vpl.n) > 0.9f)
         {
             float d = vpl.p.distanceToSquared(p);
             if (d < minDist)
             {
                 pow = vpl.power;
                 minDist = d;
             }
         }
     }
     return pow == null ? Color.BLACK : pow.copy().mul(1.0f / maxAvgPow);
 }
开发者ID:rzel,项目名称:sunflowsharp,代码行数:23,代码来源:InstantGI.cs


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