WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   post-processing effect to single object (https://forum.worldviz.com/showthread.php?t=6141)

saket 05-09-2018 11:26 PM

post-processing effect to single object
 
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 10:39 AM

All postprocess effects are applied to the entire window. You can apply shaders to individual objects using Vizard's effects framework. The custom and example effects pages have some example code.

saket 05-15-2018 10:45 PM

Thanks Jeff. The Effects might solve what I am looking for.

saket 05-17-2018 11:09 PM

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 04:38 PM

Yes, you will need to use the generateEffects command on that model. Here's an example:

Code:

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 10:34 PM

Thanks Jeff.

It worked with on-the-fly object.

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

saket 05-24-2018 12: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 03:35 PM

Can you provide a sample file and code that reproduces the issue?

saket 05-27-2018 10:21 PM

1 Attachment(s)
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.

Code:

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 05-31-2018 11:10 PM

Quote:

Originally Posted by Jeff (Post 19807)
All postprocess effects are applied to the entire window. You can apply shaders to individual objects using Vizard's effects framework. The custom and example 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.


All times are GMT -7. The time now is 01:17 PM.

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