BillBoard shader实现

    技术2025-01-17  7

    BillBoard shader实现 当前效果是Quad始终处于相机正前方, 而不只是方向垂直。去掉m_vOffset就是一般意义上的billboard了。 Vert程序 uniform mat4 g_WorldViewProjectionMatrix; uniform mat4 g_WorldMatrix; uniform mat4 g_ProjectionMatrix; uniform mat4 g_ViewMatrix; uniform vec3 m_vOffset; uniform vec3 m_CamPos; attribute vec3 inPosition; attribute vec2 inTexCoord; varying vec2 texCoord; void main(){ //    gl_Position =   g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);     //  billboard实现     // Quad中心点的世界坐标     vec4 vCenter = g_WorldMatrix * vec4(0,0,0,1) + vec4(m_vOffset, 0) ;     // Quad自身坐标系的Up方向     vec3 vUp = vec3(0,1,0);      // 中心点到相机的LookAt方向     vec3 vEye = normalize( m_CamPos  - vCenter);     // Quad自身坐标系的Right方向     vec3 vRight = cross(vUp, vEye);     vUp = normalize(cross(vEye, vRight));     vRight = normalize(vRight);     // 根据纹理坐标偏移,10为Quad的scale size     vec3 vTmpPos = vCenter.xyz;     vTmpPos += (inTexCoord.x - 0.5) *10 * vRight;     vTmpPos += (inTexCoord.y - 0.5) *10 * vUp;     gl_Position = g_ProjectionMatrix * g_ViewMatrix * vec4(( vTmpPos), 1);     texCoord = inTexCoord;   } Frag程序 varying vec2 texCoord; uniform sampler2D m_ColorMap; uniform vec4 m_Color; void main(){     gl_FragColor= texture2D(m_ColorMap, texCoord); }

    最新回复(0)