我最近开始学习HLSL,因为我决定要比BasicEffect提供的更好的照明。在阅读了许多教程之后,我发现了这一点,并决定从中学习:http://brooknovak.wordpress.com/2008/11/13/hlsl-per-pixel-point-light-using-phong-blinn-lighting-model/
上面的着色器似乎在我的游戏中不太好用,因为我的游戏使用了一种基于瓷砖的方法,这意味着在一个类似网格的阵型中有多个模型。
我的每块瓷砖都是分开的。请看这张图片作为视觉参考:http://i.imgur.com/1Sfi2.png,我知道这是因为每个瓷砖都有自己的模型,而且着色器没有考虑其他模型,因为它是在模型的网格上执行的。
现在,为了这个问题。怎样才能把所有的瓷砖都遮住?我知道我可能需要从头开始写一个着色器来完成这个任务,但是如果有人能给我一些关于如何达到我想要的效果的建议,我会非常感激的。
很晚了,所以我有可能忘了什么。如果您需要更多的信息,请告诉我,我会添加它。
谢谢你,梅里格里姆
编辑:
下面是我绘制模型的代码:
public void DrawModel(Model model, Matrix modelTransform, Matrix[] absoluteBoneTransforms, Vector3 color, float alpha = 1.0f, Texture2D texture = null)
{
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (ModelMeshPart part in mesh.MeshParts)
{
part.Effect = effect;
Matrix world = absoluteBoneTransforms[mesh.ParentBone.Index] * modelTransform;
effect.Parameters["World"].SetValue(absoluteBoneTransforms[mesh.ParentBone.Index] * modelTransform);
effect.Parameters["View"].SetValue(camera.view);
effect.Parameters["Projection"].SetValue(camera.projection);
effect.Parameters["CameraPos"].SetValue(camera.cameraPosition);
Vector3 lookAt = camera.cameraPosition + camera.cameraDirection;
effect.Parameters["LightPosition"].SetValue(new Vector3(lookAt.X, 1.0f, lookAt.Z - 5.0f));
effect.Parameters["LightDiffuseColor"].SetValue(new Vector3(0.45f, 0.45f, 0.45f));
effect.Parameters["LightSpecularColor"].SetValue(new Vector3(0.45f, 0.45f, 0.45f));
effect.Parameters["LightDistanceSquared"].SetValue(40.0f);
effect.Parameters["DiffuseColor"].SetValue(color);
effect.Parameters["AmbientLightColor"].SetValue(Color.Black.ToVector3());
effect.Parameters["EmissiveColor"].SetValue(Color.White.ToVector3());
effect.Parameters["SpecularColor"].SetValue(Color.White.ToVector3());
effect.Parameters["SpecularPower"].SetValue(10.0f);
if (texture != null)
{
effect.Parameters["DiffuseTexture"].SetValue(texture);
}
mesh.Draw();
}
}
pass.Apply();
}
}发布于 2011-07-29 12:47:08
这一次,正常人似乎是坏人。在修正了搅拌机的法线后,一切似乎都正常了。
我要感谢医生和安德鲁·罗素。如果没有你的帮助,我是不会想出来的!
所以现在我知道了,当你的照明有问题时,一定要先检查正常值。
https://stackoverflow.com/questions/6867231
复制相似问题