WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Crosshatch Post-Processing Effect give away (https://forum.worldviz.com/showthread.php?t=5809)

Vaquero 08-03-2016 09:48 PM

Crosshatch Post-Processing Effect give away
 
He there!
As I was digging more into GLSL shader programming and its usage inside Vizard, I implemented the code for a crosshatch post-processing effect as a practice. But I thought, maybe it's useful for anybody, so I share it here.
It also demonstrates how to partially overlay the original image.

Vizard Script:
Code:

"""
Crosshatch Post Processing Effect
with adjustable split screen.
"""

import viz
viz.go()

import vizcam
vizcam.PivotNavigate(center=[0,1,0],distance=10)

viz.add('piazza.osgb')

import vizinfo
# Setup info panel
info = vizinfo.InfoPanel()

import vizfx.postprocess

class CrosshatchEffect(vizfx.postprocess.BaseShaderEffect):
       
        def _getFragmentCode(self):
                return """
                uniform sampler2D vizpp_InputTex;
                uniform float scale;
                uniform float vx_offset;
                uniform float hatch_y_offset; // 5.0
                uniform float lum_threshold_1; // 1.0
                uniform float lum_threshold_2; // 0.7
                uniform float lum_threshold_3; // 0.5
                uniform float lum_threshold_4; // 0.3
                void main()
                {
                  vec2 uv = gl_TexCoord[0].xy;
                 
                  vec3 tc = vec3(1.0, 0.0, 0.0);
                  if (uv.x < (vx_offset-0.005))
                  {
                    float lum_r = texture2D(vizpp_InputTex, uv).r * 0.2126;
                        float lum_g = texture2D(vizpp_InputTex, uv).g*0.7152;
                        float lum_b = texture2D(vizpp_InputTex, uv).b*0.0722;
                        float lum = scale * length(lum_r + lum_g + lum_b);
                        tc = vec3(1.0, 1.0, 1.0);
                 
                        if (lum < lum_threshold_1)
                        {
                          if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0)
                                tc = vec3(0.0, 0.0, 0.0);
                        } 
                 
                        if (lum < lum_threshold_2)
                        {
                          if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0)
                                tc = vec3(0.0, 0.0, 0.0);
                        } 
                 
                        if (lum < lum_threshold_3)
                        {
                          if (mod(gl_FragCoord.x + gl_FragCoord.y - hatch_y_offset, 10.0) == 0.0)
                                tc = vec3(0.0, 0.0, 0.0);
                        } 
                 
                        if (lum < lum_threshold_4)
                        {
                          if (mod(gl_FragCoord.x - gl_FragCoord.y - hatch_y_offset, 10.0) == 0.0)
                                tc = vec3(0.0, 0.0, 0.0);
                        }
                  }
                  else if (uv.x>=(vx_offset+0.005))
                  {
                        tc = texture2D(vizpp_InputTex, uv).rgb;
                  }
                 
                  gl_FragColor = vec4(tc, 1.0);
                }
                """
       
        def _createUniforms(self):
                self.uniforms.addFloat('scale',1.0)
                self.uniforms.addFloat('vx_offset',0.5)
                self.uniforms.addFloat('hatch_y_offset',5.0)
                self.uniforms.addFloat('lum_threshold_1',1.0)
                self.uniforms.addFloat('lum_threshold_2',0.7)
                self.uniforms.addFloat('lum_threshold_3',0.5)
                self.uniforms.addFloat('lum_threshold_4',0.3)
       
        def setScale(self,scale):
                self.uniforms.setValue('scale',scale)
       
        def getScale(self):
                return self.uniforms.getValue('scale')
               
        def setvx_offset(self,vx_offset):
                self.uniforms.setValue('vx_offset',vx_offset)
       
        def getvx_offset(self):
                return self.uniforms.getValue('vx_offset')
               
effect = CrosshatchEffect()
vizfx.postprocess.addEffect(effect)

import vizconfig
# Setup config options for post processing effect
ppConfig = vizconfig.BasicConfigurable('Crosshatch')
ppConfig.addBoolItem('Enable', fget=effect.getEnabled, fset=effect.setEnabled)
ppConfig.addFloatRangeItem('Brightness', [0.5,5.0], fget=lambda: effect.getScale(), fset=lambda v: effect.setScale(v))
ppConfig.addFloatRangeItem('Split Screen', [0.0,1.0], fget=lambda: effect.getvx_offset(), fset=lambda v: effect.setvx_offset(v))
vizconfig.register(ppConfig)

vizconfig.getConfigWindow().setWindowVisible(True)

Source: http://www.geeks3d.com/20110219/shad...g-glsl-filter/


All times are GMT -7. The time now is 06:33 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC