File: BlurredMipmapDemoShader.frag.txt

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (41 lines) | stat: -rw-r--r-- 1,447 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* BlurredMipmapDemoShader.frag.txt
 * Shader used for BlurredMipmapDemo.m
 *
 * This shader computes the level of resolution for each output texel
 * during Screen('DrawTexture') of the video image texture. Resolution
 * directly depends on radial distance to the provided simulated center of gaze.
 *
 * Resolution level is used to determine the mip-map miplevel (lod) to use for
 * lookup of the mip-map filtered texel in the images mipmap pyramid.
 *
 * (C) 2012 Mario Kleiner - Licensed under MIT license.
 *
 */

#extension GL_ARB_shader_texture_lod : enable

/* Image is the mip-mapped texture with the image resolution pyramid: */
uniform sampler2D Image;

/* Passed from vertex shader: */
varying vec4  baseColor;
varying vec2  gazePosition;
varying float gazeRadius;

void main(void)
{
    /* Output pixel position in absolute window coordinates: */
    vec2 outpos = gl_FragCoord.xy;

    /* Compute distance to center of gaze, normalized to units of gazeRadius: */
    /* We take log2 of it, because lod selects mip-level, which selects for a */
    /* 2^lod decrease in resolution: */
    float lod = log2(distance(outpos, gazePosition) / gazeRadius);

    /* Lookup texel color in image pyramid at input texture coordinate and
     * specific mip-map level 'lod': */
    vec4 texel = texture2DLod(Image, gl_TexCoord[0].st, lod);

    /* Apply modulation baseColor and write to framebuffer: */
    gl_FragColor = texel * baseColor;
}