aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-09-14 11:57:44 +0200
committerAdrian Kummerlaender2019-09-14 11:57:44 +0200
commit67c063fda67a4b6379b40a5c41ddba9eec3329ad (patch)
tree25488740a80dbb7e76f585ee08ab38a7d6cf45c3
parentbf728d8a33b57b2b775b9a1c3bc8f2d84388acd6 (diff)
downloadsymlbm_playground-67c063fda67a4b6379b40a5c41ddba9eec3329ad.tar
symlbm_playground-67c063fda67a4b6379b40a5c41ddba9eec3329ad.tar.gz
symlbm_playground-67c063fda67a4b6379b40a5c41ddba9eec3329ad.tar.bz2
symlbm_playground-67c063fda67a4b6379b40a5c41ddba9eec3329ad.tar.lz
symlbm_playground-67c063fda67a4b6379b40a5c41ddba9eec3329ad.tar.xz
symlbm_playground-67c063fda67a4b6379b40a5c41ddba9eec3329ad.tar.zst
symlbm_playground-67c063fda67a4b6379b40a5c41ddba9eec3329ad.zip
Draw 3d geometry outline
-rw-r--r--ldc_3d_gl_interop.py66
1 files changed, 53 insertions, 13 deletions
diff --git a/ldc_3d_gl_interop.py b/ldc_3d_gl_interop.py
index 483ea1a..7fb5d5c 100644
--- a/ldc_3d_gl_interop.py
+++ b/ldc_3d_gl_interop.py
@@ -15,11 +15,11 @@ from OpenGL.GL import shaders
from pyrr import matrix44
lattice_x = 64
-lattice_y = 32
-lattice_z = 32
+lattice_y = 64
+lattice_z = 64
updates_per_frame = 20
-particle_count = 50000
+particle_count = 10000
lid_speed = 0.001
relaxation_time = 0.515
@@ -55,7 +55,7 @@ def get_projection(width, height):
projection = matrix44.create_perspective_projection(45.0, width/height, 0.1, 1000.0)
look = matrix44.create_look_at(
- eye = [lattice_x/2, -2*lattice_y, lattice_z/2],
+ eye = [lattice_x/2, -2*lattice_y, 1.2*lattice_z],
target = [lattice_x/2, lattice_y/2, lattice_z/2],
up = [0, 0, 1])
rotate = matrix44.create_from_axis_rotation(axis=[0,1,0], theta=0.2)
@@ -81,12 +81,11 @@ lbm = LBM(D3Q19)
window = glut_window(fullscreen = False)
-vertex_shader = shaders.compileShader(Template("""
+particle_shader = shaders.compileShader(Template("""
#version 430
layout (location=0) in vec4 particles;
-
-out vec3 color;
+ out vec3 color;
uniform mat4 projection;
@@ -109,6 +108,19 @@ void main() {
color = fire(1.0-particles[3]);
}""").substitute({}), GL_VERTEX_SHADER)
+vertex_shader = shaders.compileShader(Template("""
+#version 430
+
+layout (location=0) in vec4 vertex;
+ out vec3 color;
+
+uniform mat4 projection;
+
+void main() {
+ gl_Position = projection * vertex;
+ color = vec3(1.0,1.0,1.0);
+}""").substitute({}), GL_VERTEX_SHADER)
+
fragment_shader = shaders.compileShader("""
#version 430
@@ -118,8 +130,10 @@ void main(){
gl_FragColor = vec4(color.xyz, 0.0);
}""", GL_FRAGMENT_SHADER)
-shader_program = shaders.compileProgram(vertex_shader, fragment_shader)
-projection_id = shaders.glGetUniformLocation(shader_program, 'projection')
+particle_program = shaders.compileProgram(particle_shader, fragment_shader)
+projection_id = shaders.glGetUniformLocation(particle_program, 'projection')
+
+geometry_program = shaders.compileProgram(vertex_shader, fragment_shader)
lattice = Lattice(
descriptor = D3Q19,
@@ -139,9 +153,9 @@ particles = Particles(
lattice.queue,
lattice.memory.float_type,
numpy.mgrid[
- 6*lattice.geometry.size_x//8:7*lattice.geometry.size_x//8:10j,
- lattice.geometry.size_y//8:7*lattice.geometry.size_y//8:particle_count/100j,
- 6*lattice.geometry.size_z//8:7*lattice.geometry.size_z//8:10j,
+ 8*lattice.geometry.size_x//10:9*lattice.geometry.size_x//10:10j,
+ lattice.geometry.size_y//10:9*lattice.geometry.size_y//10:particle_count/100j,
+ 8*lattice.geometry.size_z//10:9*lattice.geometry.size_z//10:10j,
].reshape(3,-1).T)
def on_display():
@@ -160,13 +174,39 @@ def on_display():
particles.gl_particles.bind()
- shaders.glUseProgram(shader_program)
+ shaders.glUseProgram(particle_program)
glUniformMatrix4fv(projection_id, 1, False, numpy.ascontiguousarray(projection))
glVertexPointer(4, GL_FLOAT, 0, particles.gl_particles)
glPointSize(point_size)
glEnable(GL_POINT_SMOOTH)
glDrawArrays(GL_POINTS, 0, particles.count)
+ shaders.glUseProgram(geometry_program)
+ glUniformMatrix4fv(projection_id, 1, False, numpy.ascontiguousarray(projection))
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
+ glBegin(GL_POLYGON)
+ glVertex3f(0,0,0)
+ glVertex3f(lattice_x,0,0)
+ glVertex3f(lattice_x,lattice_y,0)
+ glVertex3f(0,lattice_y,0)
+ glEnd()
+ glBegin(GL_POLYGON)
+ glVertex3f(0,0,lattice_z)
+ glVertex3f(lattice_x,0,lattice_z)
+ glVertex3f(lattice_x,lattice_y,lattice_z)
+ glVertex3f(0,lattice_y,lattice_z)
+ glEnd()
+ glBegin(GL_LINES)
+ glVertex3f(0,0,0)
+ glVertex3f(0,0,lattice_z)
+ glVertex3f(lattice_x,0,0)
+ glVertex3f(lattice_x,0,lattice_z)
+ glVertex3f(lattice_x,lattice_y,0)
+ glVertex3f(lattice_x,lattice_y,lattice_z)
+ glVertex3f(0,lattice_y,0)
+ glVertex3f(0,lattice_y,lattice_z)
+ glEnd()
+
glutSwapBuffers()
def on_reshape(width, height):