查看: 818|回复: 0

hdr特效shader的texture2D纹理坐标计算是什么意思?

[复制链接]

该用户从未签到

发表于 2019-11-3 12:49:07 | 显示全部楼层 |阅读模式
  1.   //There seems to be a texture coordinate error...
  2.         "varying vec3 vLocalVertex;\n"
  3.                 "varying vec4 TextureCoord0;\n"

  4.                 "void main()\n"
  5.                 "{\n"
  6.                 "   vLocalVertex  = gl_Vertex;\n"
  7.                 "   TextureCoord0 = gl_TextureMatrix[0] * gl_MultiTexCoord0;\n"
  8.                 "   gl_Position   = ftransform();\n"
  9.                 "}\n"
  10.                 "\n"
  11.                 ,
  12.                 "uniform sampler2D default_map;\n"
  13.                 "varying vec4   TextureCoord0;\n"
  14.                 "varying vec3   vLocalVertex;\n"
  15.                 "uniform float  hdrExposure;\n"
  16.                 "uniform float  hdrGamma;\n"

  17.                 "vec3 decodeRGBE(vec4 rgba) \n"
  18.                 "{ \n"
  19.                 "   float f = pow(2.0, rgba.a * 255.0 - (128.0 + 8.0)); \n"
  20.                 "        return rgba.rgb * 255.0 * f; \n"
  21.                 "} \n"

  22.                 "vec3 toneMapHDR(vec3 rgb) \n"
  23.                 "{ \n"
  24.                 "         return pow(rgb * 1.0, 1.0 / vec3(2.2));\n"
  25.                 "} \n"

  26.                 "vec4 textureSphere(sampler2D texture,vec3 n) \n"
  27.                 "{ \n"
  28.                 "         const float PI =  3.14159;\n"
  29.                 "         float yaw = acos(n.y) / PI;\n"
  30.                 "         float pitch = (atan(n.x, n.z) + PI) / (2.0 * PI);\n"
  31.                 "         return texture2D(texture, vec2(pitch, yaw));\n"
  32.                 "} \n"

  33.                 "void main()\n"
  34.                 "{\n"
  35.                 "                vec3 normal = normalize(vLocalVertex.xyz);\n"
  36.                 "                vec3 c = toneMapHDR(decodeRGBE(textureSphere(default_map, normal)));\n"
  37.                 "            gl_FragColor = vec4(c, 1.0);\n"
  38.                 "}\n"
  39.                 "\n"
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表