•float4 RayMarchPS(Ray eyeray :
TEXCOORD0,
• uniform int
steps) : COLOR
•{
• eyeray.d = normalize(eyeray.d);
•
• // calculate ray intersection with bounding box
• float tnear, tfar;
• bool hit = IntersectBox(eyeray, boxMin, boxMax, tnear,
tfar);
• if (!hit) discard;
• if (tnear < 0.0) tnear = 0.0;
•
• // calculate intersection points
• float3 Pnear = eyeray.o + eyeray.d*tnear;
• float3 Pfar = eyeray.o + eyeray.d*tfar;
•
• // march along ray, accumulating color
• half4 c = 0;
• half3 step = (Pnear - Pfar) / (steps-1);
• half3 P = Pfar;
• for(int i=0; i<steps; i++) {
• half4 s = VOLUMEFUNC(P);
• c = s.a*s + (1.0-s.a)*c;
• P += step;
• }
• c /= steps;
• return c;
•}
•