gpt4 book ai didi

graphics - HLSL 点光源着色器导致图 block 单独着色

转载 作者:行者123 更新时间:2023-12-02 19:43:43 25 4
gpt4 key购买 nike

在决定需要比 BasicEffect 提供的更好的照明后,我最近开始学习 HLSL。经过许多教程后,我发现了这一点并决定从中学习: http://brooknovak.wordpress.com/2008/11/13/hlsl-per-pixel-point-light-using-phong-blinn-lighting-model/

上面的着色器似乎在我的游戏中运行得不太好,因为我的游戏使用基于图 block 的方法,这意味着网格状结构中的多个模型。

发生的情况是我的每个图 block 都与其他图 block 分开着色。请参阅此图片以获取视觉引用: /image/hGDv1.png据我所知,这是因为每个图 block 都有自己的模型,并且着色器在模型的网格上执行时不会考虑其他模型。

现在,回答这个问题。如何将所有瓷砖一起遮光?我知道我可能必须从头开始编写一个着色器才能完成此任务,但如果有人能给我一些关于如何实现我想要的效果的提示,我将非常感激。

时间已经很晚了,我可能忘记了什么。如果您需要更多信息,请告诉我,我会添加。

谢谢,梅格里姆

编辑:

这是我绘制模型的代码:

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();
}
}

最佳答案

这一次,普通人似乎成了恶棍。在 Blender 中修正法线后,现在一切似乎都正常了。

我要感谢药物和安德鲁·拉塞尔。没有你的帮助我就不可能弄清楚!

所以现在我知道,当您的照明出现问题时,请务必先检查法线。

关于graphics - HLSL 点光源着色器导致图 block 单独着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6867231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com