Hi guys, I've implemented this shadow sample into my engine: http://www.catalinzima.com/2013/01/dynamic-2d-shadows-for-windows-phone-7/ Everything was working fine until I ran my game on the Xbox 360.... I get 30 FPS when my game runs at 1920 x 1080, but if I run it at 1280 x 720 or below it runs at 60 FPS. If you run the stand alone sample the same thing happens.
I don't know exactly why the resolution makes a difference, but I did some further profiling and found that this call gets called for every hull:
game.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2);
When I draw just one hull my FPS goes back up to 60, so for the last week or so I've been trying to add all of the verts and indices to a list and then make this call one time after iterating through the hulls. The problem is that after doing this the shadows are drawing really whacky... I'm not sure where I'm going wrong, this should be a simple fix but it seems I'm overlooking something small that is screwing me up.
Any help would be appreciated! I attached the modified sample to this post.
My changes are in ConvexHull's DrawShadows:
int currentIndex = startingIndex;
int svCount = 0;
while (svCount != shadowVertexCount * 2)
{
shadowHullIndices.Add(currentIndex + shadowHullVertices.Count); //Added this
Vector3 vertexPos = vertices[currentIndex].Position + new Vector3(position, 0);
//one vertex on the hull
shadowVertices[svCount] = new VertexPositionColor();
shadowVertices[svCount].Color = Color.Transparent;
shadowVertices[svCount].Position = vertexPos;
//one extruded by the light direction
shadowVertices[svCount + 1] = new VertexPositionColor();
shadowVertices[svCount + 1].Color = Color.Transparent;
Vector3 L2P = vertexPos - new Vector3(lightSource.Position, 0);
L2P.Normalize();
shadowVertices[svCount + 1].Position = new Vector3(lightSource.Position, 0) + L2P * 9000;
svCount += 2;
currentIndex = (currentIndex + 1) % primitiveCount;
}
drawingEffect.World = Matrix.Identity;
drawingEffect.CurrentTechnique.Passes[0].Apply();
for (int i = 0; i < shadowVertexCount * 2 - 2; i++) //Added this
shadowHullVertices.Add(shadowVertices[i]);
//Original call:
//game.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, shadowVertices, 0, shadowVertexCount * 2 - 2);
and in Game1's DrawLightmap:
foreach (ConvexHull ch in objects)
{
//draw shadow
ch.DrawShadows(light, shadowHullVertices, shadowHullIndices); //Added. For now, pass the lists in and add the appropriate verts and indices.
}
//Added this:
GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, shadowHullVertices.ToArray(), 0, shadowHullVertices.Count, shadowHullIndices.ToArray(), 0, shadowHullIndices.Count / 3);