@@ -166,6 +166,12 @@ public unsafe void Draw(GraphicsDevice context, Matrix world, Matrix view, Matri
166
166
Matrix * localSharedDrawBoneMatrices = stackalloc Matrix [ boneCount ] ;
167
167
168
168
CopyAbsoluteBoneTransformsTo ( new IntPtr ( localSharedDrawBoneMatrices ) ) ;
169
+
170
+ var viewProjection = Matrix . Identity ;
171
+ bool viewProjectionUsed = false ;
172
+ var worldViewProjection = Matrix . Identity ;
173
+ bool worldViewProjectionUsed = false ;
174
+
169
175
for ( int i = 0 ; i < count ; i ++ )
170
176
{
171
177
var mesh = Meshes [ i ] ;
@@ -179,16 +185,57 @@ public unsafe void Draw(GraphicsDevice context, Matrix world, Matrix view, Matri
179
185
throw new InvalidOperationException ( "Mesh has no effect" ) ;
180
186
}
181
187
188
+ Matrix result ;
189
+ Matrix . Multiply ( ref localSharedDrawBoneMatrices [ index ] , ref world , out result ) ;
190
+
182
191
var matrices = effect as IEffectMatrices ;
183
192
if ( matrices == null )
184
193
{
185
- throw new InvalidOperationException ( "Effect has no IEffectMatrices" ) ;
194
+ var worldParameter = effect . Parameters [ "World" ] ;
195
+ if ( worldParameter != null )
196
+ worldParameter . SetValue ( ref result ) ;
197
+
198
+ var viewdParameter = effect . Parameters [ "View" ] ;
199
+ if ( viewdParameter != null )
200
+ viewdParameter . SetValue ( ref view ) ;
201
+
202
+ var projectiondParameter = effect . Parameters [ "Projection" ] ;
203
+ if ( projectiondParameter != null )
204
+ projectiondParameter . SetValue ( ref projection ) ;
205
+
206
+ var viewProjectiondParameter = effect . Parameters [ "ViewProjection" ] ;
207
+
208
+ if ( viewProjectiondParameter != null )
209
+ {
210
+ if ( ! viewProjectionUsed )
211
+ {
212
+ Matrix . Multiply ( ref view , ref projection , out viewProjection ) ;
213
+ viewProjectionUsed = true ;
214
+ }
215
+ viewProjectiondParameter . SetValue ( ref viewProjection ) ;
216
+ }
217
+
218
+ var worldViewProjectiondParameter = effect . Parameters [ "WorldViewProj" ] ;
219
+
220
+ if ( worldViewProjectiondParameter != null )
221
+ {
222
+ if ( ! viewProjectionUsed )
223
+ {
224
+ Matrix . Multiply ( ref view , ref projection , out viewProjection ) ;
225
+ viewProjectionUsed = true ;
226
+ }
227
+
228
+ Matrix . Multiply ( ref result , ref viewProjection , out worldViewProjection ) ;
229
+
230
+ worldViewProjectiondParameter . SetValue ( ref worldViewProjection ) ;
231
+ }
232
+ }
233
+ else
234
+ {
235
+ matrices . World = result ;
236
+ matrices . View = view ;
237
+ matrices . Projection = projection ;
186
238
}
187
- Matrix result ;
188
- Matrix . Multiply ( ref localSharedDrawBoneMatrices [ index ] , ref world , out result ) ;
189
- matrices . World = result ;
190
- matrices . View = view ;
191
- matrices . Projection = projection ;
192
239
}
193
240
194
241
mesh . Draw ( context ) ;
0 commit comments