Horde3D

Next-Generation Graphics Engine
It is currently 22.11.2024, 12:11

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: 21.11.2011, 19:08 
Offline

Joined: 21.11.2011, 18:53
Posts: 2
Hello everyone,
Our team is working on an underwater simulation and today I tried adding new ground geometry but noticed that the colors of the ground were completely different then expected when being rendered using the shader.

When I debugged and tried setting the gl_FragColor to full red this was the result I got:
http://i1100.photobucket.com/albums/g41 ... ullred.png

This was what I expected but now when I tried setting R to 0.5 I got this result:
http://i1100.photobucket.com/albums/g41 ... alfred.png

I am pretty lost on this one what could possibly influence the colors to be different. I checked the materials and shader over and over.
Here is the scene and material files that are being used. The log file doesn't contain any errors. I expect I messed up the material but I don't see it.
Any help would be welcome!

Code:
AQUARIUM.SCENE.XML
----------------------------------------------------------

<Model name="aquarium" geometry="models/aquarium.geo">
   <Mesh name="aquarium_test" material="models/lambert_pool.material.xml" batchStart="0" batchCount="300" vertRStart="0" vertREnd="101" />
   <Mesh name="polySurface1" material="models/ground.material.xml" tx="0" ty="0" tz="749.845" batchStart="300" batchCount="12288" vertRStart="102" vertREnd="8293" />
</Model>




GROUND.MATERIAL.XML
----------------------------------------------------------

<Material>
   <Shader source="shaders/water.shader" />
   
   <Sampler name="causticMap" map="/textures/caustics/001.png" />
   
   <Uniform name="textureMatrixRow0" a="0.0" b="0.0" c="0.0" d="0.0" />
   <Uniform name="textureMatrixRow1" a="0.0" b="0.0" c="0.0" d="0.0" />
   <Uniform name="textureMatrixRow2" a="0.0" b="0.0" c="0.0" d="0.0" />
   <Uniform name="textureMatrixRow3" a="0.0" b="0.0" c="0.0" d="0.0" />
   <Uniform name="fogColor" a="0.0" b="0.0" c="0.0" d="0.0" />
</Material>


LAMBERT_POOL.MATERIAL.XML
----------------------------------------------------------

<Material>
   <Shader source="shaders/water.shader" />
   
   <Sampler name="causticMap" map="/textures/caustics/001.png" />
   
   <Uniform name="textureMatrixRow0" a="0.0" b="0.0" c="0.0" d="0.0" />
   <Uniform name="textureMatrixRow1" a="0.0" b="0.0" c="0.0" d="0.0" />
   <Uniform name="textureMatrixRow2" a="0.0" b="0.0" c="0.0" d="0.0" />
   <Uniform name="textureMatrixRow3" a="0.0" b="0.0" c="0.0" d="0.0" />
   <Uniform name="fogColor" a="0.0" b="0.0" c="0.0" d="0.0" />
</Material>



And this is the shader that is used to render the geometry:
Code:
// Per pixel fog: http://www.ozone3d.net/tutorials/glsl_fog/index.php
// By Jerome 'JeGX' Guinot - jegx_AT_ozone3d(dot)net

[[FX]]
// Supported Flags
/* ---------------
   _F01_Skinning
   _F02_NormalMapping
*/

// Samplers
sampler2D albedoMap;
sampler2D causticMap = sampler_state
{
   Address = Wrap;
   Filter = Trilinear;
   MaxAnisotropy = 1;
};

sampler2D normalMap = sampler_state
{
   Texture = "textures/common/defnorm.tga";
};

samplerCube ambientMap = sampler_state
{
   Address = Clamp;
   Filter = Bilinear;
   MaxAnisotropy = 1;
};

// Uniforms
float4 specParams <
   string desc_a = "a: specular mask";
   string desc_b = "b: specular exponent";
> = {0.1, 16.0, 0, 0};

float4 textureMatrixRow0;
float4 textureMatrixRow1;
float4 textureMatrixRow2;
float4 textureMatrixRow3;
float4 fogColor;

// Contexts
context ATTRIBPASS
{
   VertexShader = compile GLSL VS_GENERAL;
   PixelShader = compile GLSL FS_ATTRIBPASS;
}

context SHADOWMAP
{
   VertexShader = compile GLSL VS_SHADOWMAP;
   PixelShader = compile GLSL FS_SHADOWMAP;
}

context LIGHTING
{
   VertexShader = compile GLSL VS_GENERAL;
   PixelShader = compile GLSL FS_LIGHTING;
   
   ZWriteEnable = false;
   BlendMode = Add;
}

context AMBIENT
{
   VertexShader = compile GLSL VS_GENERAL;
   PixelShader = compile GLSL FS_AMBIENT;
}

[[VS_GENERAL]]
// =================================================================================================

#include "shaders/shaderSettings.shader"

#include "shaders/utilityLib/vertCommon.glsl"

#ifdef _F01_Skinning
   #include "shaders/utilityLib/vertSkinning.glsl"
