} // RenderModelSimple /// <summary> /// Render a skinned model. /// </summary> internal void RenderModelSkinned(ref Matrix worldMatrix, Model model, Matrix[] boneTransform, Constant material, int meshIndex, int meshPart) { try { Resource.CurrentTechnique = Resource.Techniques["ConstantSkinned"]; // Skinned spBones.Value = boneTransform; // Matrix Matrix worldViewProjection; Matrix.Multiply(ref worldMatrix, ref viewProjectionMatrix, out worldViewProjection); spWorldViewProjMatrix.QuickSetValue(ref worldViewProjection); // Diffuse if (material.DiffuseTexture == null) { spDiffuseColor.Value = material.DiffuseColor; spDiffuseTexture.Value = Texture.BlackTexture; } else { spDiffuseColor.Value = Color.Black; spDiffuseTexture.Value = material.DiffuseTexture; } spAlphaBlending.Value = material.AlphaBlending; Resource.CurrentTechnique.Passes[0].Apply(); model.RenderMeshPart(meshIndex, meshPart); } catch (Exception e) { throw new InvalidOperationException("Constant Material: Unable to render model.", e); } } // RenderModelSkinned
} // RenderModelSimple /// <summary> /// Render a skinned model. /// </summary> internal void RenderModelSkinned(ref Matrix worldMatrix, Model model, Matrix[] boneTransform, BlinnPhong material, int meshIndex, int meshPart) { try { Resource.CurrentTechnique = blinnPhongSkinnedTechnique; // Skinned spBones.Value = boneTransform; // Matrix Matrix worldViewProjection; Matrix.Multiply(ref worldMatrix, ref viewProjectionMatrix, out worldViewProjection); spWorldViewProjMatrix.QuickSetValue(ref worldViewProjection); spWorldMatrix.QuickSetValue(ref worldMatrix); // Diffuse if (material.DiffuseTexture == null) { spDiffuseColor.Value = material.DiffuseColor; spDiffuseTexture.Value = Texture.BlackTexture; } else { spDiffuseColor.Value = Color.Black; spDiffuseTexture.Value = material.DiffuseTexture; } // Specular spSpecularIntensity.Value = material.SpecularIntensity; spSpecularTexture.Value = material.SpecularTexture ?? Texture.WhiteTexture; // Reflection if (material.ReflectionTexture != null) { spReflectionTexture.Value = material.ReflectionTexture; if (material.ReflectionTexture.IsRgbm) { spIsRGBM.Value = true; spMaxRange.Value = material.ReflectionTexture.RgbmMaxRange; } else { spIsRGBM.Value = false; } spReflectionTextured.Value = true; } else { spReflectionTextured.Value = false; } Resource.CurrentTechnique.Passes[0].Apply(); model.RenderMeshPart(meshIndex, meshPart); } catch (Exception e) { throw new InvalidOperationException("Bling Phong Material: Unable to render model.", e); } } // RenderModelSkinned
} // RenderModel /// <summary> /// Render objects in light space. /// </summary> internal void RenderModelCubeShadows(ref Matrix worldMatrix, Model model, Matrix[] boneTransform) { if (model.IsSkinned) // If it is a skinned model. { spBones.Value = boneTransform; Resource.CurrentTechnique = generateCubeLightDepthBufferSkinnedTechnique; } else { Resource.CurrentTechnique = generateCubeLightDepthBufferTechnique; } if (boneTransform == null || model.IsSkinned) { Matrix worldLightProjectionMatrix; Matrix.Multiply(ref worldMatrix, ref lightViewProjectionMatrix, out worldLightProjectionMatrix); spWorldViewProjMatrix.Value = worldLightProjectionMatrix; spWorldMatrix.Value = worldMatrix; Resource.CurrentTechnique.Passes[0].Apply(); model.Render(); } else { for (int mesh = 0; mesh < model.MeshesCount; mesh++) { Matrix boneTransformedWorldMatrix; Matrix.Multiply(ref boneTransform[mesh + 1], ref worldMatrix, out boneTransformedWorldMatrix); spWorldMatrix.Value = boneTransformedWorldMatrix; Matrix boneTransformedWorldLighProjectionMatrix; Matrix.Multiply(ref boneTransformedWorldMatrix, ref lightViewProjectionMatrix, out boneTransformedWorldLighProjectionMatrix); spWorldViewProjMatrix.Value = boneTransformedWorldLighProjectionMatrix; Resource.CurrentTechnique.Passes[0].Apply(); // Render the model's mesh. int meshPartsCount = model.MeshPartsCountPerMesh[mesh]; for (int meshPart = 0; meshPart < meshPartsCount; meshPart++) { model.RenderMeshPart(mesh, meshPart); } } } } // RenderModel
} // Begin #endregion #region Render /// <summary> /// Render a model. /// </summary> internal void RenderModel(ref Matrix worldMatrix, Model model, CarPaint material, int meshIndex, int meshPart) { try { // Matrices Matrix worldViewProjection; Matrix.Multiply(ref worldMatrix, ref viewProjectionMatrix, out worldViewProjection); spWorldViewProjMatrix.QuickSetValue(ref worldViewProjection); spWorldMatrix.QuickSetValue(ref worldMatrix); spWorldITMatrix.Value = Matrix.Transpose(Matrix.Invert(worldMatrix)); // Surface // spSpecularIntensity.Value = material.SpecularIntensity; spBasePaintColor.Value = material.BasePaintColor; spSecondBasePaintColor.Value = material.SecondBasePaintColor; spThridBasePaintColor.Value = material.ThirdBasePaintColor; spFlakeLayerColor.Value = material.FlakesColor; spNormalPerturbation.Value = material.NormalPerturbation; spMicroflakePerturbation.Value = material.MicroflakePerturbation; spMicroflakePerturbationA.Value = material.MicroflakePerturbationA; spReflectionTexture.Value = material.ReflectionTexture; if (material.ReflectionTexture.IsRgbm) { spIsRGBM.Value = true; spMaxRange.Value = material.ReflectionTexture.RgbmMaxRange; } else { spIsRGBM.Value = false; } spFlakeScale.Value = material.FlakesScale; spFlakesExponent.Value = material.FlakesExponent; Resource.CurrentTechnique.Passes[0].Apply(); model.RenderMeshPart(meshIndex, meshPart); } catch (Exception e) { throw new InvalidOperationException("Car Paint Material: Unable to render model.", e); } } // RenderModel
} // Begin #endregion #region Render Model /// <summary> /// Render a model. /// </summary> internal void RenderModel(ref Matrix worldMatrix, Model model, BlinnPhong material, int meshIndex, int meshPart, Vector3 spotLightPosition, Vector3 spotLightDirection, Color spotLightColor, float spotLightIntensity, float spotLightInnerAngle, float spotLightOuterAngle, float spotLightRange, Vector3 pointLightPos1, Color pointLightColor1, float pointLightIntensity1, float pointLightRange1, Vector3 pointLightPos2, Color pointLightColor2, float pointLightIntensity2, float pointLightRange2) { // Set Render States. EngineManager.Device.RasterizerState = material.BothSides ? RasterizerState.CullNone : RasterizerState.CullCounterClockwise; try { spWorldViewProjMatrix.Value = worldMatrix * viewprojectionMatrix; spWorldMatrix.Value = worldMatrix; spWorldITMatrix.Value = Matrix.Transpose(Matrix.Invert(worldMatrix)); spSpecularIntensity.Value = material.SpecularIntensity; spSpecularPower.Value = material.SpecularPower; spDiffuseColor.Value = material.DiffuseColor; spAlphaBlending.Value = material.AlphaBlending; // Diffuse if (material.DiffuseTexture == null) { spDiffuseColor.Value = material.DiffuseColor; spDiffuseTexture.Value = Texture.BlackTexture; } else { spDiffuseColor.Value = Color.Black; spDiffuseTexture.Value = material.DiffuseTexture; } // Reflection if (material.ReflectionTexture != null) { spReflectionTexture.Value = material.ReflectionTexture; if (material.ReflectionTexture.IsRgbm) { spIsRGBM.Value = true; spMaxRange.Value = material.ReflectionTexture.RgbmMaxRange; } else { spIsRGBM.Value = false; } spReflectionTextured.Value = true; } else { spReflectionTextured.Value = false; } // Spot Light // spSpotLightDirection.Value = spotLightDirection; spSpotLightPosition.Value = spotLightPosition; spSpotLightColor.Value = spotLightColor; spSpotLightIntensity.Value = spotLightIntensity; spSpotLightInnerAngle.Value = spotLightInnerAngle * (3.141592f / 180.0f); spSpotLightOuterAngle.Value = spotLightOuterAngle * (3.141592f / 180.0f); spInvSpotLightRadius.Value = 1 / spotLightRange; // Point Light // spPointLightPos1.Value = pointLightPos1; spPointLightColor1.Value = pointLightColor1; spPointLightIntensity1.Value = pointLightIntensity1; spInvPointLightRadius1.Value = 1 / pointLightRange1; spPointLightPos2.Value = pointLightPos2; spPointLightColor2.Value = pointLightColor2; spPointLightIntensity2.Value = pointLightIntensity2; spInvPointLightRadius2.Value = 1 / pointLightRange2; Resource.CurrentTechnique.Passes[0].Apply(); model.RenderMeshPart(meshIndex, meshPart); } catch (Exception e) { throw new InvalidOperationException("Forward Bling Phong Material: Unable to render model.", e); } }
} // RenderModelSkinned /// <summary> /// Render a model using the parallax technique. /// </summary> internal void RenderModelParallax(ref Matrix worldMatrix, Model model, BlinnPhong material, int meshIndex, int meshPart) { try { Resource.CurrentTechnique = blinnPhongWithParrallaxTechnique; // Matrix Matrix worldViewProjection; Matrix.Multiply(ref worldMatrix, ref viewProjectionMatrix, out worldViewProjection); spWorldViewProjMatrix.QuickSetValue(ref worldViewProjection); spWorldMatrix.QuickSetValue(ref worldMatrix); // Diffuse if (material.DiffuseTexture == null) { spDiffuseColor.Value = material.DiffuseColor; spDiffuseTexture.Value = Texture.BlackTexture; } else { spDiffuseColor.Value = Color.Black; spDiffuseTexture.Value = material.DiffuseTexture; } // Specular spSpecularIntensity.Value = material.SpecularIntensity; spSpecularTexture.Value = material.SpecularTexture ?? Texture.WhiteTexture; // Parallax spNormalTexture.Value = material.NormalTexture; spNormalTextureSize.Value = new Vector2(material.NormalTexture.Width, material.NormalTexture.Height); EngineManager.Device.SamplerStates[1] = SamplerState.AnisotropicClamp; spLODThreshold.Value = material.ParallaxLodThreshold; spMinimumNumberSamples.Value = material.ParallaxMinimumNumberSamples; spMaximumNumberSamples.Value = material.ParallaxMaximumNumberSamples; spHeightMapScale.Value = material.ParallaxHeightMapScale; spWorldITMatrix.Value = Matrix.Transpose(Matrix.Invert(worldMatrix)); // Reflection if (material.ReflectionTexture != null) { spReflectionTexture.Value = material.ReflectionTexture; if (material.ReflectionTexture.IsRgbm) { spIsRGBM.Value = true; spMaxRange.Value = material.ReflectionTexture.RgbmMaxRange; } else { spIsRGBM.Value = false; } spReflectionTextured.Value = true; } else { spReflectionTextured.Value = false; } Resource.CurrentTechnique.Passes[0].Apply(); model.RenderMeshPart(meshIndex, meshPart); } catch (Exception e) { throw new InvalidOperationException("Bling Phong Material: Unable to render model.", e); } } // RenderModelParallax