tag:blogger.com,1999:blog-8106074206020085661.post27741357291480246..comments2012-06-02T21:36:26.848+01:00Comments on Crumpled Code: Shader Instancing on WP7 using the SkinnedEffect trickJonathan Yonghttp://www.blogger.com/profile/01754882279015827123noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-8106074206020085661.post-18915027382956581352012-06-02T21:36:26.848+01:002012-06-02T21:36:26.848+01:00Hmm. I used the code As is and plunged into my rol...Hmm. I used the code As is and plunged into my roller coaster project.<br />I have a pretty simple model<br /><br />With 200 Tracks before I would get 25 fps<br />And with this it drops to 17 fps<br /><br />It also seemed to lock up after attempting to render 370 tracks. (in chucks of 60)<br /><br />Perhaps i am not doing it correct so ill mess around a bit more.<br /><br />But Pretty Cool Never the less.Markhttps://www.blogger.com/profile/09368321607363049011noreply@blogger.comtag:blogger.com,1999:blog-8106074206020085661.post-87756600930814751902011-06-03T19:57:49.734+01:002011-06-03T19:57:49.734+01:00(continued)
3. This is a memory intensive way to ...(continued)<br /><br />3. This is a memory intensive way to do hardware instancing and you will quickly bump-up against the max vertex/index buffer size of 64MB. But if you get anywhere near this, you probably shouldn’t be using this technique for instancing. So we need a guard, like this, and could consider guarding the index buffer size, as well…<br /><br /> // Adjust the vertex stride to include our additional index channel.<br /> int oldVertexStride = part.VertexBuffer.VertexDeclaration.VertexStride;<br /> int newVertexStride = oldVertexStride + (sizeof(byte) * 4) + (sizeof(float) * 4); //add Byte4 for BoneIndices and Vector4 for BoneWeights<br /> int newVertexCount = originalVertexCount * SkinnedEffect.MaxBones;<br /> int newVertexBufferSize = newVertexCount * newVertexStride;<br /><br /> // Vertex and Index buffers are cap'ed at 64MB<br /> if (newVertexBufferSize > 0x3FFFFFF)<br /> throw new InvalidOperationException(String.Format("Attempted to create a vertex buffer of size {0} bytes. Maximum vertex or index buffer size is 67108863 bytes (64MB)", newVertexBufferSize / 0x1000000));<br /><br /><br />4. The 3rd parameter is the vertex count, not the new buffer size. This is the primary cause of your perf problem. This…<br /> // Create a new vertex buffer, and set the replicated data into it.<br /> VertexBuffer instancedVertexBuffer = new VertexBuffer(this.Game1.GraphicsDevice, instancedVertexDeclaration, newVertexData.Length, BufferUsage.None);<br /><br /> should be this…<br /> // Create a new vertex buffer, and set the replicated data into it.<br /> VertexBuffer instancedVertexBuffer = new VertexBuffer(this.Game1.GraphicsDevice, instancedVertexDeclaration, newVertexCount, BufferUsage.None);<br /><br />5. [TODO] There is a problem with last triangle bleed-over across instances. Could be off-by-one issue or my model – either way, the cause needs to be handled. Investigating.paulbrohttps://www.blogger.com/profile/14123283772485724998noreply@blogger.comtag:blogger.com,1999:blog-8106074206020085661.post-88846576660684394142011-05-27T13:52:15.028+01:002011-05-27T13:52:15.028+01:00Love the article :) , some question..
1) I think ...Love the article :) , some question..<br /><br />1) I think SkinnedEffect supports 72 bones thus maxShaderMatrices can be the same?<br />2) Do you think this could run into a problem where the VertexBuffer is too big? I'm not sure, but probably WP supports maximum of 64MB ?Nickhttps://www.blogger.com/profile/04434868175649187916noreply@blogger.comtag:blogger.com,1999:blog-8106074206020085661.post-3635768761856381152011-02-08T16:20:17.490+00:002011-02-08T16:20:17.490+00:00@Luis
The code dont casts BasicEffect... it only g...@Luis<br />The code dont casts BasicEffect... it only gets the texture of BasicEffect and sets it on the SkinnedEffect...<br />So process your model with BasicEffect, so that the code can get the texture of it<br />Create a SkinnedEffect.. set defaultlightning and pass it through the Draw MethodUnknownhttps://www.blogger.com/profile/02859651524978417435noreply@blogger.comtag:blogger.com,1999:blog-8106074206020085661.post-71615474206233834782011-01-04T23:07:34.146+00:002011-01-04T23:07:34.146+00:00Hi, i've given this a try but i'm stuck a ...Hi, i've given this a try but i'm stuck a the Draw method call. What's the skinned effect that i'm supposed to pass as an argument? I though for a second that maybe i should choose SkinnedEffect as my content processor, but then you cast BasicEffect in the first line of the Draw method so i though maybe it's something else entirely that i'm missing.1337https://www.blogger.com/profile/03534143505964997766noreply@blogger.comtag:blogger.com,1999:blog-8106074206020085661.post-71487760734905616172010-11-02T01:24:05.511+00:002010-11-02T01:24:05.511+00:00Instancing isn't really required for particles...Instancing isn't really required for particles on Windows Phone because the CPU is actually faster than the GPU for transform operations. That's why it's faster to perform skinning on the CPU too.<br /><br />Also, with a large number of simple particles, it's faster to use vertex batching instead of instancing because shader instancing only allows a maximum of 80 or so objects per draw call. Vertex batching allows you to draw many more particles within a single call using a large vertex buffer.Jonathan Yonghttps://www.blogger.com/profile/01754882279015827123noreply@blogger.comtag:blogger.com,1999:blog-8106074206020085661.post-74009135572354937592010-11-01T16:26:37.165+00:002010-11-01T16:26:37.165+00:00Do you think you could combine your particle examp...Do you think you could combine your particle example in your previous post with shader instancing to improve performance?runnerhttps://www.blogger.com/profile/17875017196223289797noreply@blogger.com