View Single Post
Old 08-03-2016, 11:20 AM
Vaquero Vaquero is offline
Join Date: Nov 2015
Posts: 62
The effect I'm trying to achieve is a modern approach to energy conserving shading, but there's an extra thread for that ( Here, I'd like to get information on how to use the custom effects and shaders in general, because it's unclear to me what's supported and what is not.

I tried using the addShader function instead of the effects framework, but this doesn't seem to work in Vizard as I would expect it to, whereas the exact same code produces visible results in ShaderMaker (, though the shader code must contain some errors in the calculations of _normalDir, _viewDir or light0Dir.

Here's the Vizard script:
import viz
import vizfx
import vizcam


# Setup camera navigation
cam = vizcam.PivotNavigate(distance=8.0, center=(0,1,0))

# Setup lighting
light = vizfx.addPointLight(color=viz.WHITE, pos=(4,4,-4))
vizfx.setAmbientColor(viz.BLACK) # disable ambient light

# Setup environment

# Setup models
logo1 = vizfx.addChild('logo.osgb')

vertCode = """
varying vec3 _viewDir;
varying vec3 _normalDir;
varying vec3 light0Dir;

void main()
	vec4 eyeVertex = gl_Vertex;
	vec3 eyeNormal = gl_Normal;

	eyeVertex = gl_ModelViewMatrix * eyeVertex;
	eyeNormal = normalize(gl_NormalMatrix * eyeNormal);
	vec4 eyeViewDir = vec4(,0.0);
	_viewDir =;
	_normalDir = eyeNormal;
	vec3 dir = gl_LightSource[0] -;
	light0Dir = dir;

	gl_Position    = gl_ModelViewProjectionMatrix * gl_Vertex;

# PBR Calculations
fragCode = """
uniform float roughness;

varying vec3 _viewDir;
varying vec3 _normalDir;
varying vec3 light0Dir;

const float PI = 3.14159265358979323846;

float sqr(float x) { return x*x; }

float GGX(float alpha, float cosThetaM)
    float CosSquared = cosThetaM*cosThetaM;
    float TanSquared = (1.0-CosSquared)/CosSquared;
    return (1.0/PI) * sqr(alpha/(CosSquared * (alpha*alpha + TanSquared)));

vec3 BRDF( vec3 L, vec3 V, vec3 N)
    vec3 H = normalize( L + V );
    float D = GGX(roughness, dot(N,H));
    return vec3(D);

void main()
	vec3 color = BRDF(light0Dir, _viewDir, _normalDir);
	gl_FragColor.rgb = color;
pbrShader = viz.addShader(vert=vertCode, frag=fragCode)

roughnessUniform = viz.addUniformFloat('roughness',0.6)
The model doesn't show up at all!

I saw that in the composer.vizfx file matrices like gl_ModelViewProjectionMatrix are used, that's why I used them here and because I have no idea how to get the matrices from vizard. But these matrices are deprecated since GLSL version 4.1. So which version is Vizard using?

Are varying variables between vertex and fragment shader supported?
Reply With Quote