本文整理汇总了C#中Disque.Math.ShadeRec类的典型用法代码示例。如果您正苦于以下问题:C# ShadeRec类的具体用法?C# ShadeRec怎么用?C# ShadeRec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ShadeRec类属于Disque.Math命名空间,在下文中一共展示了ShadeRec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetColor
public override Vector3 GetColor(ShadeRec sr)
{
float x = sr.LocalHitPoint.X;
float y = sr.LocalHitPoint.Y;
float z = sr.LocalHitPoint.Z;
float x_size = b.X / num_x_checkers; // in radians - azimuth angle
float z_size = a.Z / num_z_checkers;
int i_phi = MathHelper.Floor(x / x_size);
int i_theta = MathHelper.Floor(z / z_size);
float f_phi = x / x_size - i_phi;
float f_theta = z / z_size - i_theta;
float phi_line_width = 0.5f * x_line_width;
float theta_line_width = 0.5f * z_line_width;
bool in_outline = (f_phi < phi_line_width || f_phi > 1.0 - phi_line_width) ||
(f_theta < theta_line_width || f_theta > 1.0 - theta_line_width);
if ((i_phi + i_theta) % 2 == 0)
{
if (!in_outline)
return (color1);
}
else
{
if (!in_outline)
return (color2);
}
return (line_color);
}
示例2: Hit
public override bool Hit(Ray ray, ref float tmin, ref ShadeRec sr)
{
if (bbox.Hit(ray))
return base.Hit(ray, ref tmin, ref sr);
else
return false;
}
示例3: Global_Shade
public override Vector3 Global_Shade(ShadeRec sr)
{
if (sr.Depth == 1)
return (Vector3.Zero);
else
return ls * t.GetColor(sr);
}
示例4: Area_Light_Shade
public override Vector3 Area_Light_Shade(ShadeRec sr)
{
Vector3 wo = -sr.Ray.Direction;
Vector3 L = ambient.RHO(sr, wo) * sr.World.AmbientLight.L(sr);
int num_lights = sr.World.Lights.Count;
for (int j = 0; j < num_lights; j++)
{
Light light_ptr = sr.World.Lights[j];
Vector3 wi = light_ptr.GetDirection(sr); //compute_direction ?
wi.Normalize();
float ndotwi = Vector3.Dot(sr.Normal, wi);
float ndotwo = Vector3.Dot(sr.Normal, wo);
if (ndotwi > 0.0 && ndotwo > 0.0)
{
bool in_shadow = false;
if (sr.World.Lights[j].Shadows)
{
Ray shadow_ray = new Ray(sr.HitPoint, wi);
in_shadow = light_ptr.InShadow(shadow_ray, sr);
}
if (!in_shadow)
L += diffuse.F(sr, wo, wi) * light_ptr.L(sr) * light_ptr.G(sr) * ndotwi / sr.World.Lights[j].PDF(sr);
}
}
return (L);
}
示例5: GetColor
public override Vector3 GetColor(ShadeRec sr)
{
float x = sr.LocalHitPoint.X - center.X;
float y = sr.LocalHitPoint.Y - center.Y;
float z = sr.LocalHitPoint.Z - center.Z;
float phi = MathHelper.Atan2(x, z);
float phi_size = 2 * MathHelper.PI / num_angular_checkers;
float theta_size = radius / num_radial_checkers;
float ra = MathHelper.Sqrt(x * x + z * z) / radius;
int i_phi = MathHelper.Floor(phi / phi_size);
int i_theta = MathHelper.Floor(ra / theta_size);
float f_phi = phi / phi_size - i_phi;
float f_theta = ra / theta_size - i_theta;
float phi_line_width = 0.5f * angular_line_width;
float theta_line_width = 0.5f * radial_line_width;
bool in_outline = (f_phi < phi_line_width || f_phi > 1.0 - phi_line_width) ||
(f_theta < theta_line_width || f_theta > 1.0 - theta_line_width);
if ((i_phi + i_theta) % 2 == 0)
{
if (!in_outline)
return (color1);
}
else
{
if (!in_outline)
return (color2);
}
return (line_color);
}
示例6: Hit
public override bool Hit(Ray ray, ref float tmin, ref ShadeRec sr)
{
Vector3 v0 = (Mesh.Vertices[index0]);
Vector3 v1 = (Mesh.Vertices[index1]);
Vector3 v2 = (Mesh.Vertices[index2]);
float a = v0.X - v1.X, b = v0.X - v2.X, c = ray.Direction.X, d = v0.X - ray.Position.X;
float e = v0.Y - v1.Y, f = v0.Y - v2.Y, g = ray.Direction.Y, h = v0.Y - ray.Position.Y;
float i = v0.Z - v1.Z, j = v0.Z - v2.Z, k = ray.Direction.Z, l = v0.Z - ray.Position.Z;
float m = f * k - g * j, n = h * k - g * l, p = f * l - h * j;
float q = g * i - e * k, s = e * j - f * i;
float inv_denom = 1.0f / (a * m + b * q + c * s);
float e1 = d * m - b * n - c * p;
float beta = e1 * inv_denom;
if (beta < 0.0)
return (false);
float r = e * l - h * i;
float e2 = a * n + d * q + c * r;
float gamma = e2 * inv_denom;
if (gamma < 0.0)
return (false);
if (beta + gamma > 1.0)
return (false);
float e3 = a * p - b * r + d * s;
float t = e3 * inv_denom;
if (t < MathHelper.Epsilon)
return (false);
tmin = t;
sr.Normal = interpolate_normal(beta, gamma); // for smooth shading
sr.LocalHitPoint = ray.Position + t * ray.Direction;
return (true);
}
示例7: Sample_F
public override Vector3 Sample_F(ShadeRec sr, Vector3 wo, ref Vector3 wi, ref float pdf)
{
float ndotwo = Vector3.Dot(sr.Normal, wo);
wi = -wo + 2.0f * sr.Normal * ndotwo;
pdf = Vector3.AbsDot(sr.Normal, wi);
return kr * cr.GetColor(sr);
}
示例8: Area_Light_Shade
public override Vector3 Area_Light_Shade(ShadeRec sr)
{
Vector3 wo = -sr.Ray.Direction;
Vector3 L = ambient.RHO(sr, wo) * sr.World.AmbientLight.L(sr);
int num_lights = sr.World.Lights.Count;
for (int j = 0; j < num_lights; j++)
{
Vector3 wi = sr.World.Lights[j].GetDirection(sr);
float ndotwi = Vector3.Dot(sr.Normal, wi);
if (ndotwi > 0.0)
{
if (Shadows)
{
bool in_shadow = false;
if (sr.World.Lights[j].Shadows)
{
Ray shadowRay = new Ray(sr.HitPoint, wi);
in_shadow = sr.World.Lights[j].InShadow(shadowRay, sr);
}
if (!in_shadow)
L += (diffuse.F(sr, wo, wi)
+ specular.F(sr, wo, wi)) * sr.World.Lights[j].L(sr) * ndotwi * sr.World.Lights[j].G(sr) / sr.World.Lights[j].PDF(sr);
}
else
{
L += (diffuse.F(sr, wo, wi)
+ specular.F(sr, wo, wi)) * sr.World.Lights[j].L(sr) * ndotwi * sr.World.Lights[j].G(sr) / sr.World.Lights[j].PDF(sr);
}
}
}
return (L);
}
示例9: Area_Light_Shade
public override Vector3 Area_Light_Shade(ShadeRec sr)
{
if (Vector3.Dot(-sr.Normal, sr.Ray.Direction) > 0.0f) //here may be ConcaveSphere not support
return (Radiance * Color);
else
return (Vector3.Zero);
}
示例10: HitObjects
public ShadeRec HitObjects(Ray ray)
{
ShadeRec sr = new ShadeRec(this);
float t = 0;
Vector3 normal = Vector3.Zero;
Vector3 local_hit_point = Vector3.Zero;
float tmin = float.MaxValue;
int num_objects = Objects.Count;
for (int j = 0; j < num_objects; j++)
{
if (Objects[j].Hit(ray, ref t, ref sr) && (t < tmin))
{
sr.Hit_an_object = true;
tmin = t;
sr.Material = Objects[j].GetMaterial();
sr.HitPoint = ray.Position + t * ray.Direction;
normal = sr.Normal;
local_hit_point = sr.LocalHitPoint;
}
}
if (sr.Hit_an_object)
{
sr.T = tmin;
sr.Normal = normal;
sr.LocalHitPoint = local_hit_point;
}
return (sr);
}
示例11: Shade
public override Vector3 Shade(ShadeRec sr)
{
if (Vector3.Dot(-sr.Normal, sr.Ray.Direction) > 0.0f)
return (Radiance * Color);
else
return (Vector3.Zero);
}
示例12: Sample_F
public override Vector3 Sample_F(ShadeRec sr, Vector3 wo, ref Vector3 wi, ref float pdf)
{
float ndotwo = Vector3.Dot(sr.Normal, wo);
wi = -wo + 2.0f * sr.Normal * ndotwo;
pdf = MathHelper.Abs(Vector3.Dot(sr.Normal, wi));
return (ReflectionCoefficient * Color);
}
示例13: Hit
public override bool Hit(Ray ray, ref float tmin, ref ShadeRec sr)
{
if (!bbox.Hit(ray))
return false;
float t = 0;
Vector3 normal = new Vector3(), local_hit_point = Vector3.Zero;
bool hit = false;
tmin = float.MaxValue;
int num_objects = Objects.Count;
for (int j = 0; j < num_objects; j++)
if (Objects[j].Hit(ray, ref t,ref sr) && (t < tmin))
{
hit = true;
tmin = t;
Material = Objects[j].GetMaterial();
normal = sr.Normal;
local_hit_point = sr.LocalHitPoint;
}
if (hit)
{
sr.T = tmin;
sr.Normal = normal;
sr.LocalHitPoint = local_hit_point;
}
return (hit);
}
示例14: Hit
public override bool Hit(Ray ray, ref float tmin, ref ShadeRec sr)
{
if (!bbox.Hit(ray))
return (false);
float t = Vector3.Dot((center - ray.Position), normal) / Vector3.Dot(ray.Direction, normal);
if (t <= MathHelper.Epsilon)
return (false);
Vector3 p = ray.Position + t * ray.Direction;
float v = center.DistanceSquared(p);
if (v < w_squared && v > i_squared)
{
double phi =MathHelper.Atan2(p.X, p.Z);
if (phi < 0.0)
phi += MathHelper.TwoPI;
if (phi <= max_azimuth && phi >= min_azimuth)
{
tmin = t;
sr.Normal = normal;
sr.LocalHitPoint = p;
return (true);
}
else
return false;
}
else
return (false);
}
示例15: Hit
public override bool Hit(Ray ray, ref float tmin, ref ShadeRec sr)
{
float t;
Vector3 temp = ray.Position - center;
float a = Vector3.Dot(ray.Direction, ray.Direction);
float b = 2.0f * Vector3.Dot(temp, ray.Direction);
float c = Vector3.Dot(temp, temp) - radius * radius;
float disc = b * b - 4.0f * a * c;
if (disc < 0.0)
return (false);
else
{
float e = MathHelper.Sqrt(disc);
float denom = 2.0f * a;
t = (-b - e) / denom;
if (t > MathHelper.BigEpsilon)
{
tmin = t;
sr.Normal = -(temp + t * ray.Direction) / radius;
sr.LocalHitPoint = ray.Position + t * ray.Direction;
return (true);
}
t = (-b + e) / denom;
if (t > MathHelper.BigEpsilon)
{
tmin = t;
sr.Normal = -(temp + t * ray.Direction) / radius;
sr.LocalHitPoint = ray.Position + t * ray.Direction;
return (true);
}
}
return (false);
}