zoukankan      html  css  js  c++  java
  • demo的凹凸贴图效果

    图1.凹凸贴图开启的效果

    图2.不使用凹凸贴图

    要想使用凹凸贴图,必须计算切线空间(纹理空间)的切线和副法线,否则不能正确的得到光照值,计算切线空间我使用的计算代码如下:

    Vector3f vCurVertexPosi( pVBBump[nCurVertexIndex].fPositionX, pVBBump[nCurVertexIndex].fPositionY, pVBBump[nCurVertexIndex].fPositionZ );
    Vector3f vCampVertexPosi( pVBBump[nCampVertexIndex].fPositionX, pVBBump[nCampVertexIndex].fPositionY, pVBBump[nCampVertexIndex].fPositionZ );
    Vector3f vCurVertexNormal( pVBBump[nCurVertexIndex].fNormalX, pVBBump[nCurVertexIndex].fNormalY, pVBBump[nCurVertexIndex].fNormalZ );
    Vector3f vTangent = (vCampVertexPosi-vCurVertexPosi).UNIT();
    Vector3f vTangentTemp = (vTangent^vCurVertexNormal).UNIT();
    vTangent = vCurVertexNormal^vTangentTemp;
    float fDifferU = pVBBump[nCampVertexIndex].fTextureU - pVBBump[nCurVertexIndex].fTextureU;
    float fDifferV = pVBBump[nCampVertexIndex].fTextureV - pVBBump[nCurVertexIndex].fTextureV;
    Vector3f vNormalU = ( vTangent*fDifferU + vTangentTemp*fDifferV ).UNIT();
    Vector3f vNormalV = vCurVertexNormal^vNormalU;
    pVBBump[nCurVertexIndex].fNormalUX = vNormalU.X;
    pVBBump[nCurVertexIndex].fNormalUY = vNormalU.Y;
    pVBBump[nCurVertexIndex].fNormalUZ = vNormalU.Z;
    pVBBump[nCurVertexIndex].fNormalVX = vNormalV.X;
    pVBBump[nCurVertexIndex].fNormalVY = vNormalV.Y;
    pVBBump[nCurVertexIndex].fNormalVZ = vNormalV.Z;

    其中vCurVertexPosi是当前需要计算切线空间的顶点vCampVertexPosi是相邻的顶点,用来比较相对纹理坐标“^”表示向量积UINT方法是将向量单位化,实现后的效果如图1,图2显示的是没有使用凹凸纹理的效果

  • 相关阅读:
    c语言命名规则 [转载]
    [转贴]C编译过程概述
    [转贴]漫谈C语言及如何学习C语言
    Semaphore源码分析
    如何快速转行大数据
    web前端到底怎么学?
    Code Review怎样做好
    SDK与API的理解
    分析消费者大数据
    程序员的搞笑段子
  • 原文地址:https://www.cnblogs.com/crown20/p/2218266.html
Copyright © 2011-2022 走看看