【问题标题】:Shadow map matrix transformation阴影贴图矩阵变换
【发布时间】:2018-11-07 01:20:57
【问题描述】:

我似乎无法理解这些阴影贴图矩阵。当光线角度大约 45 度到 0,0,0 时,它的效果很好。例如,如果太阳角度相对于 x,z 高 (y)。阴影与模型不一致。 (-7,-10,7) 或 (-9,-10,0) 的灯光位置可以正常工作。 (-1,-10,1) 是倾斜的。这是我的代码示例。 -x 左,-y 上,-z 远。

public Vector3f cameraPosition = new Vector3f(0f, -10f, 7f);
public float[] lightPosition = new float[]{-7f, -10.0f, 7f}

将对象绘制到阴影贴图纹理

Matrix.setLookAtM(sunMatrix, 0, -lightPosition[0], lightPosition[1], lightPosition[2],
            0, 0, 0,
            0f, 1f, 0f);

    //projection matrix plus sun
    float width = (globals.glScreenSize/2);
    float height = (globals.glScreenSize/2);
    Matrix.orthoM(projectionMatrix, 0, -width, width,
            -height, height,
            -1f, 100f);
    tempMatrix = new float[16];
    Matrix.multiplyMM(tempMatrix, 0, projectionMatrix, 0, sunMatrix, 0);//add camera matrix to perspective
    projectionMatrix = tempMatrix.clone();

    //translate
    Matrix.setIdentityM(modelMatrix, 0);//set to 0

    //translate
    Matrix.translateM(modelMatrix, 0, modelPos.location.x,
            -(modelPos.location.y),
            modelPos.location.z);//move

    //rotate
    Matrix.rotateM(modelMatrix, 0, modelPos.angles.x, 1f, 0f, 0f);
    Matrix.rotateM(modelMatrix, 0, -modelPos.angles.y, 0f, 1f, 0f);
    Matrix.rotateM(modelMatrix, 0, -modelPos.angles.z, 0f, 0f, 1f);

    //scale
    Matrix.scaleM(modelMatrix, 0, modelPos.scales.x,
            modelPos.scales.y,
            modelPos.scales.z);//scale


    Matrix.multiplyMM(viewProjMatrix, 0, projectionMatrix, 0, modelMatrix, 0);
    //Matrix.multiplyMM(projectionMatrix, 0, globals.viewProjMatrix, 0, modelMatrix, 0);//perspective/model/view projection matrix
    finalMatrix = viewProjMatrix.clone();//final matrix created

绕y轴旋转并在屏幕上绘制阴影贴图

Matrix.setLookAtM(modelMatrix, 0, 0f, 0f, 0f, 
    globals.lightPosition[0], 0f, -globals.lightPosition[2],
                              0f, 1f, 0f);




    //scale
    Matrix.scaleM(modelMatrix, 0, scale.x, scale.y, scale.y);//scale

    Matrix.multiplyMM(projectionMatrix, 0, globals.viewProjMatrix, 0, modelMatrix, 0);//projection matrix

    finalMatrix = projectionMatrix.clone();//final matrix created

enter image description here

感谢您的帮助,

标准

【问题讨论】:

    标签: dictionary matrix shadow


    【解决方案1】:

    我变了,

    浮动高度 = (globals.glScreenSize/2) * Math.abs(lightPos.y);

    阴影现在都与模型对齐。如果您正在寻找一个简单的阴影贴图和 obj 加载器示例,请查看 https://github.com/Normfly/myOpenglES20

    编码愉快,

    标准

    【讨论】:

      猜你喜欢
      • 2015-03-31
      • 1970-01-01
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-06
      • 1970-01-01
      相关资源
      最近更新 更多