res wrote:
On 23.10.2007 06:00, Philipp Wojke wrote:
Some other strange behavior I encountered: inserting an unnecessary
SetVertexCount/SetTriangleCount (with unchanged counts) before
manipulating the vertices and triangles considerably speeds up the
drawing process.
This actually marks some data as "dirty". Makes one wonder what the
point of pre-allocating a large number of vertices then is, since it
seems that you can just as well stick to changing the counts to the
needed number.
Anyhow, last time I asked wrt the color corruption: "what if you also
manually set the vertex color for each vertex?" Either you didn't try or
didn't tell anyone the results.
I have finally found the error. Someone has forgotten to initialize
static_mesh_colors after changing vertex count.
Is static_mesh_colors used? I can't find changes to it other then
initialization with zero values.
I will attach a patch for this problem and the correct per-vertex
lighting I talked some time earlier. The patched is for
https://crystal.svn.sourceforge.net/svnroot/crystal/CS/branches/release/V1.0/plugins/mesh/genmesh/object/genmesh.cpp
Philipp
Index: genmesh.cpp
===================================================================
--- genmesh.cpp (revision 26870)
+++ genmesh.cpp (working copy)
@@ -263,6 +263,9 @@
lit_mesh_colors = new csColor4 [num_lit_mesh_colors];
delete[] static_mesh_colors;
static_mesh_colors = new csColor4 [num_lit_mesh_colors];
+ for (int i = 0 ; i < num_lit_mesh_colors; i++)
+ //static_mesh_colors[i] = base_color; // Initialize to base color.
+ static_mesh_colors[i].Set (0, 0, 0);
}
}
@@ -784,42 +787,89 @@
csColor4* colors = lit_mesh_colors;
// Compute light position in object coordinates
csVector3 wor_light_pos = li->GetMovable ()->GetFullPosition ();
- csVector3 obj_light_pos = trans.Other2This (wor_light_pos);
- float obj_sq_dist = csSquaredDist::PointPoint (obj_light_pos, 0);
- if (obj_sq_dist >= csSquare (li->GetCutoffDistance ())) return;
- float in_obj_dist =
- (obj_sq_dist >= SMALL_EPSILON) ? csQisqrt (obj_sq_dist) : 1.0f;
+ csVector3 obj_light_pos = trans.Other2This (wor_light_pos);
- csColor light_color = li->GetColor () * (256. / CS_NORMAL_LIGHT_LEVEL)
- * li->GetBrightnessAtDistance (csQsqrt (obj_sq_dist));
- if (light_color.red < EPSILON && light_color.green < EPSILON
- && light_color.blue < EPSILON)
- return;
+ // Check wich effect vertice positions will have on lighting.
+ // If lighting is not much affected by vertice positions calculate
+ // lighting based on object center for speed up.
- csColor col;
- int i;
- if (obj_sq_dist < SMALL_EPSILON)
+ float obj_light_dist = obj_light_pos.Norm();
+ float obj_radius = factory->GetRadius();
+
+ if (obj_light_dist > obj_radius
+ && fabs(li->GetBrightnessAtDistance(obj_light_dist - obj_radius)
+ - li->GetBrightnessAtDistance(obj_light_dist + obj_radius)) < 1.0f
/ 128.0f)
{
- for (i = 0 ; i < factory->GetVertexCount () ; i++)
+ float obj_sq_dist = csSquaredDist::PointPoint (obj_light_pos, 0);
+ if (obj_sq_dist >= csSquare (li->GetCutoffDistance ())) return;
+ float in_obj_dist =
+ (obj_sq_dist >= SMALL_EPSILON) ? csQisqrt (obj_sq_dist) : 1.0f;
+
+ csColor light_color = li->GetColor () * (256. / CS_NORMAL_LIGHT_LEVEL)
+ * li->GetBrightnessAtDistance (csQsqrt (obj_sq_dist));
+ if (light_color.red < EPSILON && light_color.green < EPSILON
+ && light_color.blue < EPSILON)
+ return;
+
+ csColor col;
+ int i;
+ if (obj_sq_dist < SMALL_EPSILON)
{
- colors[i] += light_color;
+ for (i = 0 ; i < factory->GetVertexCount () ; i++)
+ {
+ colors[i] += light_color;
+ }
}
+ else
+ {
+ obj_light_pos *= in_obj_dist;
+ for (i = 0 ; i < factory->GetVertexCount () ; i++)
+ {
+ float cosinus = obj_light_pos * normals[i];
+ // because the vector from the object center to the light center
+ // in object space is equal to the position of the light
+
+ if (cosinus > 0)
+ {
+ col = light_color;
+ if (cosinus < 1) col *= cosinus;
+ colors[i] += col;
+ }
+ }
+ }
}
else
{
- obj_light_pos *= in_obj_dist;
- for (i = 0 ; i < factory->GetVertexCount () ; i++)
+ csVector3* vertices = factory->GetVertices();
+ for (int i = 0 ; i < factory->GetVertexCount () ; i++)
{
- float cosinus = obj_light_pos * normals[i];
- // because the vector from the object center to the light center
- // in object space is equal to the position of the light
+ float obj_sq_dist = csSquaredDist::PointPoint (obj_light_pos,
vertices[i]);
+ if (obj_sq_dist >= csSquare (li->GetCutoffDistance ())) continue;
+ float in_obj_dist =
+ (obj_sq_dist >= SMALL_EPSILON) ? csQisqrt (obj_sq_dist) : 1.0f;
- if (cosinus > 0)
+ csColor light_color = li->GetColor () * (256. / CS_NORMAL_LIGHT_LEVEL)
+ * li->GetBrightnessAtDistance (csQsqrt (obj_sq_dist));
+ if (light_color.red < EPSILON && light_color.green < EPSILON
+ && light_color.blue < EPSILON)
+ continue;
+
+ csColor col;
+ if (obj_sq_dist < SMALL_EPSILON)
{
- col = light_color;
- if (cosinus < 1) col *= cosinus;
- colors[i] += col;
+ colors[i] += light_color;
}
+ else
+ {
+ float cosinus = ((obj_light_pos - vertices[i]) * in_obj_dist) *
normals[i];
+
+ if (cosinus > 0)
+ {
+ col = light_color;
+ if (cosinus < 1) col *= cosinus;
+ colors[i] += col;
+ }
+ }
}
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Crystal-main mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/crystal-main
Unsubscribe: mailto:[EMAIL PROTECTED]