WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 06-12-2008, 06:54 PM
djdesmangles djdesmangles is offline
Member
 
Join Date: Nov 2006
Posts: 88
Exclamation BumpMapping

Hello Wizard,

My BumpMapping shader is almost working !!! Except that my texture is going bye bye on some faces of my model... Can you tell me what is wrong ? I don't understand how to use the "attributes" in Vizard neither.

I've attached the test. It's a rar file that I've renamed to zip for the uploading.
Ciao !!
D.
Attached Files
File Type: zip BumpMapping.rar.zip (749.4 KB, 855 views)
Reply With Quote
  #2  
Old 06-13-2008, 12:16 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
To the fix the texture issue, you need to enable texture repeating. Use the following code when adding the textures:
Code:
baseMap = viz.addTexture('Fieldstone.dds',wrap=viz.REPEAT)
bumpMap	= viz.addTexture('Fieldstone_nm.png',wrap=viz.REPEAT)
Regarding the shader attributes, Vizard suppports computing tangent data for your mesh. I've modified your VirtualFX.py file to use this feature. I just modified a small portion of the vertex shader and enabled tangent computation on the shader object:
Code:
import viz

class BumpMapping(object):
	
	def __init__(self):
		self.__vert = """		
		uniform vec3 fvLightPosition;
		uniform vec3 fvEyePosition;

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

		attribute vec3 Tangent;

		void main( void )
		{
			gl_Position = ftransform();
			Texcoord    = gl_MultiTexCoord0.xy;

			vec4 fvObjectPosition = gl_ModelViewMatrix * gl_Vertex;

			vec3 fvViewDirection  = fvEyePosition - fvObjectPosition.xyz;
			vec3 fvLightDirection = fvLightPosition - fvObjectPosition.xyz;
	
			vec3 fvNormal         = gl_NormalMatrix * gl_Normal;
			vec3 fvTangent        = gl_NormalMatrix * Tangent;
			vec3 fvBinormal       = cross(fvNormal, fvTangent);

			ViewDirection.x  = dot( fvTangent, fvViewDirection );
			ViewDirection.y  = dot( fvBinormal, fvViewDirection );
			ViewDirection.z  = dot( fvNormal, fvViewDirection );

			LightDirection.x  = dot( fvTangent, fvLightDirection.xyz );
			LightDirection.y  = dot( fvBinormal, fvLightDirection.xyz );
			LightDirection.z  = dot( fvNormal, fvLightDirection.xyz );
		} """
		
		self.__frag = """
		uniform vec4 fvAmbient;
		uniform vec4 fvSpecular;
		uniform vec4 fvDiffuse;
		uniform float fSpecularPower;

		uniform sampler2D baseMap;
		uniform sampler2D bumpMap;

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

		void main( void )
		{
			vec3  fvLightDirection = normalize( LightDirection );
			vec3  fvNormal         = normalize( ( texture2D( bumpMap, Texcoord ).xyz * 2.0 ) - 1.0 );
			float fNDotL           = dot( fvNormal, fvLightDirection ); 

			vec3  fvReflection     = normalize( ( ( 2.0 * fvNormal ) * fNDotL ) - fvLightDirection ); 
			vec3  fvViewDirection  = normalize( ViewDirection );
			float fRDotV           = max( 0.0, dot( fvReflection, fvViewDirection ) );

			vec4  fvBaseColor      = texture2D( baseMap, Texcoord );

			vec4  fvTotalAmbient   = fvAmbient * fvBaseColor; 
			vec4  fvTotalDiffuse   = fvDiffuse * fNDotL * fvBaseColor; 
			vec4  fvTotalSpecular  = fvSpecular * ( pow( fRDotV, fSpecularPower ) );

			gl_FragColor = ( fvTotalAmbient + fvTotalDiffuse + fvTotalSpecular );
		} """
		
		# Creating shader
		self.__shader = viz.addShader(vert=self.__vert, frag=self.__frag,flag=viz.SHADER_TANGENT)
		
		# Adding vertex uniforms
		ufvLightPosition	= viz.addUniformFloat('fvLightPosition', 0, 0, 0);
		ufvEyePosition 		= viz.addUniformFloat('fvEyePosition', 0,0,0);
		#urm_Binormal 		= viz.addUniformFloat('rm_Binormal', 0,0,0);
		#urm_Tangent 		= viz.addUniformFloat('rm_Tangent', 0,0,0);
		
		# Adding fragment uniforms
		ufvAmbient		= viz.addUniformFloat('fvAmbient', .35,.35,.35,1);
		ufvSpecular 	= viz.addUniformFloat('fvSpecular',.50,.50,.50,1);
		ufvDiffuse 		= viz.addUniformFloat('fvDiffuse', .80,.80,.80,1);
		ufSpecularPower	= viz.addUniformFloat('fSpecularPower', 5);
		
		ubaseMap 		= viz.addUniformInt('baseMap', 0);
		ubumpMap		= viz.addUniformInt('bumpMap', 1);
		
		self.__shader.attach(ufvLightPosition)
		self.__shader.attach(ufvEyePosition)
		#self.__shader.attach(urm_Binormal)
		#self.__shader.attach(urm_Tangent)
		
		self.__shader.attach(ufvAmbient)
		self.__shader.attach(ufvSpecular)
		self.__shader.attach(ufvDiffuse)
		self.__shader.attach(ufSpecularPower)
		
		self.__shader.attach(ubaseMap)
		self.__shader.attach(ubumpMap)

	def applyfx(self, node):
		node.apply(self.__shader)
Reply With Quote
  #3  
Old 06-14-2008, 05:16 AM
djdesmangles djdesmangles is offline
Member
 
Join Date: Nov 2006
Posts: 88
Thumbs up Thanks !!

Thanks Farshi,

It's working...

viz.FOREVER !!
D.
Reply With Quote
Reply

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


All times are GMT -7. The time now is 11:17 PM.


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