Commit b1c243fd authored by Deepak Surti's avatar Deepak Surti

Merge branch 'render-front-to-tex' into 'master'

Render front faces to texture

As per Kruger's paper, render front faces to texture and back faces use a VS that does the volume rendering.

See merge request !4
parents 7933913d c8d45585
......@@ -62,7 +62,7 @@ void main()
}
'''
back_cube_fs = '''
front_cube_fs = '''
#version 410
in vec4 vColor;
......@@ -74,14 +74,12 @@ void main()
}
'''
def make_back_cube():
def make_front_cube():
geometry = Geometry(vertices, colors, indices,
cube_vs, back_cube_fs, back=True)
cube_vs, front_cube_fs, front=True)
return geometry
front_cube_fs = '''
back_cube_fs = '''
#version 410
in vec4 vColor;
......@@ -94,15 +92,15 @@ out vec4 fragColor;
void main()
{
// start of ray
vec3 start = vColor.rgb;
// end of ray
vec3 end = vColor.rgb;
// calculate texture coords at fragment, which is a
// fraction of window coords
vec2 texc = gl_FragCoord.xy/uWinDims.xy;
// get end of ray = back-face color
vec3 end = texture(texBackFaces, texc).rgb;
// get start of ray = front-face color
vec3 start = texture(texBackFaces, texc).rgb;
// calculate ray direction
vec3 dir = end - start;
......@@ -144,7 +142,7 @@ void main()
}
'''
def make_front_cube():
def make_back_cube():
geometry = Geometry(vertices, colors, indices,
cube_vs, front_cube_fs)
cube_vs, back_cube_fs)
return geometry
......@@ -6,7 +6,7 @@ from PyQt5.QtGui import (QGuiApplication, QMatrix4x4, QOpenGLContext, QColor,
class Geometry(object):
def __init__(self, vertices, colors, indices, vs_str, fs_str, back=False):
def __init__(self, vertices, colors, indices, vs_str, fs_str, front=False):
self.vertices = vertices
self.vertex_count = len(vertices) / 3
self.colors = colors
......@@ -27,7 +27,7 @@ class Geometry(object):
self.tex_volume = 0
self.back = back
self.front = front
self.fbo = 0
self.fbo_tex = 0
......@@ -87,7 +87,7 @@ class Geometry(object):
self.program.link()
if self.back:
if self.front:
print 'Initialize FBO ...'
self.fbo = QOpenGLFramebufferObject(self.width, self.height)
self.fbo.setAttachment(QOpenGLFramebufferObject.Depth)
......@@ -106,14 +106,14 @@ class Geometry(object):
self.program.setUniformValue(p_mat, self.p_mat)
# enable face culling
if self.back: # implies back cube
if self.front: # implies front cube
gl.glFrontFace(gl.GL_CCW)
gl.glCullFace(gl.GL_FRONT)
gl.glCullFace(gl.GL_BACK)
gl.glEnable(gl.GL_CULL_FACE)
self.fbo.bind()
else: # implies front cube
else: # implies back cube
gl.glFrontFace(gl.GL_CCW)
gl.glCullFace(gl.GL_BACK)
gl.glCullFace(gl.GL_FRONT)
gl.glEnable(gl.GL_CULL_FACE)
win_dims = self.program.uniformLocation('uWinDims')
tex_back_faces = self.program.uniformLocation('texBackFaces')
......@@ -140,6 +140,6 @@ class Geometry(object):
self.program.release()
self.vao.release()
self.idx.release()
if self.back:
if self.front:
gl.glDisable(gl.GL_CULL_FACE)
self.fbo.release()
......@@ -5,17 +5,17 @@ class Scene(object):
def __init__(self, texture_loader=None):
self.texture_loader = texture_loader
self.back_cube = make_back_cube()
self.front_cube = make_front_cube()
self.back_cube = make_back_cube()
def initialize(self, parent, gl):
self.texture_loader.load_gl_3d_texture(gl)
self.back_cube.initialize(parent, gl)
print 'AFTER: FBO Texture: %s' % self.back_cube.fbo.texture()
self.front_cube.tex_volume = self.texture_loader.texture
self.front_cube.fbo_tex = self.back_cube.fbo.texture()
self.front_cube.initialize(parent, gl)
print 'AFTER: FBO Texture: %s' % self.front_cube.fbo.texture()
self.back_cube.tex_volume = self.texture_loader.texture
self.back_cube.fbo_tex = self.front_cube.fbo.texture()
self.back_cube.initialize(parent, gl)
def render(self, gl):
self.back_cube.render(gl)
self.front_cube.render(gl)
self.back_cube.render(gl)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment