[SOLVED]Specular highlights not visible on EMT_PARALLAX

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
oldskoolPunk
Posts: 199
Joined: Wed Nov 29, 2006 4:07 am

[SOLVED]Specular highlights not visible on EMT_PARALLAX

Post by oldskoolPunk »

Hi!

I want to see the specular highlights on my surface.

Here is the plane using EMT_SOLID, showing a big ole specular highlight spread across the plane.
Image

When I change to EMT_PARALLAX_MAP_SOLID all the spec vanishes.
Image

The light is default, here is its code.

Code: Select all

light=Graphics::scenemanager->addLightSceneNode(0,irr::core::vector3df(0,0,-3),irr::video::SColorf(1,1,1));
irr::scene::IBillboardSceneNode *bbil = Graphics::scenemanager->addBillboardSceneNode(light,irr::core::dimension2df(2,2));
bbil->setMaterialType(irr::video::EMT_TRANSPARENT_ADD_COLOR);
bbil->setMaterialTexture(0,Graphics::driver->getTexture("C:/Floor/light.jpg"));
bbil->setMaterialFlag (irr::video::EMF_LIGHTING,false);
And here is the code for the plane.

Code: Select all

irr::video::ITexture *colorMap = Graphics::driver->getTexture("C:/Shaders/brick/colorMap.tga");
irr::video::ITexture *bumpMap  = Graphics::driver->getTexture("C:/Shaders/brick/bumpMap.tga");

Graphics::driver->makeNormalMapTexture(bumpMap,7.0f);
             
irr::scene::IAnimatedMesh *mesh = Graphics::scenemanager->getMesh("C:/Objects/Plane/Plane.b3d");
tmesh = Graphics::scenemanager->getMeshManipulator()->createMeshWithTangents(mesh->getMesh(0));
irr::scene::ISceneNode *node = Graphics::scenemanager->addMeshSceneNode(tmesh);

//node->setMaterialType(irr::video::EMT_SOLID);			node->setMaterialType(irr::video::EMT_PARALLAX_MAP_SOLID);
node->setMaterialFlag (irr::video::EMF_LIGHTING,true);

node->setMaterialTexture(0,colorMap);
node->setMaterialTexture(1,bumpMap);
node->getMaterial(0).MaterialTypeParam = 0.02f;
node->getMaterial(0).Shininess = 40.0f;
Ive tried both .obj and .b3d, using both EDT_OPENGL and EDT_DIRECT3D9
Last edited by oldskoolPunk on Wed Oct 29, 2008 7:21 pm, edited 1 time in total.
Signature? I ain't signin nuthin!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

The shaders don't support much of the typical attributes the other materials use. This is just a problem of the shader sources, though, so you can improve the code and add those features. However, the material is usually not though to be used like this, because the parallax feature takes a bumpmap to do some other lighting effects. Check example 11.
oldskoolPunk
Posts: 199
Joined: Wed Nov 29, 2006 4:07 am

Post by oldskoolPunk »

Thank you.

So I guess I must try to create my own normal mapping shader to get specular highlights on it. Hmm this is gonna be hard.

I am trying to use the RenderMonkey normal map shader, but it doesnt look right on my screen. Can I pass the Tangent and BiNormal to the shader straight from S3DVertexTangents in the shader callback?

Code: Select all

irr::core::vector3df Tangent;
irr::video::S3DVertexTangents *verts = (irr::video::S3DVertexTangents*)Plane::tmesh->getMeshBuffer(0)->getVertices();
Tangent = verts->Tangent;
services->setVertexShaderConstant("Tangent", &Tangent.X, 3);
Signature? I ain't signin nuthin!
oldskoolPunk
Posts: 199
Joined: Wed Nov 29, 2006 4:07 am

Post by oldskoolPunk »

Well...

Specular highlights seemed like it should be a beginners question. Maybe I will start a new thread in the advanced section?

Trying to get Rendermonkey's normal map shader to work in Irrlicht just to get spec seems to be quite challenging ...
Signature? I ain't signin nuthin!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Repelling all users who took the time and read your topic despite being in the beginner's section might be wrong, though... But we can also move the topic.
oldskoolPunk
Posts: 199
Joined: Wed Nov 29, 2006 4:07 am

Post by oldskoolPunk »

Well I will leave that up to you sir and continue :)


In learning to use normal maps in glsl I am using the default Rendermonkey textured bump shader. I will list the default code, and my shader callback.

Code: Select all


// VERTEX SHADER //

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: Select all


// FRAGMENT SHADER//

//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  fvAmbient		  = vec4(0.1,0.1,0.1,0.1);
   vec4  fvSpecular		  = vec4(0.8,0.8,0.7,0.7);
   vec4  fvDiffuse		  = vec4(1.0,1.0,1.0,1.0);
   float  fvSpecularPower       = 20.0f;
   
   
   vec4  fvTotalAmbient   = fvAmbient * fvBaseColor; 
   vec4  fvTotalDiffuse   = fvDiffuse * fNDotL * fvBaseColor; 
   vec4  fvTotalSpecular  = fvSpecular * ( pow( fRDotV, fSpecularPower ) );
  
   gl_FragColor = ( fvTotalAmbient + fvTotalDiffuse + fvTotalSpecular );
       
}

Code: Select all

