Skip to content

Commit

Permalink
Merge pull request #137 from chemlab/outlinecustom
Browse files Browse the repository at this point in the history
Improved outline by adding color
  • Loading branch information
gabrielelanaro committed Sep 18, 2015
2 parents 2e46b9e + 8dcb956 commit 238e9bf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
15 changes: 10 additions & 5 deletions chemlab/graphics/postprocessing/outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import os

class OutlineEffect(object):
"""Add a black, cartoon-like outline.
"""Add a colored, cartoon-like outline.
This effect analyzes each point to be drawn and check if it's at a
point of discontinuity, either because there's a change in surface normal
Expand All @@ -27,11 +27,14 @@ class OutlineEffect(object):
Set the edge-determination test to both depth and normal
discontinuity or either one of the two.
color: 3d vectors
Set the color to the rgb value specified (each value between 0 and 1)
"""


def __init__(self, widget, kind='depthnormal'):
def __init__(self, widget, kind='depthnormal', color=(0, 0, 0)):
self.widget = widget
curdir = os.path.dirname(__file__)
vert = open(os.path.join(curdir, 'shaders', 'noeffect.vert')).read()
Expand All @@ -44,7 +47,7 @@ def __init__(self, widget, kind='depthnormal'):
raise Exception('The kind of outline should be choosen between depthnormal, depthonly and normalonly')

self.kind = kind

self.outline_color = np.array(color)
self.quad_program = shaders.compileProgram(vertex, fragment)

def render(self, fb, texturedict):
Expand All @@ -62,6 +65,8 @@ def render(self, fb, texturedict):
set_uniform(self.quad_program, 'inv_projection', 'mat4fv',
inv_projection)

set_uniform(self.quad_program, "outline_color", "3f", self.outline_color)

normal_id = glGetUniformLocation(self.quad_program, b"s_norm")
glUniform1i(normal_id, 0)

Expand Down Expand Up @@ -107,4 +112,4 @@ def render(self, fb, texturedict):
glDisableClientState(GL_VERTEX_ARRAY)

def on_resize(self, w, h):
pass
pass
3 changes: 2 additions & 1 deletion chemlab/graphics/postprocessing/shaders/outline.frag
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ uniform sampler2D s_color;
uniform vec2 texcoordOffset;
uniform mat4 inv_projection;
uniform int whichoutline; // 0 - depthnormal; 1 - depthonly; 0 - normalonly;
uniform vec3 outline_color;

vec2 offsets [8];

Expand Down Expand Up @@ -78,6 +79,6 @@ void main() {
illum = 1.0 - darkness_norm;
}

gl_FragColor.rgb = texture2D(s_color, pos).rgb * illum;
gl_FragColor.rgb = mix(outline_color.rgb, texture2D(s_color, pos).rgb, illum);
gl_FragColor.a = 1.0;
}
5 changes: 3 additions & 2 deletions tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ def test_outline():
sr = v.add_renderer(AtomRenderer, mol.r_array, mol.type_array,
'impostors', shading='toon')

v.add_post_processing(OutlineEffect, 'depthnormal')
#v.add_post_processing(OutlineEffect, 'depthnormal')
v.add_post_processing(OutlineEffect, 'depthnormal', color=[0, 0, 1])
v.add_post_processing(SSAOEffect, ssao_power=4.0)
v.add_post_processing(FXAAEffect)
v.add_post_processing(GammaCorrectionEffect)
Expand Down Expand Up @@ -539,4 +540,4 @@ def test_molecular_viewer():

v.run()



0 comments on commit 238e9bf

Please sign in to comment.