快速8-bit通道的伪HDR的实现
2015-07-18 12:33
239 查看
作者Nhsoft
看了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);
}
以上是个GLSL代码:
翻译成CG也很简单地
made by Azure
//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;//看代码。。。。
float4 xposure(float4 cl,float e)
{
return ( exp(expfactor) - exp(expfactor-e)) * cl;
}
void main( float2 texcoord : TEXCOORD0
out float4 finalColor : COLOR)
{
float delp = blurfactor* cdelp;
float4 texColor = tex2D(texture, texcoord.x, texcoord.y);
//把当前位置的颜色和周围的做blur,算曝光度时候和算最后颜色结合的时候,权重是不同,
//最终的颜色是。。。。。
float4 color = texColor*2.0 / 22.0;
color += tex2D(texture,float2(texcoord.x+delp, texcoord.y+delp))*5.0 /22.0;
color += tex2D(texture,float2(texcoord.x+delp, texcoord.y- delp))*5.0 /22.0;
color += tex2D(texture,float2(texcoord.x- delp, texcoord.y- delp))*5.0 /22.0;
color += tex2D(texture,float2(texcoord.x- delp, texcoord.y+delp))*5.0 /22.0;
float e = color.r * 0.3 + color.g * 0.59 + color.b * 11;
//算出了亮度信息,
finalColor = xposure(texColor*sharpness + color*(1-sharpness),e);
}
看了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);
}
以上是个GLSL代码:
翻译成CG也很简单地
made by Azure
//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;//看代码。。。。
float4 xposure(float4 cl,float e)
{
return ( exp(expfactor) - exp(expfactor-e)) * cl;
}
void main( float2 texcoord : TEXCOORD0
out float4 finalColor : COLOR)
{
float delp = blurfactor* cdelp;
float4 texColor = tex2D(texture, texcoord.x, texcoord.y);
//把当前位置的颜色和周围的做blur,算曝光度时候和算最后颜色结合的时候,权重是不同,
//最终的颜色是。。。。。
float4 color = texColor*2.0 / 22.0;
color += tex2D(texture,float2(texcoord.x+delp, texcoord.y+delp))*5.0 /22.0;
color += tex2D(texture,float2(texcoord.x+delp, texcoord.y- delp))*5.0 /22.0;
color += tex2D(texture,float2(texcoord.x- delp, texcoord.y- delp))*5.0 /22.0;
color += tex2D(texture,float2(texcoord.x- delp, texcoord.y+delp))*5.0 /22.0;
float e = color.r * 0.3 + color.g * 0.59 + color.b * 11;
//算出了亮度信息,
finalColor = xposure(texColor*sharpness + color*(1-sharpness),e);
}
相关文章推荐
- 代理模式
- SQL 2008提供几种数据同步方式
- C语言简单实现计算字符个数的方法
- C++内存管理
- java事件处理机制的核心
- 如何进入游戏行业成为一个程序员
- Linux 注意
- cv::Mat访问元素的方法
- java中数组的3中初始化方法
- codevs1027
- VS2013与VS2010的转换
- try-catch-finally陷阱
- u3d 当你发现一个函数被调用,但是完全找不到是谁调用的时候
- My first CSDN
- hashCode与equals的区别与联系
- HYSBZ 1012 最大数maxnumber
- thinkphp的知识点
- 操作系统的启动
- codevs1026
- VC 各种情况下的窗口句柄的获取