virtual void OnSetConstants(irr::video::IMaterialRendererServices* services, irr::s32 userData)
{
// VERTEX SHADER CONSTANTS //

irr::core::vector3df fvLightPosition = Light::light->getAbsolutePosition();
services->setVertexShaderConstant("fvLightPosition", reinterpret_cast<irr::f32*>(&fvLightPosition),3);

irr::core::vector3dffvEyePosition=Camera::camera->getAbsolutePosition();
services->setVertexShaderConstant("fvEyePosition", reinterpret_cast<irr::f32*>(&fvEyePosition),3);

irr::video::S3DVertexTangents *tVerts = (irr::video::S3DVertexTangents*)Plane::tmesh->getMeshBuffer(0)->getVertices();

irr::core::vector3df rm_Tangent = tVerts->Tangent;
services->setVertexShaderConstant("rm_Tangent", reinterpret_cast<irr::f32*>(&rm_Tangent),3);

irr::core::vector3df rm_Binormal = tVerts->Binormal;
services->setVertexShaderConstant("rm_Binormal", reinterpret_cast<irr::f32*>(&rm_Binormal),3);

// FRAG SHADER CONSTANTS //

irr::f32 baseMap = 0;
services->setPixelShaderConstant("baseMap", &baseMap,1);

irr::f32 bumpMap = 1;
services->setPixelShaderConstant("bumpMap", &bumpMap,1);

irr::video::SColorf fvAmbient;
fvAmbient.set(0.1f,0.1f,0.1f,1);
services->setPixelShaderConstant("fvAmbient",reinterpret_cast<irr::f32*>(&fvAmbient),4);

irr::video::SColorf fvDiffuse;
fvDiffuse.set(0.8f,0.8f,0.7f,1);
services->setPixelShaderConstant("fvDiffuse", reinterpret_cast<irr::f32*>(&fvDiffuse),4);

irr::video::SColorf fvSpecular;
fvSpecular.set(1,1,1,1);
services->setPixelShaderConstant("fvSpecular",reinterpret_cast<irr::f32*>(&fvSpecular),4);

		  irr::f32fSpecularPower=20.0f;                                               services->setPixelShaderConstant("fSpecularPower",reinterpret_cast<irr::f32*>(&fSpecularPower),1);
Image

I want to learn this on my own, but I cant figure out what Im missing.
I changed fvLightPosition to gl_LightSource[0].position, and that seems to make the randomness at least react to the light, ...randomly.
Can you help me to make this code work? For me to learn from it?
Signature? I ain't signin nuthin!
fmx

Post by fmx »

for you to learn from it, you will have to find a solution to this problem yourself :P

I can't pinpoint the exact problem myself (go figure, :oops: ), but maybe if you try playing with the glFragColor output and try to see if the 3 final components (fvTotalAmbient, fvTotalDiffuse and fvTotalSpecular) are even returning the "correct" values, you might be able to narrow the problem down

good luck!
oldskoolPunk
Posts: 199
Joined: Wed Nov 29, 2006 4:07 am

Post by oldskoolPunk »

Thanks fmx

But Im positive the shader code itself is correct because it is just a default Rendermonkey shader that looks fine in the app itself. I just pasted the shader code here for you to see.

What I am trying to do is send the correct data to the shader from the Irrlicht OnSetConstants callback. The fragment shader data is ok , its just the colors and the textures. The vertex shader data is what Im studying.

fvLightPosition and fvEyePosition seem straightforward enough? But the tangent and binormal, that cant be right can it? How does it know which vertex its even on?

I am still trying. I dont get much time per day to work on it but I will post back when Ive got more data under my belt :)
Signature? I ain't signin nuthin!
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

Please see sample code I wrote, hope that will help.

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=30829

It's not complete, but you get the idea. It's code taken from RenderMonkey.
Image
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Code: Select all

attribute vec3 rm_Binormal;
attribute vec3 rm_Tangent;
Irrlicht doesn't support vertex attributes, since you are passing them as uniforms you might want to change that?

(Although the way you are doing it is very odd, why don't you just use the 2nd and 3rd texcoord's that Irrlicht has already set up with tangents and binormals for you? Yes I am talking about gl_MultiTexCoord1 and gl_MultiTexCoord2)
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

Blindside:

How's the declaration of that? Does it look like this one?

Code: Select all


varying vec3 rm_Binormal;
varying vec3 rm_Tangent;

main() {

rm_Binormal = gl_MultiTexCoord1;
rm_Tangent = gl_MultiTexCoord2;

}
This is new to me.

Thanks.

PS: This is what I'm getting at the moment using the declaration above.

Image

Found it, the declaration is...

Code: Select all


	"ATTRIB InTangent = vertex.texcoord[1];\n"\
	"ATTRIB InBinormal = vertex.texcoord[2];\n"\

in COpenGLParallaxMapRenderer.cpp
Image
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

Yup, I think I'm getting it to show now. Tho I still need to work on it.

I'll post the vert and frag in the bump map demo thread later.

Image
Image
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

offtopic:

blindside, do you have any idea how to use samplerCube on Irrlicht?
I'm thinking of adding Ambient Occlusion in there. RenderMonkey requires a samplerCube for the both diffuse and environment.

Thanks.

Code: Select all

uniform samplerCube DiffuseEnvironment;
uniform sampler2D AmbientOcclusion;
uniform samplerCube Environment;

// inputs from vertex shader
varying vec2 vTexCoord;
varying vec3 vRotNorm;   // rotated normal



void main(void)
{
 
  vec4 ambient = textureCube( DiffuseEnvironment, vRotNorm);

  float ambientOcclusion = texture2D(AmbientOcclusion, vTexCoord).r;

   gl_FragColor =  ambientOcclusion * ambient;
   
}
Image
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

Thanks, I will take a look at it.
Image
Post Reply