Mercurial > touhou
comparison pytouhou/ui/gamerenderer.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 | 1c773544eaeb |
children | 705870483559 |
comparison
equal
deleted
inserted
replaced
400:7aa70f0def38 | 401:3ce4065840e9 |
---|---|
69 elif back is not None: | 69 elif back is not None: |
70 x, y, z = back.position_interpolator.values | 70 x, y, z = back.position_interpolator.values |
71 dx, dy, dz = back.position2_interpolator.values | 71 dx, dy, dz = back.position2_interpolator.values |
72 fog_b, fog_g, fog_r, fog_start, fog_end = back.fog_interpolator.values | 72 fog_b, fog_g, fog_r, fog_start, fog_end = back.fog_interpolator.values |
73 | 73 |
74 # Those two lines may come from the difference between Direct3D and | |
75 # OpenGL’s distance handling. The first one seem to calculate fog | |
76 # from the eye, while the second does that starting from the near | |
77 # plane. | |
78 #TODO: investigate, and use a variable to keep the near plane | |
79 # distance at a single place. | |
80 fog_start -= 101010101./2010101. | |
81 fog_end -= 101010101./2010101. | |
82 | |
74 model = Matrix() | 83 model = Matrix() |
75 model.data[3] = [-x, -y, -z, 1] | 84 model.data[3] = [-x, -y, -z, 1] |
76 view = self.setup_camera(dx, dy, dz) | 85 view = self.setup_camera(dx, dy, dz) |
77 | 86 model_view_projection = model * view * self.proj |
78 glFogi(GL_FOG_MODE, GL_LINEAR) | 87 mvp = model_view_projection.get_c_data() |
79 glFogf(GL_FOG_START, fog_start) | |
80 glFogf(GL_FOG_END, fog_end) | |
81 glFogfv(GL_FOG_COLOR, (GLfloat * 4)(fog_r / 255., fog_g / 255., fog_b / 255., 1.)) | |
82 | 88 |
83 if self.use_fixed_pipeline: | 89 if self.use_fixed_pipeline: |
90 glMatrixMode(GL_MODELVIEW) | |
91 glLoadMatrixf(mvp) | |
92 | |
84 glEnable(GL_FOG) | 93 glEnable(GL_FOG) |
85 | 94 glFogi(GL_FOG_MODE, GL_LINEAR) |
86 model_view_projection = model * view * self.proj | 95 glFogf(GL_FOG_START, fog_start) |
87 glMatrixMode(GL_MODELVIEW) | 96 glFogf(GL_FOG_END, fog_end) |
88 glLoadMatrixf(model_view_projection.get_c_data()) | 97 glFogfv(GL_FOG_COLOR, (GLfloat * 4)(fog_r / 255., fog_g / 255., fog_b / 255., 1.)) |
89 else: | 98 else: |
90 self.background_shader.bind() | 99 self.background_shader.bind() |
100 self.background_shader.uniform_matrixf('mvp', mvp) | |
91 | 101 |
92 model_view = model * view | 102 self.background_shader.uniformf('fog_scale', 1. / (fog_end - fog_start)) |
93 self.background_shader.uniform_matrixf('model_view', model_view.get_c_data()) | 103 self.background_shader.uniformf('fog_end', fog_end) |
94 self.background_shader.uniform_matrixf('projection', self.proj.get_c_data()) | 104 self.background_shader.uniformf('fog_color', fog_r / 255., fog_g / 255., fog_b / 255., 1.) |
95 | 105 |
96 self.render_background() | 106 self.render_background() |
97 else: | 107 else: |
98 glClear(GL_COLOR_BUFFER_BIT) | 108 glClear(GL_COLOR_BUFFER_BIT) |
99 | 109 |