#endif

uniform mat4      viewProjMat;
uniform vec3      viewerPos;
attribute vec3      vertPos;
attribute vec2      texCoords0;
attribute vec3      normal;

#ifdef _F02_NormalMapping
   attribute vec4   tangent;
#endif

varying vec4      pos, vsPos;
varying vec2      texCoords;

#ifdef _F02_NormalMapping
   varying mat3   tsbMat;
#else
   varying vec3   tsbNormal;
#endif

varying vec4      projCoords;

// texture matrix
uniform vec4      textureMatrixRow0;
uniform vec4      textureMatrixRow1;
uniform vec4      textureMatrixRow2;
uniform vec4      textureMatrixRow3;

void main( void )
{
#ifdef _F01_Skinning
   mat4 skinningMat = calcSkinningMat();
   mat3 skinningMatVec = getSkinningMatVec( skinningMat );
#endif
   
   // Calculate normal
#ifdef _F01_Skinning
   vec3 _normal = normalize( calcWorldVec( skinVec( normal, skinningMatVec ) ) );
#else
   vec3 _normal = normalize( calcWorldVec( normal ) );
#endif

   // Calculate tangent and bitangent
#ifdef _F02_NormalMapping
   #ifdef _F01_Skinning
      vec3 _tangent = normalize( calcWorldVec( skinVec( tangent.xyz, skinningMatVec ) ) );
   #else
      vec3 _tangent = normalize( calcWorldVec( tangent.xyz ) );
   #endif
   
   vec3 _bitangent = cross( _normal, _tangent ) * tangent.w;
   tsbMat = calcTanToWorldMat( _tangent, _bitangent, _normal );
#else
   tsbNormal = _normal;
#endif

   // Calculate world space position
#ifdef _F01_Skinning   
   pos = calcWorldPos( skinPos( vec4( vertPos, 1.0 ), skinningMat ) );
#else
   pos = calcWorldPos( vec4( vertPos, 1.0 ) );
#endif

   vsPos = calcViewPos( pos );
   
   // setup lightview matrix
   mat4 textureMatrix = mat4(0.0);
   textureMatrix[0] = textureMatrixRow0;
   textureMatrix[1] = textureMatrixRow1;
   textureMatrix[2] = textureMatrixRow2;
   textureMatrix[3] = textureMatrixRow3;
   
   // get projected texture coordinates
   projCoords = textureMatrix * pos;
   
   // Calculate texture coordinates and clip space position
   texCoords = texCoords0;
   gl_Position = viewProjMat * pos;
}

[[FS_ATTRIBPASS]]
// =================================================================================================

#include "shaders/utilityLib/fragDeferredWrite.glsl"

uniform vec3         viewerPos;
uniform vec4         specParams;
uniform sampler2D      albedoMap;

#ifdef _F02_NormalMapping
   uniform sampler2D   normalMap;
#endif

varying vec4         pos;
varying vec2         texCoords;

#ifdef _F02_NormalMapping
   varying mat3      tsbMat;
#else
   varying vec3      tsbNormal;
#endif

void main( void )
{
   vec3 newCoords = vec3( texCoords, 0 );

   // Flip texture vertically to match the GL coordinate system
   newCoords.t *= -1.0;

   vec4 albedo = texture2D( albedoMap, newCoords.st );
   
#ifdef _F02_NormalMapping
   vec3 normalMap = texture2D( normalMap, newCoords.st ).rgb * 2.0 - 1.0;
   vec3 normal = tsbMat * normalMap;
#else
   vec3 normal = tsbNormal;
#endif

   vec3 newPos = pos.xyz;
   
   setMatID( 1.0 );
   setPos( newPos - viewerPos );
   setNormal( normalize( normal ) );
   setAlbedo( albedo.rgb );
   setSpecMask( specParams.x );
}
   
[[VS_SHADOWMAP]]
// =================================================================================================
   
#include "shaders/utilityLib/vertCommon.glsl"
#include "shaders/utilityLib/vertSkinning.glsl"

uniform mat4      viewProjMat;
uniform vec4      lightPos;
attribute vec3      vertPos;
varying vec3      lightVec;

void main( void )
{
#ifdef _F01_Skinning   
   vec4 pos = calcWorldPos( skinPos( vec4( vertPos, 1.0 ) ) );
#else
   vec4 pos = calcWorldPos( vec4( vertPos, 1.0 ) );
#endif

   lightVec = lightPos.xyz - pos.xyz;
   gl_Position = viewProjMat * pos;
}
      
[[FS_SHADOWMAP]]
// =================================================================================================

uniform vec4      lightPos;
uniform float      shadowBias;
varying vec3      lightVec;

void main( void )
{
#ifdef _F05_AlphaTest
   vec4 albedo = texture2D( albedoMap, texCoords * vec2( 1, -1 ) );
   if( albedo.a < 0.01 ) discard;
#endif
   
   float dist = length( lightVec ) / lightPos.w;
   gl_FragDepth = dist + shadowBias;
   
   // Clearly better bias but requires SM 3.0
   //gl_FragDepth = dist + abs( dFdx( dist ) ) + abs( dFdy( dist ) ) + shadowBias;
}

