WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

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

Hello,

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:

Code:
//Uniform 

uniform vec3 LightPosition;
uniform vec3 EyePosition;
//Varying

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

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

My Fragment Shader:

Code:
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:

Code:
import viz

viz.go()

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

viz.MainView.eyeheight(0.0)

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

trex2 = viz.add('sphere.obj')
trex2.setPosition(15,0,0)
#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 )

shader.attach(Texture)
shader.attach(SpecularMap)

trex.apply(shader)
trex2.apply(shader)
Reply With Quote
  #2  
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
  #3  
Old 05-06-2009, 11:08 AM
shivanangel shivanangel is offline
Member
 
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,
George
Reply With Quote
Reply


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 02:22 PM.


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