快速8-bit通道的伪HDR的实现

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

快速8-bit通道的伪HDR

http://bbs.gameres.com/showthread.asp?threadid=23298

看了Hugo老师的文章,试验了一下.

写了一个Fragment shader,用ShaderDesigner写的.

fakehdr.frag

//http://freespace.virgin.net/hugo.elias/graphics/x_posure.htm

//Hugo老师指出,曝光度是根据进入镜头的光线来决定的。

//在我们渲染完一个图象后,应该采用float16格式来保存。

//但是如果对于一个不是float16格式的Rendertarget,我们可以取

//周围的颜色平均后作为决定曝光度的因子,

//以下的shader代码应该说是非常偷工减料的。但是效果看上去还可以。

uniform sampler2D texture;

const float blurfactor = 12.5;//blur度,就是把多远处的像素取过来

const float expfactor = 0.8;//曝光度

const float cdelp = 0.0009765625;//一个像素对应的float大小。我用的纹理是1024,自己去算

const float sharpness = 0.8;//看代码。。。。

vec4 xposure(vec4 cl,float e)

{

return ( exp(expfactor) - exp(expfactor-e)) * cl;

}

void main()

{

float delp = blurfactor* cdelp;

vec4 texColor = texture2D(texture,vec2(gl_TexCoord[0].s ,gl_TexCoord[0].t ));

//把当前位置的颜色和周围的做blur,算曝光度时候和算最后颜色结合的时候,权重是不同,

//最终的颜色是。。。。。

vec4 color = texColor*2.0 / 22.0;

color += texture2D(texture,vec2(gl_TexCoord[0].s+delp,gl_TexCoord[0].t+delp))*5.0 /22.0;

color += texture2D(texture,vec2(gl_TexCoord[0].s+delp,gl_TexCoord[0].t-delp))*5.0 /22.0;

color += texture2D(texture,vec2(gl_TexCoord[0].s-delp,gl_TexCoord[0].t-delp))*5.0 /22.0;

color += texture2D(texture,vec2(gl_TexCoord[0].s-delp,gl_TexCoord[0].t+delp))*5.0 /22.0;

float e = color.r * 0.3 + color.g * 0.59 + color.b * 11;

//算出了亮度信息,

gl_FragColor = xposure(texColor*sharpness + color*(1-sharpness),e);

}

Blog 上不知道怎么贴图,详细见

http://bbs.chinagamedev.net/showthread.php?t=9679

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航