[[FS_LIGHTING]]
// =================================================================================================

#include "shaders/shaderSettings.shader"

#include "shaders/utilityLib/fragLighting.glsl"

uniform vec4         specParams;
uniform sampler2D      albedoMap;
uniform sampler2D      causticMap;

#ifdef _F02_NormalMapping
   uniform sampler2D   normalMap;
#endif

varying vec4         pos, vsPos;
varying vec2         texCoords;

#ifdef _F02_NormalMapping
   varying mat3      tsbMat;
#else
   varying vec3      tsbNormal;
#endif

varying float         fogFactor;
uniform vec4         fogColor;
varying vec4         projCoords;

void main( void )
{
   vec3 newCoords = vec3( texCoords, 0 );

   // Flip texture vertically to match the GL coordinate system
   newCoords.t *= -1.0;

   vec4 albedo = texture2D( albedoMap, newCoords.st );
   
#ifdef _F02_NormalMapping
   vec3 normalMap = texture2D( normalMap, newCoords.st ).rgb * 2.0 - 1.0;
   vec3 normal = tsbMat * normalMap;
#else
   vec3 normal = tsbNormal;
#endif

   vec3 newPos = pos.xyz;
   
   // calculate phong and add caustic texture to final color
   vec4 causticColor = vec4( 0.0, 0.0, 0.0, 0.0 );
   if ( projCoords.w > 0 )
    {
      causticColor = texture2DProj( causticMap, projCoords );
   }
   vec3 finalColor = calcPhongSpotLight( newPos, normalize( normal ), albedo.rgb + (causticColor*SHADERSETTINGS_CAUSTICS_STRENGTH).rgb, specParams.x, specParams.y, -vsPos.z, 0.0 );
      
   // distance between camera and pixel
   float camVertexDistance = gl_FragCoord.z / gl_FragCoord.w;
   camVertexDistance /= SHADERSETTINGS_FOG_FARCLIPPLANE;
      
   // display z-buffer
//   float z = camVertexDistance / SHADERSETTINGS_FOG_FARCLIPPLANE;
//   gl_FragColor = vec4( z, z, z, 1.0 );
   
   // calculate fog factor
/*   const float LOG2 = 1.442695;
   float fogFactor = exp2( -gl_Fog.density * gl_Fog.density * camVertexDistance * camVertexDistance * LOG2 );
   fogFactor = clamp( fogFactor, 0.0, 1.0 );

   // determine final color
   gl_FragColor.rgb = mix( fogColor.rgb, finalColor.rgb, fogFactor );

   //gl_FragColor.rgb = vec3( fogFactor, fogFactor, fogFactor );
*/
   gl_FragColor.rgb = vec3( 0.5, 0.0, 0.0 );
}

[[FS_AMBIENT]]   
// =================================================================================================

#include "shaders/utilityLib/fragLighting.glsl"

uniform sampler2D         albedoMap;
uniform samplerCube         ambientMap;

#ifdef _F02_NormalMapping
   uniform sampler2D      normalMap;
#endif

varying vec4            pos;
varying vec2            texCoords;

#ifdef _F02_NormalMapping
   varying mat3         tsbMat;
#else
   varying vec3         tsbNormal;
#endif

void main( void )
{
   vec3 newCoords = vec3( texCoords, 0 );

   // Flip texture vertically to match the GL coordinate system
   newCoords.t *= -1.0;

   vec4 albedo = texture2D( albedoMap, newCoords.st );
   
#ifdef _F02_NormalMapping
   vec3 normalMap = texture2D( normalMap, newCoords.st ).rgb * 2.0 - 1.0;
   vec3 normal = tsbMat * normalMap;
#else
   vec3 normal = tsbNormal;
#endif
   
   //gl_FragColor.rgb = albedo.rgb;// * textureCube( ambientMap, normal ).rgb;
   gl_FragColor.rgb = vec3( 0.0, 0.0, 0.0 );
}



Top
 Profile  
Reply with quote  
PostPosted: 21.11.2011, 19:44 
Offline

Joined: 17.11.2009, 17:00
Posts: 205
Location: Russia, Moscow
Is your scene visible without any light present in the scene? By default (in samples) Horde uses global illumination with brown color (resides in content/textures/ambientmap.dds, if I'm not mistaken). It can alter the color of your scene. Try renaming globalSettings.material.xml (resides in content/materials) to something like _globalsettings.material.xml. Horde will give you a warning that file couldn't be found, but will load the scene. If global illumination was the problem then you should change the default ambient map to your custom map or delete the link to the material in the pipeline xml file. Hope this helps.


Top
 Profile  
Reply with quote  
PostPosted: 21.11.2011, 21:21 
Offline

Joined: 21.11.2011, 18:53
Posts: 2
This solved my problem
//BlendMode = Add;


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group