opengl shader//内置函数fract浮点数如何转换成向量?

mirro 2018-10-12 10:31:29

// 改编过来的。
#ifdef GL_ES
precision highp float;
#endif

varying vec4 projectedPosition;

vec4 pack( float depth )
{
const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0,
256.0 * 256.0,
256.0,
1.0 );
const vec4 bitMsk = vec4( 0.0,
1.0 / 256.0,
1.0 / 256.0,
1.0 / 256.0 );
vec4 comp = fract( depth * bitSh );
comp -= comp.xxyz * bitMsk;
return comp;
}

void main( void )
{
float normalizedZ = projectedPosition.z / projectedPosition.w;
normalizedZ = ( normalizedZ + 1.0 ) / 2.0;
gl_FragColor = pack( normalizedZ );
}
...全文
506 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
schlafenhamster 2018-10-17
  • 打赏
  • 举报
回复
anyFloat fract(anyFloat x) 这个函数有矢量 版 的 吗 即
vec4 fract(vec4 x) ?
寻开心 2018-10-17
  • 打赏
  • 举报
回复
fract 不仅仅可以对float取小数部分,还可以对向量的每个分量分别取小数部分,看函数的原型
mirro 2018-10-16
  • 打赏
  • 举报
回复
引用 3 楼 schlafenhamster 的回复:
float depth
vec4 bitSh

depth * bitSh 也是 vec4

问题 是 fract ??
fract可以转化vec4向量呀……
schlafenhamster 2018-10-14
  • 打赏
  • 举报
回复
anyFloat fract(anyFloat x) ?
schlafenhamster 2018-10-14
  • 打赏
  • 举报
回复
float depth
vec4 bitSh

depth * bitSh 也是 vec4

问题 是 fract ??
mirro 2018-10-14
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903 的回复:
fract returns the fractional part of x. This is calculated as x - floor(x).

vec4 comp = fract( depth * bitSh );//vec4不是浮点数呀
zgl7903 2018-10-13
  • 打赏
  • 举报
回复
fract returns the fractional part of x. This is calculated as x - floor(x).

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