本文整理汇总了C#中ShadingState.getRay方法的典型用法代码示例。如果您正苦于以下问题:C# ShadingState.getRay方法的具体用法?C# ShadingState.getRay怎么用?C# ShadingState.getRay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShadingState
的用法示例。
在下文中一共展示了ShadingState.getRay方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
示例2: 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);
}
}
示例3: 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));
}
示例4: 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());
}
示例5: 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);
}
示例6: 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);
}
}
示例7: 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()));
}
示例8: 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()));
}
示例9: getRadiance
public Color getRadiance(ShadingState state)
{
return new Color(Math.Abs(state.getRay().dot(state.getNormal())));
}
示例10: getRadiance
public Color getRadiance(ShadingState state)
{
Vector3 n = state.getNormal();
float f = n == null ? 1.0f : Math.Abs(state.getRay().dot(n));
return BORDERS[state.getPrimitiveID() % BORDERS.Length].copy().mul(f);
}
示例11: getRadiance
public Color getRadiance(ShadingState state)
{
return getSkyRGB(basis.untransform(state.getRay().getDirection())).constrainRGB();
}
示例12: 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);
}
}
示例13: prepareShadingState
public void prepareShadingState(ShadingState state)
{
state.init();
Instance parent = state.getInstance();
int primID = state.getPrimitiveID();
float u = state.getU();
float v = state.getV();
float w = 1 - u - v;
state.getRay().getPoint(state.getPoint());
int tri = 3 * primID;
int index0 = triangles[tri + 0];
int index1 = triangles[tri + 1];
int index2 = triangles[tri + 2];
Point3 v0p = getPoint(index0);
Point3 v1p = getPoint(index1);
Point3 v2p = getPoint(index2);
Vector3 ng = Point3.normal(v0p, v1p, v2p);
ng = parent.transformNormalObjectToWorld(ng);
ng.normalize();
state.getGeoNormal().set(ng);
switch (normals.interp)
{
case ParameterList.InterpolationType.NONE:
case ParameterList.InterpolationType.FACE:
{
state.getNormal().set(ng);
break;
}
case ParameterList.InterpolationType.VERTEX:
{
int i30 = 3 * index0;
int i31 = 3 * index1;
int i32 = 3 * index2;
float[] normals1 = this.normals.data;
state.getNormal().x = w * normals1[i30 + 0] + u * normals1[i31 + 0] + v * normals1[i32 + 0];
state.getNormal().y = w * normals1[i30 + 1] + u * normals1[i31 + 1] + v * normals1[i32 + 1];
state.getNormal().z = w * normals1[i30 + 2] + u * normals1[i31 + 2] + v * normals1[i32 + 2];
state.getNormal().set(parent.transformNormalObjectToWorld(state.getNormal()));
state.getNormal().normalize();
break;
}
case ParameterList.InterpolationType.FACEVARYING:
{
int idx = 3 * tri;
float[] normals1 = this.normals.data;
state.getNormal().x = w * normals1[idx + 0] + u * normals1[idx + 3] + v * normals1[idx + 6];
state.getNormal().y = w * normals1[idx + 1] + u * normals1[idx + 4] + v * normals1[idx + 7];
state.getNormal().z = w * normals1[idx + 2] + u * normals1[idx + 5] + v * normals1[idx + 8];
state.getNormal().set(parent.transformNormalObjectToWorld(state.getNormal()));
state.getNormal().normalize();
break;
}
}
float uv00 = 0, uv01 = 0, uv10 = 0, uv11 = 0, uv20 = 0, uv21 = 0;
switch (uvs.interp)
{
case ParameterList.InterpolationType.NONE:
case ParameterList.InterpolationType.FACE:
{
state.getUV().x = 0;
state.getUV().y = 0;
break;
}
case ParameterList.InterpolationType.VERTEX:
{
int i20 = 2 * index0;
int i21 = 2 * index1;
int i22 = 2 * index2;
float[] uvs1 = this.uvs.data;
uv00 = uvs1[i20 + 0];
uv01 = uvs1[i20 + 1];
uv10 = uvs1[i21 + 0];
uv11 = uvs1[i21 + 1];
uv20 = uvs1[i22 + 0];
uv21 = uvs1[i22 + 1];
break;
}
case ParameterList.InterpolationType.FACEVARYING:
{
int idx = tri << 1;
float[] uvs1 = this.uvs.data;
uv00 = uvs1[idx + 0];
uv01 = uvs1[idx + 1];
uv10 = uvs1[idx + 2];
uv11 = uvs1[idx + 3];
uv20 = uvs1[idx + 4];
uv21 = uvs1[idx + 5];
break;
}
}
if (uvs.interp != ParameterList.InterpolationType.NONE)
{
// get exact uv coords and compute tangent vectors
state.getUV().x = w * uv00 + u * uv10 + v * uv20;
state.getUV().y = w * uv01 + u * uv11 + v * uv21;
float du1 = uv00 - uv20;
float du2 = uv10 - uv20;
float dv1 = uv01 - uv21;
float dv2 = uv11 - uv21;
Vector3 dp1 = Point3.sub(v0p, v2p, new Vector3()), dp2 = Point3.sub(v1p, v2p, new Vector3());
//.........这里部分代码省略.........
示例14: prepareShadingState
public void prepareShadingState(ShadingState state)
{
state.init();
state.getRay().getPoint(state.getPoint());
Instance parent = state.getInstance();
// compute local normal
Point3 p = parent.transformWorldToObject(state.getPoint());
float gx1w = p.x - DELTA;
float gx1x = p.y;
float gx1y = p.z;
float gx1z = 0;
float gx2w = p.x + DELTA;
float gx2x = p.y;
float gx2y = p.z;
float gx2z = 0;
float gy1w = p.x;
float gy1x = p.y - DELTA;
float gy1y = p.z;
float gy1z = 0;
float gy2w = p.x;
float gy2x = p.y + DELTA;
float gy2y = p.z;
float gy2z = 0;
float gz1w = p.x;
float gz1x = p.y;
float gz1y = p.z - DELTA;
float gz1z = 0;
float gz2w = p.x;
float gz2x = p.y;
float gz2y = p.z + DELTA;
float gz2z = 0;
for (int i = 0; i < maxIterations; i++)
{
{
// z = z*z + c
float nw = gx1w * gx1w - gx1x * gx1x - gx1y * gx1y - gx1z * gx1z + cw;
gx1x = 2 * gx1w * gx1x + cx;
gx1y = 2 * gx1w * gx1y + cy;
gx1z = 2 * gx1w * gx1z + cz;
gx1w = nw;
}
{
// z = z*z + c
float nw = gx2w * gx2w - gx2x * gx2x - gx2y * gx2y - gx2z * gx2z + cw;
gx2x = 2 * gx2w * gx2x + cx;
gx2y = 2 * gx2w * gx2y + cy;
gx2z = 2 * gx2w * gx2z + cz;
gx2w = nw;
}
{
// z = z*z + c
float nw = gy1w * gy1w - gy1x * gy1x - gy1y * gy1y - gy1z * gy1z + cw;
gy1x = 2 * gy1w * gy1x + cx;
gy1y = 2 * gy1w * gy1y + cy;
gy1z = 2 * gy1w * gy1z + cz;
gy1w = nw;
}
{
// z = z*z + c
float nw = gy2w * gy2w - gy2x * gy2x - gy2y * gy2y - gy2z * gy2z + cw;
gy2x = 2 * gy2w * gy2x + cx;
gy2y = 2 * gy2w * gy2y + cy;
gy2z = 2 * gy2w * gy2z + cz;
gy2w = nw;
}
{
// z = z*z + c
float nw = gz1w * gz1w - gz1x * gz1x - gz1y * gz1y - gz1z * gz1z + cw;
gz1x = 2 * gz1w * gz1x + cx;
gz1y = 2 * gz1w * gz1y + cy;
gz1z = 2 * gz1w * gz1z + cz;
gz1w = nw;
}
{
// z = z*z + c
float nw = gz2w * gz2w - gz2x * gz2x - gz2y * gz2y - gz2z * gz2z + cw;
gz2x = 2 * gz2w * gz2x + cx;
gz2y = 2 * gz2w * gz2y + cy;
gz2z = 2 * gz2w * gz2z + cz;
gz2w = nw;
}
}
float gradX = Length(gx2w, gx2x, gx2y, gx2z) - Length(gx1w, gx1x, gx1y, gx1z);
float gradY = Length(gy2w, gy2x, gy2y, gy2z) - Length(gy1w, gy1x, gy1y, gy1z);
float gradZ = Length(gz2w, gz2x, gz2y, gz2z) - Length(gz1w, gz1x, gz1y, gz1z);
Vector3 n = new Vector3((float)gradX, (float)gradY, (float)gradZ);
state.getNormal().set(parent.transformNormalObjectToWorld(n));
state.getNormal().normalize();
state.getGeoNormal().set(state.getNormal());
state.setBasis(OrthoNormalBasis.makeFromW(state.getNormal()));
state.getPoint().x += state.getNormal().x * epsilon * 20;
state.getPoint().y += state.getNormal().y * epsilon * 20;
state.getPoint().z += state.getNormal().z * epsilon * 20;
state.setShader(parent.getShader(0));
state.setModifier(parent.getModifier(0));
//.........这里部分代码省略.........
示例15: prepareShadingState
public void prepareShadingState(ShadingState state)
{
state.init();
Instance i = state.getInstance();
state.getRay().getPoint(state.getPoint());
Ray r = state.getRay();
IShader s = i.getShader(0);
state.setShader(s != null ? s : this);
int primID = state.getPrimitiveID();
int hair = primID / numSegments;
int line = primID % numSegments;
int vRoot = hair * 3 * (numSegments + 1);
int v0 = vRoot + line * 3;
// tangent vector
Vector3 v = getTangent(line, v0, state.getV());
v = i.transformVectorObjectToWorld(v);
state.setBasis(OrthoNormalBasis.makeFromWV(v, new Vector3(-r.dx, -r.dy, -r.dz)));
state.getBasis().swapVW();
// normal
state.getNormal().set(0, 0, 1);
state.getBasis().transform(state.getNormal());
state.getGeoNormal().set(state.getNormal());
state.getUV().set(0, (line + state.getV()) / numSegments);
}