comparison pytouhou/ui/shaders/eosd.py @ 401:3ce4065840e9

Calculate the fog per-fragment and remove the fixed-pipeline glFog* functions; now both vertex shaders are the same.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 14 Feb 2013 20:07:23 +0100
parents 346614f788f1
children a71b912b45b7
comparison
equal deleted inserted replaced
400:7aa70f0def38 401:3ce4065840e9
58 58
59 attribute vec3 in_position; 59 attribute vec3 in_position;
60 attribute vec2 in_texcoord; 60 attribute vec2 in_texcoord;
61 attribute vec4 in_color; 61 attribute vec4 in_color;
62 62
63 uniform mat4 model_view; 63 uniform mat4 mvp;
64 uniform mat4 projection;
65 64
66 varying vec2 texcoord; 65 varying vec2 texcoord;
67 varying vec4 color; 66 varying vec4 color;
68 varying float fog_density;
69 67
70 void main() 68 void main()
71 { 69 {
72 vec4 position = model_view * vec4(in_position, 1.0); 70 gl_Position = mvp * vec4(in_position, 1.0);
73 texcoord = in_texcoord; 71 texcoord = in_texcoord;
74 color = in_color; 72 color = in_color;
75
76 float fog_position = -position.z / position.w;
77 fog_density = clamp((gl_Fog.end - fog_position) * gl_Fog.scale, 0.0f, 1.0f);
78
79 gl_Position = projection * position;
80 } 73 }
81 '''], [''' 74 '''], ['''
82 #version 120 75 #version 120
83 76
84 varying vec2 texcoord; 77 varying vec2 texcoord;
85 varying vec4 color; 78 varying vec4 color;
86 varying float fog_density;
87 79
88 uniform sampler2D color_map; 80 uniform sampler2D color_map;
81 uniform float fog_scale;
82 uniform float fog_end;
83 uniform vec4 fog_color;
89 84
90 void main() 85 void main()
91 { 86 {
92 vec4 temp_color = texture2D(color_map, texcoord) * color; 87 vec4 temp_color = texture2D(color_map, texcoord) * color;
93 gl_FragColor = mix(gl_Fog.color, temp_color, fog_density); 88 float depth = gl_FragCoord.z / gl_FragCoord.w;
94 gl_FragColor.a = temp_color.a; 89 float fog_density = clamp((fog_end - depth) * fog_scale, 0.0f, 1.0f);
90 gl_FragColor = vec4(mix(fog_color, temp_color, fog_density).rgb, temp_color.a);
95 } 91 }
96 ''']) 92 '''])