Text archives Help
- From: "Austin Robison" <arobison@rayscale.com>
- To: manta@sci.utah.edu
- Subject: [Manta] r2122 - in trunk: Engine/Shadows Interface
- Date: Mon, 25 Feb 2008 16:26:45 -0700 (MST)
Author: arobison
Date: Mon Feb 25 16:26:45 2008
New Revision: 2122
Modified:
trunk/Engine/Shadows/HardShadows.cc
trunk/Interface/RayPacket.cc
trunk/Interface/RayPacket.h
Log:
The shadow algorithm should use geometric normals for its
culling mechanism, not shading normals; this fixes many
silhouette edge shading issues.
Modified: trunk/Engine/Shadows/HardShadows.cc
==============================================================================
--- trunk/Engine/Shadows/HardShadows.cc (original)
+++ trunk/Engine/Shadows/HardShadows.cc Mon Feb 25 16:26:45 2008
@@ -59,7 +59,7 @@
// Compute the hit positions.
sourceRays.computeHitPositions();
- sourceRays.computeFFNormals( context );
+ sourceRays.computeFFGeometricNormals( context );
int j;
if(stateBuffer.state == StateBuffer::Finished){
@@ -88,7 +88,7 @@
if(b >= e){
for(int i = sourceRays.begin(); i < sourceRays.end(); i++){
Vector dir = shadowRays.getDirection(i);
- if(Dot(dir, sourceRays.getFFNormal(i)) > 0) {
+ if(Dot(dir, sourceRays.getFFGeometricNormal(i)) > 0) {
shadowRays.setOrigin(i, sourceRays.getHitPosition(i));
shadowRays.setTime(i, sourceRays.getTime(i));
// This is a version of resetHit that only sets the material
@@ -123,7 +123,7 @@
int i = sourceRays.rayBegin;
for(;i<b;i++){
Vector dir = shadowRays.getDirection(i);
- if(Dot(dir, sourceRays.getFFNormal(i)) > 0) {
+ if(Dot(dir, sourceRays.getFFGeometricNormal(i)) > 0) {
shadowRays.setOrigin(i, sourceRays.getHitPosition(i));
shadowRays.setTime(i, sourceRays.getTime(i));
// See comment above.
@@ -171,9 +171,9 @@
int firstSSE = first;
for(;i<e;i+=4){
- __m128 normalx = _mm_load_ps(&sourceData->ffnormal[0][i]);
- __m128 normaly = _mm_load_ps(&sourceData->ffnormal[1][i]);
- __m128 normalz = _mm_load_ps(&sourceData->ffnormal[2][i]);
+ __m128 normalx = _mm_load_ps(&sourceData->ffgeometricNormal[0][i]);
+ __m128 normaly = _mm_load_ps(&sourceData->ffgeometricNormal[1][i]);
+ __m128 normalz = _mm_load_ps(&sourceData->ffgeometricNormal[2][i]);
__m128 dx = _mm_load_ps(&shadowData->direction[0][i]);
__m128 dy = _mm_load_ps(&shadowData->direction[1][i]);
__m128 dz = _mm_load_ps(&shadowData->direction[2][i]);
@@ -263,7 +263,7 @@
for(;i<sourceRays.rayEnd;i++){
Vector dir = shadowRays.getDirection(i);
- if(Dot(dir, sourceRays.getFFNormal(i)) > 0) {
+ if(Dot(dir, sourceRays.getFFGeometricNormal(i)) > 0) {
shadowRays.setOrigin(i, sourceRays.getHitPosition(i));
shadowRays.setTime(i, sourceRays.getTime(i));
// See comment above.
@@ -302,7 +302,7 @@
for(int i = sourceRays.begin(); i < sourceRays.end(); i++){
// Check to see if the light is on the front face.
Vector dir = shadowRays.getDirection(i);
- if(Dot(dir, sourceRays.getFFNormal(i)) > 0) {
+ if(Dot(dir, sourceRays.getFFGeometricNormal(i)) > 0) {
shadowRays.setOrigin(i, sourceRays.getHitPosition(i));
shadowRays.setTime(i, sourceRays.getTime(i));
// See comment above.
Modified: trunk/Interface/RayPacket.cc
==============================================================================
--- trunk/Interface/RayPacket.cc (original)
+++ trunk/Interface/RayPacket.cc Mon Feb 25 16:26:45 2008
@@ -260,6 +260,24 @@
flags |= HaveGeometricNormals | HaveUnitGeometricNormals;
}
+void RayPacket::actualComputeFFGeometricNormals(const RenderContext& context)
+{
+ // We need to have normals
+ computeGeometricNormals(context);
+
+ for(int i = rayBegin; i < rayEnd; ++i) {
+ // Compute the dot product
+ Vector normal(getGeometricNormal(i));
+ if (Dot(normal, getDirection(i)) <= 0) {
+ setFFGeometricNormal(i, normal);
+ } else {
+ setFFGeometricNormal(i, -normal);
+ }
+ }
+
+ flags |= HaveFFGeometricNormals;
+}
+
void RayPacket::actualComputeSurfaceDerivatives(const RenderContext&
context) {
// Compute surface derivatives in runs over Primitive*
for(int i=rayBegin;i<rayEnd;){
Modified: trunk/Interface/RayPacket.h
==============================================================================
--- trunk/Interface/RayPacket.h (original)
+++ trunk/Interface/RayPacket.h Mon Feb 25 16:26:45 2008
@@ -97,6 +97,7 @@
MANTA_ALIGN(16) Real normal[3][MaxSize];
MANTA_ALIGN(16) Real ffnormal[3][MaxSize]; // Forward facing normals
MANTA_ALIGN(16) Real geometricNormal[3][MaxSize];
+ MANTA_ALIGN(16) Real ffgeometricNormal[3][MaxSize];
MANTA_ALIGN(16) Real hitPosition[3][MaxSize];
MANTA_ALIGN(16) Real texCoords[3][MaxSize];
MANTA_ALIGN(16) Real dPdu[3][MaxSize];
@@ -164,6 +165,7 @@
HaveGeometricNormals = 0x00040000,
HaveUnitGeometricNormals = 0x00080000,
+ HaveFFGeometricNormals = 0x00100000,
DebugPacket = 0x80000000,
};
@@ -785,6 +787,11 @@
for(int i=0;i<3;i++)
data->geometricNormal[i][which] = gnormal[i];
}
+ void setFFGeometricNormal(int which, const Vector& normal)
+ {
+ for(int i=0;i<3;++i)
+ data->ffgeometricNormal[i][which] = normal[i];
+ }
Vector getNormal(int which) const
{
return Vector(data->normal[0][which], data->normal[1][which],
data->normal[2][which]);
@@ -796,9 +803,15 @@
Vector getGeometricNormal(int which) const
{
return Vector(data->geometricNormal[0][which],
- data->geometricNormal[1][which],
+ data->geometricNormal[1][which],
data->geometricNormal[2][which]);
}
+ Vector getFFGeometricNormal(int which) const
+ {
+ return Vector(data->ffgeometricNormal[0][which],
+ data->ffgeometricNormal[1][which],
+ data->ffgeometricNormal[2][which]);
+ }
Vector getSurfaceDerivativeU(int which) const {
return Vector(data->dPdu[0][which], data->dPdu[1][which],
data->dPdu[2][which]);
}
@@ -826,10 +839,18 @@
{
if(flags & HaveGeometricNormals)
return;
-
+
actualComputeGeometricNormals(context);
}
+ void computeFFGeometricNormals(const RenderContext& context)
+ {
+ if(flags & HaveFFGeometricNormals)
+ return;
+
+ actualComputeFFGeometricNormals(context);
+ }
+
// Compute the surface derivatives
void computeSurfaceDerivatives(const RenderContext& context) {
if(flags & HaveSurfaceDerivatives)
@@ -891,6 +912,7 @@
void actualComputeNormals(const RenderContext& context);
void actualComputeFFNormals(const RenderContext& context);
void actualComputeGeometricNormals(const RenderContext& context);
+ void actualComputeFFGeometricNormals(const RenderContext& context);
void actualComputeSurfaceDerivatives(const RenderContext& context);
void actualComputeTextureCoordinates2(const RenderContext& context);
- [Manta] r2122 - in trunk: Engine/Shadows Interface, Austin Robison, 02/25/2008
Archive powered by MHonArc 2.6.16.