Hey!
I'm trying to change they way models get shaded, so I was looking into the custom effects. The documentation only gives very simple examples.
When things get more complicated I need helper functions, but I suspect these are not supported to work with vizard's effects framework?
Let's do a really simple dummy example.
Assume inside the shader code I want to use this helper function:
Code:
float halve(float k)
{
return k*0.5;
}
Of course, in a real world example it will be much more complicated than this.
But whereever I put this function, it throws some error. Inside Shader, but outside Units:
Code:
# Setup model
logo = vizfx.addChild('logo.osgb')
code = """
Effect CustomShadingModel {
Shader {
float halve(float k)
{
return k*0.5;
}
BEGIN FinalColor
float half_r = halve(gl_FragColor.r);
gl_FragColor.rgb = vec3(half_r, 1.0, 1.0);
END
}
}
"""
customEffect = viz.addEffect(code)
# Apply effect specifically to a model
logo.apply(customEffect)
throws:
Quote:
** WARNING: Invalid character when parsing "<effect string>", line 8:
float halve(float k)
|
If I put it in the properties, I get the same error, and if I put it inside the Unit section I get another error message.
So is this really not possible with the effects framework?
If not, I would have to use a custom GLSL fragment shader? But the documentation on this is very sparse (just a make-a-uniform-color-example). How do I get the ViewDirection, the surface normal, the light direction, etc. to be used inside the shader code? And how can I apply the shader to all osgb models loaded and reference their texures inside the code? Because I don't want to set all textures for a hundred objects via script.