WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Thread Tools Rate Thread Display Modes
Old 05-06-2009, 08:23 AM
shivanangel shivanangel is offline
Join Date: Feb 2006
Location: New Jersey
Posts: 182
Specular Shader Issue


I was wondering if I could get a help with a Specular Shader problem.

I made a shader in the program AMD RenderMonkey, which if you are not familiar with is a 'sandbox' for making shaders and testing them out.

Everything works fine in RenderMonkey, but I run into the issue of nothing
rendering when I move into Vizard.

My Vertex Shader is:


uniform vec3 LightPosition;
uniform vec3 EyePosition;

varying vec3 ViewDirection;
varying vec3 LightDirection;
varying vec3 Normal;
varying vec2 Texcoord;

void main(void)
   gl_Position = ftransform();
   Texcoord = gl_MultiTexCoord0.xy;
   vec4 objectPosition = gl_ModelViewMatrix * gl_Vertex;
   LightDirection = (gl_ModelViewMatrix * vec4(LightPosition, 1)).xyz -;
   ViewDirection = EyePosition -;
   Normal = gl_NormalMatrix * gl_Normal;

My Fragment Shader:

uniform vec4 Diffuse;
uniform vec4 Ambient;
uniform vec4 Specular;
uniform vec3 LightPosition;
uniform vec3 EyePosition;
uniform float SpecularPower;

uniform sampler2D TexMap;
uniform sampler2D SpecMap;

varying vec3 LightDirection;
varying vec3 ViewDirection;
varying vec3 Normal;

varying vec2 Texcoord;

void main(void)
   vec3 nLightDirection = normalize(LightDirection);
   vec3 nNormal = normalize(Normal);
   float NDotL = dot(nNormal, nLightDirection);
   vec3 Reflection = normalize(((2.0 * nNormal) * NDotL) - nLightDirection); 
   vec3 nViewDirection = normalize(ViewDirection);
   float RDotV = max(0.0,dot(Reflection, nViewDirection));
   vec4 diffColor = texture2D(TexMap,Texcoord);
   vec4 specColor = texture2D(SpecMap, Texcoord);
   vec4 DiffuseColor = diffColor * Diffuse * NDotL;
   vec4 AmbientColor = Ambient * diffColor;
   vec4 SpecularColor = (Specular * (pow(RDotV, SpecularPower))) * specColor;
   gl_FragColor = DiffuseColor + AmbientColor + SpecularColor;

And my Vizard code for bringing in the shader and attaching it to the model:

import viz


shader = viz.addShader(flag = 0, vert = "SpecMap.vp", frag = "SpecMap.fp")


#Load model
trex = viz.add("TREX//TRex.CFG")

trex2 = viz.add('sphere.obj')
#Load Textures
TexMap = viz.addTexture('TRexTex_10_TexMap.bmp')
SpecMap = viz.addTexture('TRexTex_10_SpecMap.bmp')

#Attach textures
trex.texture(TexMap, '', 0)
trex.texture(SpecMap, '', 1)

trex2.texture(TexMap, '', 0)
trex2.texture(SpecMap, '', 1)

#Vertex Uniforms
EyePosition = viz.addUniformFloat('EyePosition', [0.0,0.0,0.0])
LightPosition = viz.addUniformFloat('fvLightPosition', [100,200,100])

#Fragment Uniforms
Diffuse = viz.addUniformFloat('Diffuse',[1.0,1.0,1.0,1.0])
Ambient = viz.addUniformFloat('Ambient',[1.0,1.0,1.0,1.0])
Specular = viz.addUniformFloat('Specular', [1.0,1.0,1.0,1.0])
SpecularPower = viz.addUniformFloat('SpecularPower', 3)

Texture =  viz.addUniformInt( 'TexMap', 0 )
SpecularMap = viz.addUniformInt( 'SpecMap', 1 )


Reply With Quote
Old 05-06-2009, 10:11 AM
farshizzo farshizzo is offline
WorldViz Team Member
Join Date: Mar 2003
Posts: 2,849
In your Vizard code, you are only attaching the texture uniforms to the shader. You need to attach all the other uniforms as well (LightPosition, EyePosition, Diffuse, etc...).
Reply With Quote
Old 05-06-2009, 11:08 AM
shivanangel shivanangel is offline
Join Date: Feb 2006
Location: New Jersey
Posts: 182
Thank you for the keen eye.

Will you be including shader help anytime soon in your documentation?
I've had quite a time finding information across this forum and
peeking through other people's code.

Thanks again,
Reply With Quote

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
Cal3D texture issue from Max shivanangel Vizard 5 10-17-2008 12:17 PM
Fur Shader djdesmangles Vizard 1 05-29-2008 09:37 PM
stereo projection issue asimbh Vizard 3 10-05-2007 10:22 AM
cal3d exporter issue reiverlass Vizard 4 07-18-2007 12:08 PM
viewing issue. cantwelljm Vizard 3 03-29-2006 12:03 PM

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

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