本文整理汇总了C#中ShadingState.getNormal方法的典型用法代码示例。如果您正苦于以下问题:C# ShadingState.getNormal方法的具体用法?C# ShadingState.getNormal怎么用?C# ShadingState.getNormal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShadingState
的用法示例。
在下文中一共展示了ShadingState.getNormal方法的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: 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);
}
}
}
}
示例4: 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);
}
示例5: 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);
}
示例6: getRadiance
public Color getRadiance(ShadingState state)
{
Vector3 n = state.getNormal();
if (n == null)
return Color.BLACK;
float r = (n.x + 1) * 0.5f;
float g = (n.y + 1) * 0.5f;
float b = (n.z + 1) * 0.5f;
return new Color(r, g, b);
}
示例7: 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);
}
示例8: 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);
}
}
示例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());
}
示例10: 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()));
}
示例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);
}
}
}
}
示例12: 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);
}
}
示例13: 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);
}
示例14: 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()));
}
示例15: prepareShadingState
/**
* Prepare the shading state for shader invocation. This also runs the
* currently attached surface modifier.
*
* @param state shading state to be prepared
*/
public void prepareShadingState(ShadingState state)
{
geometry.prepareShadingState(state);
if (state.getNormal() != null && state.getGeoNormal() != null)
state.correctShadingNormal();
// run modifier if it was provided
if (state.getModifier() != null)
state.getModifier().modify(state);
}