【问题标题】:Spot Light seems to always point to the center of the world聚光灯似乎总是指向世界的中心
【发布时间】:2016-05-01 17:52:52
【问题描述】:

我目前面临的问题是,即使我仔细检查了传递给着色器的方向矢量,我的聚光灯似乎总是面向我的世界中心。

具有相同代码的点光源(但不根据其允许的角度和方向限制光源)可以正常工作。所以我的光矢量和一切似乎都有效。

这里是这种行为的图片:

在图片上,灯光向上指向世界中心,而不是无人机所面对的右侧。那里的蓝色点灯表明照明在其他情况下似乎有效。

我正在计算视图空间中的灯光并将以下内容传递给着色器:

SpotLightPositionViewSpace[spotLightNum] = Vector3.Transform(l.getPosition(), viewMatrix);
…
SpotLightDirectionViewSpace[spotLightNum] = Vector3.Normalize(Vector3.Transform(l.getLightDirection(), viewMatrix));
SpotLightAngleCos[spotLightNum] = (float)Math.Cos((double)(l.getLightAngleRad() / 2f));

在着色器中,如果光方向和光矢量之间的点积大于光的最大允许角度的余弦值,我不会点亮像素(一旦工作,就会更顺利地完成此操作) :

lightDirection = normalize(SpotLightPositionViewSpace[j] - pin.PositionViewSpace.xyz);

if (intensityBasedOnDistance > 0.0 
&& (intensity = max(dot(surfaceNormal, lightDirection), 0.0)) > 0.0 
&& dot(-lightDirection, SpotLightDirectionViewSpace[j]) > SpotLightAngleCos[j])
{
diffuseColor += float4(SpotLightColor[j] * intensity * intensityBasedOnDistance * SpotLightIntensity[j], 0.0);
}

【问题讨论】:

    标签: xna shader monogame hlsl lighting


    【解决方案1】:

    尝试了几个小时的改变

    SpotLightDirectionViewSpace[spotLightNum] = Vector3.Normalize(Vector3.Transform(l.getLightDirection(), viewMatrix));
    

    SpotLightDirectionViewSpace[spotLightNum] = Vector3.Normalize(Vector3.Transform(l.getForward(), viewMatrix.Rotation));
    

    解决了...不知道为什么,但现在可以了。

    如果有人能解释一下,我将不胜感激。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 2018-11-28
      • 1970-01-01
      • 2021-10-24
      • 1970-01-01
      相关资源
      最近更新 更多