Diffuse, Glow, Specular and Bump Mapping implementation?

I’m looking for a little instruction on attaching glow and bump mapping to a Collada material. Below is the code I have generated using the DOM so far. Only Diffuse and Specular works though. Can someone please offer me a little direction with glow and bump maps by modifying the code below? Thanks : )

	<library_images>
		<image id="amulet_artifact_mesh-diffuse" height="0" width="0">
			<init_from>./amulet_artifact_diffuse.dds</init_from>
		</image>
		<image id="amulet_artifact_mesh-glow" height="0" width="0">
			<init_from>./amulet_artifact_glow.dds</init_from>
		</image>
		<image id="amulet_artifact_mesh-specular" height="0" width="0">
			<init_from>./amulet_artifact_specular.dds</init_from>
		</image>
	</library_images>
	<library_effects>
		<effect id="amulet_artifact_mesh-effect">
			<profile_COMMON>
				<newparam sid="diffuse-surface">
					<surface type="2D">
						<init_from>amulet_artifact_mesh-diffuse</init_from>
						<format>A8R8G8B8</format>
					</surface>
				</newparam>
				<newparam sid="diffuse-sampler">
					<sampler2D>
						<source>diffuse-surface</source>
						<minfilter>LINEAR_MIPMAP_LINEAR</minfilter>
						<magfilter>LINEAR</magfilter>
					</sampler2D>
				</newparam>
				<newparam sid="glow-surface">
					<surface type="2D">
						<init_from>amulet_artifact_mesh-glow</init_from>
						<format>A8R8G8B8</format>
					</surface>
				</newparam>
				<newparam sid="glow-sampler">
					<sampler2D>
						<source>glow-surface</source>
						<minfilter>LINEAR_MIPMAP_LINEAR</minfilter>
						<magfilter>LINEAR</magfilter>
					</sampler2D>
				</newparam>
				<newparam sid="normal-surface">
					<surface type="2D">
						<init_from>amulet_artifact_mesh-normal</init_from>
						<format>A8R8G8B8</format>
					</surface>
				</newparam>
				<newparam sid="normal-sampler">
					<sampler2D>
						<source>normal-surface</source>
						<minfilter>LINEAR_MIPMAP_LINEAR</minfilter>
						<magfilter>LINEAR</magfilter>
					</sampler2D>
				</newparam>
				<newparam sid="specular-surface">
					<surface type="2D">
						<init_from>amulet_artifact_mesh-specular</init_from>
						<format>A8R8G8B8</format>
					</surface>
				</newparam>
				<newparam sid="specular-sampler">
					<sampler2D>
						<source>specular-surface</source>
						<minfilter>LINEAR_MIPMAP_LINEAR</minfilter>
						<magfilter>LINEAR</magfilter>
					</sampler2D>
				</newparam>
				<technique sid="common">
					<phong>
						<emission>
							<texture texture="glow-sampler" texcoord="uv0"/>
						</emission>
						<diffuse>
							<texture texture="diffuse-sampler" texcoord="uv0"/>
						</diffuse>
						<specular>
							<texture texture="specular-sampler" texcoord="uv0"/>
						</specular>
					</phong>
				</technique>
			</profile_COMMON>
		</effect>
	</library_effects>
	<library_materials>
		<material id="amulet_artifact_mesh-material">
			<instance_effect url="#amulet_artifact_mesh-effect"/>
		</material>
	</library_materials>

What system are you trying to translate into COLLADA’s COMMON profile?

Have you considered mapping to a more advanced profile, like GLSL or Cg, that can support a direct translation?

Ah I overlooked that. We want to use the models in Torque 3D which supports Mac + Windows. It uses OpenGL and DirectX API but i’d rather work in OpenGL for portability. I’d appreciate any direction on an implementation here :slight_smile: My requirements are as stated:

  • Diffuse
  • Glow
  • Specular
  • Bump

I’ll take a stab and go for the GLSL profile. It looks like you have to write some code blocks for this profile. I wouldn’t mind just being about to reference and copy an example implementation that I can merge into my exporter. I have been studying the example from the 1.4.1 specification, this might be a good starting point?

<profile_GLSL> 
    <code sid="Vertex_Program_E0_P0_VP">uniform vec3 
fvLightPosition; 
uniform vec3 fvEyePosition; 
 
varying vec2 Texcoord; 
varying vec3 ViewDirection; 
varying vec3 LightDirection; 
  
attribute vec3 rm_Binormal; 
attribute vec3 rm_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 fvBinormal = gl_NormalMatrix * rm_Binormal; 
 vec3 fvTangent = gl_NormalMatrix * rm_Tangent; 
  
 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 ); 
  
}</code> 
    <code sid="Fragment_Program_E0_P0_FP">uniform vec4 
fvAmbient; 
uniform vec4 fvSpecular; 
uniform vec4 fvDiffuse; B-4     COLLADA – Digital Asset Schema Release 1.4.1, 2nd Edition 
March 2008 
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 ); 
  
}</code> 

You don’t necessarily have to write GLSL shaders as the COLLADA schema supports (nearly) all of the OpenGL and OpenGL ES tokens. If you can do what you want with fixed-function then you should be able to express that in COLLADA <profile_GLSL> and/or <profile_GLES> element scope.

Does anyone have a similar material in Collada format that uses these effects I could use a reference? Thanks

Wondering if FXComposer could help you with this?

Have a look at these FX tools and resources:

FXComposer

RenderMonkey

COLLADA OpenGL FX Viewer