PDA

View Full Version : post-processing effect to single object


saket
05-10-2018, 12:26 AM
Hi,

I need to access the currently displayed pixels on screen within a fragment shader.
For which i found the access through vizard's post-processing at http://docs.worldviz.com/vizard/postprocess_basics.htm using vizpp_InputTex. However it only refers to shader which are applied on whole screen.

How can I apply the the shader using postprocess to only specific objects?
Something like this :
effect = RedEffect()
object.apply(effect)

In which case only the object should have redeffect applied to it and rest of objects should have no effect.

Jeff
05-14-2018, 11:39 AM
All postprocess effects are applied to the entire window. You can apply shaders to individual objects using Vizard's effects (http://docs.worldviz.com/vizard/#Effect_Basics.htm) framework. The custom (http://docs.worldviz.com/vizard/#Effect_Custom.htm) and example (http://docs.worldviz.com/vizard/#Effect_Examples.htm) effects pages have some example code.

saket
05-15-2018, 11:45 PM
Thanks Jeff. The Effects might solve what I am looking for.

saket
05-18-2018, 12:09 AM
Hi Jeff,

The custom effect work on pre-existing models like 'logo.osgb'

But effects do not work on on-the fly object. Do i need to set some flag for on-the fly object for enabling effects on them as well?

Jeff
05-18-2018, 05:38 PM
Yes, you will need to use the generateEffects (http://docs.worldviz.com/vizard/#commands/node3d/generateEffects.htm) command on that model. Here's an example:

import viz
import vizfx
import vizcam
import vizshape

viz.setMultiSample(4)
viz.go()

viz.clearcolor(viz.SLATE)
# Disable head light
viz.MainView.getHeadLight().disable()
# Add a directional light pointing down
light = vizfx.addDirectionalLight(euler=(0,90,0), color=[0.2,0.2,0.2])

shape = vizshape.addPyramid(base=(0.4,0.4),height=0.4)
composer = vizfx.getComposer()
shape.generateEffects(composer=composer)

cam = vizcam.PivotNavigate(distance=3.5)
cam.centerNode(shape)

code = '''
Effect {
Type Highlight
Shader {
BEGIN FinalColor
gl_FragColor.rgb += vec3(0.7, 0.0, 0.0);
END
}
}
'''
effect = viz.addEffect(code)
shape.apply(effect)

saket
05-20-2018, 11:34 PM
Thanks Jeff.

It worked with on-the-fly object.

With models creating using external application like :http://www.openscenegraph.org/index.php/documentation/tools/virtual-planet-builder . Do I need to run any other command to enable effects on such models?

saket
05-24-2018, 01:03 AM
Additional Info :

If I create a separate copy of root node and apply effects only on it then the effects work.
However if I apply the effects on the entire directory structure where root node load the child nodes itself then the effects do not work.
I tried using different argument values for flags and op in generateEffects but still no success

Jeff
05-25-2018, 04:35 PM
Can you provide a sample file and code that reproduces the issue?

saket
05-27-2018, 11:21 PM
Jeff,

I am using the following code to test the effect on my model.

A subset of model with the code file is in attachment. Execute the shader_test.py to see that no effect is applied on the model.

However if I remove "Earth/main_root_L0_X0_Y0" folder then the effect start working.


import viz,vizfx

viz.go()
model=vizfx.addChild('./Earth/main.osgb')
viz.MainView.setPosition(2270347.75*2, 3137376.25*2, 7425973.0*2)
viz.MainView.lookAt([0,0,0])

composer=vizfx.getComposer()
model.generateEffects(composer=composer)

code="""
Effect {
Float rmin{value 0}
Float rmax{value 255}
Float gmin{value 0}
Float gmax{value 255}
Float bmin{value 0}
Float bmax{value 255}
Shader{
BEGIN FinalColor
float r=(vizfx_VertexColor.r-rmin)*255/(rmax-rmin);
float g=(vizfx_VertexColor.g-gmin)*255/(gmax-gmin);
float b=(vizfx_VertexColor.b-bmin)*255/(bmax-bmin);
gl_FragColor.rgb=vec3(r,g,b);
END
}
}
"""

effect=viz.addEffect(code)
model.apply(effect)
model.setUniformFloat('bmin',50)

saket
06-01-2018, 12:10 AM
All postprocess effects are applied to the entire window. You can apply shaders to individual objects using Vizard's effects (http://docs.worldviz.com/vizard/#Effect_Basics.htm) framework. The custom (http://docs.worldviz.com/vizard/#Effect_Custom.htm) and example (http://docs.worldviz.com/vizard/#Effect_Examples.htm) effects pages have some example code.

Can the Effect framework access neighboring pixels to apply effects like blur?

Because all the examples work specifically with pixel in question and not include any effect using neighboring pixel value which would be needed for implementing functions like blur.