XNA 4.0 中 2d 照明着色器中的 alpha 问题
我目前正在使用 XNA 学习 HLSL,我认为教程之后最好的起点是一些简单的 2D 着色器。我正在尝试在 2D 中实现一个简单的照明着色器。
我将没有阴影的场景绘制到渲染目标,将渲染目标交换到阴影贴图,通过 Alpha 通道将灯光(每个单独)绘制到阴影贴图上,将渲染目标交换回默认值并渲染场景,然后渲染顶部的阴影。
灯光的 alpha 变化取决于当前像素的距离和灯光的点,这对我来说一切正常,除非我渲染场景时,如果两个灯光重叠,则会导致令人讨厌的混合问题。
当我在阴影贴图上绘制以及将阴影贴图绘制到场景时,我正在使用 alphablend。 我只是在这里使用了错误的混合设置吗?我对混合状态了解不多。
抱歉,如果问题含糊不清。
I'm currently learning HLSL with XNA, I figured the best place to start after tutorials would be some simple 2D shaders. I'm attempting to implement a simple lighting shader in 2D.
I draw the scene without shadows to a rendertarget, swap my rendertarget to a shadowmap, draw my light(each individually) onto the shadowmap via alpha channel, swap my rendertarget back to default and render the scene then the shadows on top.
The alpha of the light changes depending on the distance of the current pixel and the point of the light, this is all working fine for me except when I render the scene, if two lights overlap it causes a nasty blending issue.
I'm using alphablend when I draw on the shadowmap, and when I draw the shadowmap to the scene.
Am I just using the wrong blending settings here? I don't know much about blendstates.
Sorry if the question was vague.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我以前在做软件照明时就遇到过这种情况,当你的值超过 255(或 1.0)时,你最终会回到黑暗领域。我相信这些值是使用模运算来限制的,导致 1.1 为 0.1 或 256 为 1。我注意到黑色椭圆实际上是两个球体边缘的组合,这就是给我这个结论的原因。
希望这能让您更接近理解并找出您的问题。我不知道您已经在使用什么代码,但在 HLSL 技术传递中您可以尝试添加:
I've had this happen before when doing software lighting, where your values exceed 255 (or 1.0) and you end up back in the realms of blackness. I believe the values are clamped using a modulo operation causing 1.1 to be 0.1 or 256 to be 1. I notice how the black ellipse is actually two spheres edges combined, this is what is giving me this conclusion.
Hope this gets you closer to understanding and finding out your problem. I have no idea what code you are using already but in your HLSL technique pass you could try adding: