111,097
社区成员




internal void Render(Scene scene, bool parallel)
{
int[] rgb = new int[screenWidth * screenHeight];
var pixelsQuery = from y in Enumerable.Range(0, screenHeight).AsParallel().WithDegreeOfParallelism(parallel ? 2 : 1)
let recenterY = -(y - (screenHeight / 2.0)) / (2.0 * screenHeight)
select from x in Enumerable.Range(0, screenWidth)
let recenterX = (x - (screenWidth / 2.0)) / (2.0 * screenWidth)
let point =
Vector.Norm(Vector.Plus(scene.Camera.Forward,
Vector.Plus(Vector.Times(recenterX, scene.Camera.Right),
Vector.Times(recenterY, scene.Camera.Up))))
let ray = new Ray() { Start = scene.Camera.Pos, Dir = point }
let computeTraceRay = (Func<Func<TraceRayArgs, Color>, Func<TraceRayArgs, Color>>)
(f => traceRayArgs =>
(from isect in
from thing in traceRayArgs.Scene.Things
select thing.Intersect(traceRayArgs.Ray)
where isect != null
orderby isect.Dist
let d = isect.Ray.Dir
let pos = Vector.Plus(Vector.Times(isect.Dist, isect.Ray.Dir), isect.Ray.Start)
let normal = isect.Thing.Normal(pos)
let reflectDir = Vector.Minus(d, Vector.Times(2 * Vector.Dot(normal, d), normal))
let naturalColors =
from light in traceRayArgs.Scene.Lights
let ldis = Vector.Minus(light.Pos, pos)
let livec = Vector.Norm(ldis)
let testRay = new Ray() { Start = pos, Dir = livec }
let testIsects = from inter in
from thing in traceRayArgs.Scene.Things
select thing.Intersect(testRay)
where inter != null
orderby inter.Dist
select inter
let testIsect = testIsects.FirstOrDefault()
let neatIsect = testIsect == null ? 0 : testIsect.Dist
let isInShadow = !((neatIsect > Vector.Mag(ldis)) || (neatIsect == 0))
where !isInShadow
let illum = Vector.Dot(livec, normal)
let lcolor = illum > 0 ? Color.Times(illum, light.Color) : Color.Make(0, 0, 0)
let specular = Vector.Dot(livec, Vector.Norm(reflectDir))
let scolor = specular > 0
? Color.Times(Math.Pow(specular, isect.Thing.Surface.Roughness),
light.Color)
: Color.Make(0, 0, 0)
select Color.Plus(Color.Times(isect.Thing.Surface.Diffuse(pos), lcolor),
Color.Times(isect.Thing.Surface.Specular(pos), scolor))
let reflectPos = Vector.Plus(pos, Vector.Times(.001, reflectDir))
let reflectColor = traceRayArgs.Depth >= MaxDepth
? Color.Make(.5, .5, .5)
: Color.Times(isect.Thing.Surface.Reflect(reflectPos),
f(new TraceRayArgs(new Ray()
{
Start = reflectPos,
Dir = reflectDir
},
traceRayArgs.Scene,
traceRayArgs.Depth + 1)))
select naturalColors.Aggregate(reflectColor,
(color, natColor) => Color.Plus(color, natColor))
).DefaultIfEmpty(Color.Background).First())
let traceRay = Y(computeTraceRay)
select new { X = x, Y = y, Color = traceRay(new TraceRayArgs(ray, scene, 0)) };
int rowsProcessed = 0;
pixelsQuery.ForAll(row =>
{
foreach (var pixel in row)
{
rgb[pixel.X + (pixel.Y * screenWidth)] = pixel.Color.ToInt32();
}
int processed = Interlocked.Increment(ref rowsProcessed);
if (processed % rowsPerUpdate == 0 ||
processed >= screenHeight) updateImageHandler(rgb);
});
}
它编译出来之后如何读。
整天就是纠结于定一个字符串变量、然后让别人不认识“这是一个字符串变量”上,就好像是小孩子过家家,我觉得大多数成年人都实在是没有多少时间陪玩儿。有这个时间,研究一下“自己的代码都分别被多少了竞争对手研究过?是否超过50个公司?”这还有点意义。object obj2;
Dictionary<uint, object> data = AppDomain.CurrentDomain.GetData("\x00147́�m\x000f��ޗ4�Q.�") as Dictionary<uint, object>;
if (data == null)
{
AppDomain.CurrentDomain.SetData("\x00147́�m\x000f��ޗ4�Q.�", data = new Dictionary<uint, object>());
MemoryStream stream = new MemoryStream();
using (DeflateStream stream2 = new DeflateStream(Assembly.GetCallingAssembly().GetManifestResourceStream("\x00147́�m\x000f��ޗ4�Q.�"), CompressionMode.Decompress))
{
byte[] buffer = new byte[0x1000];
int count = stream2.Read(buffer, 0, 0x1000);
do
{
stream.Write(buffer, 0, count);
count = stream2.Read(buffer, 0, 0x1000);
}
while (count != 0);
}
AppDomain.CurrentDomain.SetData("�ۏFe�E\x0015#��p5��R", stream.ToArray());
}