Glsl per-Pixel Lighting + spot texture (spotlight texture)

Source: Internet
Author: User

 

The spotlight texture is the aperture of the spotlight that shines on the surface. Prepare a spot texture brightness map, use the projection texture method described in "glsl projective texture" to project the spot texture to the spotlight.

 

Unsigned char * pixels = (unsigned char *) malloc (64*64 );

For (Int J = 0; j <64; j ++ ){
For (INT I = 0; I <64; I ++ ){
Float x = (I/31.5f)-1;
Float y = (J/31.5f)-1;

Float ls = max (1-(x * x + y * Y), 0.0f );
Pixels [J * 64 + I] = (unsigned char) (255.0f * ls );
}
}

Texid_spot = gl_create_texture (64, 64, gl_luminance, pixels );

Glbindtexture (gl_texture_2d, texid_spot );

Gltexparameterf (gl_texture_2d, gl_texture_mag_filter, gl_linear );
Gltexparameterf (gl_texture_2d, gl_texture_min_filter, gl_linear );

Glteximage2d (gl_texture_2d, 0, gl_luminance8, 64,64, 0, gl_luminance, gl_unsigned_byte, pixels );

Glbindtexture (gl_texture_2d, 0 );

 

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.