comparison pytouhou/ui/opengl/shaders/eosd.py @ 513:5e3e0b09a531

Move the OpenGL backend to its own package.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 05 Dec 2013 02:16:31 +0100
parents pytouhou/ui/shaders/eosd.py@a71b912b45b7
children 0f2af7552462
comparison
equal deleted inserted replaced
512:b39ad30c6620 513:5e3e0b09a531
1 # -*- encoding: utf-8 -*-
2 ##
3 ## Copyright (C) 2012 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
4 ##
5 ## This program is free software; you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published
7 ## by the Free Software Foundation; version 3 only.
8 ##
9 ## This program is distributed in the hope that it will be useful,
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ## GNU General Public License for more details.
13 ##
14
15
16 from ..shader import Shader
17
18
19 class GameShader(Shader):
20 def __init__(self):
21 Shader.__init__(self, ['''
22 #version 120
23
24 attribute vec3 in_position;
25 attribute vec2 in_texcoord;
26 attribute vec4 in_color;
27
28 uniform mat4 mvp;
29
30 varying vec2 texcoord;
31 varying vec4 color;
32
33 void main()
34 {
35 gl_Position = mvp * vec4(in_position, 1.0);
36 texcoord = in_texcoord;
37 color = in_color;
38 }
39 '''], ['''
40 #version 120
41
42 varying vec2 texcoord;
43 varying vec4 color;
44
45 uniform sampler2D color_map;
46
47 void main()
48 {
49 gl_FragColor = texture2D(color_map, texcoord) * color;
50 }
51 '''])
52
53
54 class BackgroundShader(Shader):
55 def __init__(self):
56 Shader.__init__(self, ['''
57 #version 120
58
59 attribute vec3 in_position;
60 attribute vec2 in_texcoord;
61 attribute vec4 in_color;
62
63 uniform mat4 mvp;
64
65 varying vec2 texcoord;
66 varying vec4 color;
67
68 void main()
69 {
70 gl_Position = mvp * vec4(in_position, 1.0);
71 texcoord = in_texcoord;
72 color = in_color;
73 }
74 '''], ['''
75 #version 120
76
77 varying vec2 texcoord;
78 varying vec4 color;
79
80 uniform sampler2D color_map;
81 uniform float fog_scale;
82 uniform float fog_end;
83 uniform vec4 fog_color;
84
85 void main()
86 {
87 vec4 temp_color = texture2D(color_map, texcoord) * color;
88 float depth = gl_FragCoord.z / gl_FragCoord.w;
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);
91 }
92 '''])
93
94
95 class PassthroughShader(Shader):
96 def __init__(self):
97 Shader.__init__(self, ['''
98 #version 120
99
100 attribute vec2 in_position;
101 attribute vec2 in_texcoord;
102
103 uniform mat4 mvp;
104
105 varying vec2 texcoord;
106
107 void main()
108 {
109 gl_Position = mvp * vec4(in_position, 0.0, 1.0);
110 texcoord = in_texcoord;
111 }
112 '''], ['''
113 #version 120
114
115 varying vec2 texcoord;
116
117 uniform sampler2D color_map;
118
119 void main()
120 {
121 gl_FragColor = texture2D(color_map, texcoord);
122 }
123 '''])