实例介绍
【实例截图】
【核心代码】
precision mediump float;
//uniform sampler2D usTexture;
varying vec2 vTexCoord;
//uniform int isHighPrecision;
uniform sampler2D heightCurrentSampler;
uniform float fNormalScale;
//uniform vec4 texture_size;
uniform float inverseViewportWidth;
uniform float inverseViewportHeight;
float DecodeHeightmap(vec4 heightmap)
{
vec4 table;
//if ( isHighPrecision == 1 )
// table = vec4(1.0, -1.0, 1.0/256.0, -1.0/256.0);
//else
table = vec4(1.0, -1.0, 0.0, 0.0);
return dot(heightmap, table);
}
float DecodeHeightmap(sampler2D heightmapSampler, vec2 texcoord)
{
vec4 heightmap = texture2D(heightmapSampler, texcoord);
return DecodeHeightmap(heightmap);
}
void main() {
vec2 offset[4];
offset[0] = vec2(-1.0, 0.0);
offset[1] = vec2( 1.0, 0.0);
offset[2] = vec2( 0.0,-1.0);
offset[3] = vec2( 0.0, 1.0);
vec2 inverseViewportSize = vec2(inverseViewportWidth, inverseViewportHeight);
float fHeightL = DecodeHeightmap(heightCurrentSampler, vTexCoord offset[0]*inverseViewportSize);
float fHeightR = DecodeHeightmap(heightCurrentSampler, vTexCoord offset[1]*inverseViewportSize);
float fHeightT = DecodeHeightmap(heightCurrentSampler, vTexCoord offset[2]*inverseViewportSize);
float fHeightB = DecodeHeightmap(heightCurrentSampler, vTexCoord offset[3]*inverseViewportSize);
//vec3 n = vec3(fHeightR - fHeightL,fHeightB - fHeightT,fNormalScale);
//vec3 normal = (n 1.0) * 0.5;
gl_FragColor = vec4(fHeightR - fHeightL, fHeightB - fHeightT, fNormalScale, 1.0);
/*
//float s_offset = (fHeightB - fHeightT) / 2048.0;
//float t_offset = (fHeightL - fHeightR) / 2048.0;
float s_offset = (fHeightB - fHeightT) / 1.0;
float t_offset = (fHeightL - fHeightR) / 1.0;
float clampFactor = 0.5;
s_offset = (s_offset < -clampFactor) ? -clampFactor : s_offset;
t_offset = (t_offset < -clampFactor) ? -clampFactor : t_offset;
s_offset = (s_offset > clampFactor) ? clampFactor : s_offset;
t_offset = (t_offset > clampFactor) ? clampFactor : t_offset;
gl_FragColor = vec4(s_offset, t_offset, 0.0, 0.0);
*/
}
标签: shader
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)