Implementation of pseudo HDR for quick 8-bit Channels

Source: Internet
Author: User
Quick 8-bit pseudo HDR Http://bbs.gameres.com/showthread.asp? Threadid = 23298

I read the document from teacher Hugo and tried it.
Write a fragment shader, written in shaderdesigner.

Fakehdr. Frag

// Http://freespace.virgin.net/hugo.elias/graphics/x_posure.htm
// Teacher Hugo pointed out that the exposure is determined by the light in the camera.
// After an image is rendered, it should be saved in the float16 format.
// However, if an rendertarget is not in float16 format
// The average surrounding color is used as the factor to determine the exposure,
// The following shader code should be said to be very cost-effective. But the effect looks okay.
Uniform sampler2d texture;
Const float blurfactor = 12.5; // blur level, that is, to retrieve pixels from multiple distances
Const float expfactor = 0.8; // exposure
Const float cdelp = 0.0009765625; // float size of a pixel. The texture I use is 1024. Calculate it by yourself.
Const float sharpness = 0.8; // read the code ....

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 ));
// Make the color of the current position and the surrounding blur. When the impression is calculated and the final color is combined, the weight is different,
// The final color is .....
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;
// Calculates the brightness,
Gl_fragcolor = xposure (texcolor * sharpness + color * (1-sharpness), e );
}

I don't know how to map images on the blog. For details, see
Http://bbs.chinagamedev.net/showthread.php? T = 9679

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.