Text archives Help
- From: bigler@sci.utah.edu
- To: manta@sci.utah.edu
- Subject: [MANTA] r1200 - in trunk: Model/Materials SwigInterface
- Date: Mon, 2 Oct 2006 22:47:56 -0600 (MDT)
Author: bigler
Date: Mon Oct 2 22:47:54 2006
New Revision: 1200
Modified:
trunk/Model/Materials/Lambertian.cc
trunk/SwigInterface/wxManta.py
Log:
Model/Materials/Lambertian.cc
SSE'ify the code. Checked with SSE enabled and not.
SwigInterface/wxManta.py
Use Phong for ground plane to match default scene.
Modified: trunk/Model/Materials/Lambertian.cc
==============================================================================
--- trunk/Model/Materials/Lambertian.cc (original)
+++ trunk/Model/Materials/Lambertian.cc Mon Oct 2 22:47:54 2006
@@ -64,26 +64,161 @@
// We need normalized directions for proper dot product computation.
shadowRays.normalizeDirections();
- for(int j=shadowRays.begin(); j < shadowRays.end(); j++){
- if(!shadowRays.wasHit(j)){
- // Not in shadow, so compute the direct and specular contributions.
- Vector normal = rays.getNormal(j);
- Vector shadowdir = shadowRays.getDirection(j);
+#ifdef MANTA_SSE
+ int b = (rays.rayBegin + 3) & (~3);
+ int e = rays.rayEnd & (~3);
+ if(b == e){
+ for(int i = rays.begin(); i < rays.end(); i++){
+ if(!shadowRays.wasHit(i)){
+ // Not in shadow, so compute the direct lighting contributions.
+ Vector normal = rays.getNormal(i);
+ Vector shadowdir = shadowRays.getDirection(i);
+ ColorComponent cos_theta = Dot(shadowdir, normal);
+ Color light = shadowRays.getColor(i);
+ for(int k = 0; k < Color::NumComponents;k++)
+ totalLight[k][i] += light[k]*cos_theta;
+ }
+ }
+ } else {
+ int i = rays.rayBegin;
+ for(;i<b;i++){
+ if(!shadowRays.wasHit(i)){
+ // Not in shadow, so compute the direct lighting contributions.
+ Vector normal = rays.getNormal(i);
+ Vector shadowdir = shadowRays.getDirection(i);
+ ColorComponent cos_theta = Dot(shadowdir, normal);
+ Color light = shadowRays.getColor(i);
+ for(int k = 0; k < Color::NumComponents;k++)
+ totalLight[k][i] += light[k]*cos_theta;
+ }
+ }
+ RayPacketData* data = rays.data;
+ RayPacketData* shadowData = shadowRays.data;
+ for(;i<e;i+=4){
+
+ // Compute a mask for the shadow rays that hit something.
+ // mask[i] is 0 if shadowRays[i] is in shadow.
+#ifdef __x86_64
+
+ // Check Phong.cc to see if the _mm_load_pd function is ever
+ // made to work. For now this is the method that seems to not
+ // break in most compilers.
+ __m128 masklo = _mm_castpd_ps( _mm_cmpeq_pd(
_mm_set_pd((double)(size_t)shadowData->hitMatl[i+0],
+
(double)(size_t)shadowData->hitMatl[i+1]),
+ _mm_setzero_pd() ));
+ __m128 maskhi = _mm_castpd_ps( _mm_cmpeq_pd (
_mm_set_pd((double)(size_t)shadowData->hitMatl[i+2],
+
(double)(size_t)shadowData->hitMatl[i+3] ),
+ _mm_setzero_pd() ));
+
+ __m128 mask = _mm_shuffle_ps(masklo, maskhi, _MM_SHUFFLE(2, 0, 2,
0));
+#else
+ __m128 mask =
_mm_cmpeq_ps(_mm_load_ps((float*)&shadowData->hitMatl[i]), _mm_setzero_ps());
+#endif
+
+ if(_mm_movemask_ps(mask) == 0)
+ // All hit points are in shadow
+ continue;
+
+ // Not in shadow, so compute the direct light contributions.
+
+ // Vector normal = rays.getNormal(i)
+ __m128 normalx = _mm_load_ps(&data->normal[0][i]);
+ __m128 normaly = _mm_load_ps(&data->normal[1][i]);
+ __m128 normalz = _mm_load_ps(&data->normal[2][i]);
+ // Vector shadowdir = shadowRays.getDirection(i);
+ __m128 sdx = _mm_load_ps(&shadowData->direction[0][i]);
+ __m128 sdy = _mm_load_ps(&shadowData->direction[1][i]);
+ __m128 sdz = _mm_load_ps(&shadowData->direction[2][i]);
+ // ColorComponent cos_theta = Dot(shadowdir, normal);
+ __m128 cos_theta = _mm_add_ps(_mm_add_ps(_mm_mul_ps(sdx, normalx),
_mm_mul_ps(sdy, normaly)), _mm_mul_ps(sdz, normalz));
+ // Color light = shadowRays.getColor(i);
+ __m128 lightr = _mm_load_ps(&shadowData->color[0][i]);
+ __m128 lightg = _mm_load_ps(&shadowData->color[1][i]);
+ __m128 lightb = _mm_load_ps(&shadowData->color[2][i]);
+ // for(int k = 0; k < Color::NumComponents;k++)
+ // totalLight[k][i] += light[k]*cos_theta;
+ if(_mm_movemask_ps(mask) == 0xf){
+ // All the rays are not in shadow
+ _mm_store_ps(&totalLight[0][i],
_mm_add_ps(_mm_load_ps(&totalLight[0][i]), _mm_mul_ps(lightr, cos_theta)));
+ _mm_store_ps(&totalLight[1][i],
_mm_add_ps(_mm_load_ps(&totalLight[1][i]), _mm_mul_ps(lightg, cos_theta)));
+ _mm_store_ps(&totalLight[2][i],
_mm_add_ps(_mm_load_ps(&totalLight[2][i]), _mm_mul_ps(lightb, cos_theta)));
+ } else {
+ // Some rays are in shadow so only copy over data for those that
are.
+
_mm_maskmoveu_si128(_mm_castps_si128(_mm_add_ps(_mm_load_ps(&totalLight[0][i]),
_mm_mul_ps(lightr, cos_theta))), _mm_castps_si128(mask),
(char*)&totalLight[0][i]);
+
_mm_maskmoveu_si128(_mm_castps_si128(_mm_add_ps(_mm_load_ps(&totalLight[1][i]),
_mm_mul_ps(lightg, cos_theta))), _mm_castps_si128(mask),
(char*)&totalLight[1][i]);
+
_mm_maskmoveu_si128(_mm_castps_si128(_mm_add_ps(_mm_load_ps(&totalLight[2][i]),
_mm_mul_ps(lightb, cos_theta))), _mm_castps_si128(mask),
(char*)&totalLight[2][i]);
+ }
+ }
+ // Pick up the trailing bits
+ for(;i<rays.rayEnd;i++){
+ if(!shadowRays.wasHit(i)){
+ // Not in shadow, so compute the direct lighting contributions.
+ Vector normal = rays.getNormal(i);
+ Vector shadowdir = shadowRays.getDirection(i);
+ ColorComponent cos_theta = Dot(shadowdir, normal);
+ Color light = shadowRays.getColor(i);
+ for(int k = 0; k < Color::NumComponents;k++)
+ totalLight[k][i] += light[k]*cos_theta;
+ }
+ }
+ }
+#else
+ for(int i=shadowRays.begin(); i < shadowRays.end(); i++){
+ if(!shadowRays.wasHit(i)){
+ // Not in shadow, so compute the direct lighting contributions.
+ Vector normal = rays.getNormal(i);
+ Vector shadowdir = shadowRays.getDirection(i);
ColorComponent cos_theta = Dot(shadowdir, normal);
- Color light = shadowRays.getColor(j);
+ Color light = shadowRays.getColor(i);
for(int k = 0; k < Color::NumComponents;k++)
- totalLight[k][j] += light[k]*cos_theta;
+ totalLight[k][i] += light[k]*cos_theta;
}
}
+#endif
firstTime = false;
} while(!done);
- // Sum up diffuse/specular contributions
+#ifdef MANTA_SSE
+ int b = (rays.rayBegin + 3) & (~3);
+ int e = rays.rayEnd & (~3);
+ if(b == e){
+ for(int i = rays.begin(); i < rays.end(); i++){
+ Color result;
+ for(int j=0;j<Color::NumComponents;j++)
+ result[j] = totalLight[j][i] * diffuse.colordata[j][i];
+ rays.setColor(i, result);
+ }
+ } else {
+ int i = rays.rayBegin;
+ for(;i<b;i++){
+ Color result;
+ for(int j=0;j<Color::NumComponents;j++)
+ result[j] = totalLight[j][i] * diffuse.colordata[j][i];
+ rays.setColor(i, result);
+ }
+ RayPacketData* data = rays.data;
+ for(;i<e;i+=4){
+ _mm_store_ps(&data->color[0][i],
_mm_mul_ps(_mm_load_ps(&totalLight[0][i]),
+
_mm_load_ps(&diffuse.colordata[0][i])));
+ _mm_store_ps(&data->color[1][i],
_mm_mul_ps(_mm_load_ps(&totalLight[1][i]),
+
_mm_load_ps(&diffuse.colordata[1][i])));
+ _mm_store_ps(&data->color[2][i],
_mm_mul_ps(_mm_load_ps(&totalLight[2][i]),
+
_mm_load_ps(&diffuse.colordata[2][i])));
+ }
+ for(;i<rays.rayEnd;i++){
+ Color result;
+ for(int j=0;j<Color::NumComponents;j++)
+ result[j] = totalLight[j][i] * diffuse.colordata[j][i];
+ rays.setColor(i, result);
+ }
+ }
+#else
for(int i = rays.begin(); i < rays.end(); i++){
Color result;
for(int j=0;j<Color::NumComponents;j++)
result[j] = totalLight[j][i] * diffuse.colordata[j][i];
rays.setColor(i, result);
}
+#endif
}
Modified: trunk/SwigInterface/wxManta.py
==============================================================================
--- trunk/SwigInterface/wxManta.py (original)
+++ trunk/SwigInterface/wxManta.py Mon Oct 2 22:47:54 2006
@@ -41,8 +41,8 @@
constant_color1 = manta_new(Constant_Color(Color(RGBColor(.6,.6,.6))))
checker2 = manta_new(CheckerTexture_ColorComponent(0.2, 0.5,
Vector(1,0,0),
Vector(0,1,0)))
- # plane_matl = manta_new(Phong(checker1, constant_color1, 32, checker2))
- plane_matl = manta_new(Lambertian(checker1))
+ plane_matl = manta_new(Phong(checker1, constant_color1, 32, checker2))
+ #plane_matl = manta_new(Lambertian(checker1))
world = manta_new(Group())
floor = manta_new(Parallelogram(plane_matl, Vector(-20,-20,0),
- [MANTA] r1200 - in trunk: Model/Materials SwigInterface, bigler, 10/02/2006
Archive powered by MHonArc 2.6.16.