WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 08-01-2016, 01:55 AM
Vaquero Vaquero is offline
Member
 
Join Date: Nov 2015
Posts: 62
Question Custom Effect Shading

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.
Reply With Quote
 

Tags
glsl, rendering, shader, shading

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating a Postprocessing effect MissingAFew Vizard 2 05-07-2015 09:58 AM
Adding custom faces mjabon Vizard 2 04-01-2009 08:34 PM
How do I add custom functions to a custom plugin? reedev Plug-in development 7 02-01-2009 03:39 AM
animating custom faces: in search of "open_mouth" morphs vr_boyko Vizard 1 09-16-2004 10:30 AM
Creating Custom Avatar Heads farshizzo Vizard 22 09-12-2004 09:23 PM


All times are GMT -7. The time now is 07:47 AM.


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