[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

Post by oldskoolPunk »

BlindSide wrote:(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)
omg??

Well thats quite a bit of helpful info right there ty Blindside! It's strange that in all my searching I never found that anywhere...

Anyways it solved all my problems and now everything is looking great.
( extra shiny to show it off! )

Image

Image

In trying to solve this problem, I opted to scrap the Rendermonkey code for now and write my own little shader. While a smooth hook-up between Irr and RM would be great for the community, its not the topic of this thread.

Following is my code that I wrote to solve MY original problem. I am in no way adept enough in programming to think that I should/could change the engine itself to make it better. I just made my own material using glsl.

Here is the shader code.

Code: Select all

// BUMP vertex shader
 
varying vec3 LightDirection; 
varying vec3 ViewDirection;

void main()
{
	gl_Position = ftransform();
	vec3 Position = vec3(gl_ModelViewMatrix * gl_Vertex);
	
	gl_TexCoord[0] = gl_MultiTexCoord0;
	
	vec3 Normal  = gl_NormalMatrix * gl_Normal;
	vec3 Tangent= gl_NormalMatrix * gl_MultiTexCoord1.xyz;
        vec3 Binormal = gl_NormalMatrix * gl_MultiTexCoord2.xyz;
	
	
	vec3 fvViewDirection = -Position;
	vec3 fvLightDirection = vec3(gl_LightSource[0].position.xyz -Position);
	
	ViewDirection.x  = dot( Tangent, fvViewDirection );
        ViewDirection.y  = dot( Binormal,fvViewDirection );
        ViewDirection.z  = dot( Normal,  fvViewDirection );
   
        LightDirection.x  = dot( Tangent, fvLightDirection );
        LightDirection.y  = dot( Binormal,fvLightDirection );
        LightDirection.z  = dot( Normal,  fvLightDirection  );	
}

Code: Select all

// BUMP pixel shader
 
varying vec3 LightDirection; 
varying vec3 ViewDirection;

uniform sampler2D colorMap;
uniform sampler2D bumpMap;

void main()
{

	
	vec3 N = normalize( ( texture2D( bumpMap, gl_TexCoord[0]).xyz * 2.0 ) - 1.0 );
	vec3 L = normalize(LightDirection);
        vec3 E = normalize(ViewDirection);
	vec3 R = reflect(-L, N);

        vec4 Color =  texture2D( colorMap, gl_TexCoord[0].st);  
	
	vec4 Ambient  =  Color * .1;
	vec4 Diffuse    =  Color * max(dot(N,L),0.0);
	vec4 Specular =  Color *  pow(max(dot(R,E),0.0),20.0);
 
	
	gl_FragColor = Ambient + Diffuse + Specular;
}
My callback is very basic. All I pass is which texture is which. Everything else is in the shader for now.

Code: Select all

class MyShaderCallBack : public irr::video::IShaderConstantSetCallBack
{
public:

virtual void OnSetConstants(irr::video::IMaterialRendererServices* services, irr::s32 userData)
{
	irr::s32 colorMap=0;
	irr::s32 bumpMap=1;
   services->setPixelShaderConstant("colorMap",reinterpret_cast<irr::f32*>(&colorMap), 1);

services->setPixelShaderConstant("bumpMap",reinterpret_cast<irr::f32*>(&bumpMap), 1);		
	}
};
I created the material like this.

Code: Select all

irr::s32 TexturedBump = Graphics:: gpu-> addHighLevelShaderMaterialFromFiles 
("C:/Shaders/TexturedBump/VERT.vert",													"main",																		irr::video::EVST_VS_2_0,																			"C:/Shaders/TexturedBump/FRAG.frag",																			"main",																			irr::video::EPST_PS_2_0,																			callback,																			irr::video::EMT_SOLID,																			1														  );
              node->setMaterialType((irr::video::E_MATERIAL_TYPE)TexturedBump);
I suck at text formatting on here I hope you can read that. Make sure the file paths are correct to the shaders and the textures.
Last edited by oldskoolPunk on Sun Nov 02, 2008 3:19 am, edited 1 time in total.
Signature? I ain't signin nuthin!
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

That's AWESOME dude!
Image
fmx

Post by fmx »

wow, lookin' sweet oldskoolPunk!
thanks for sharing your working solution, its one of the simplest (working) irrlicht-shader pieces in the forum!
:D
oldskoolPunk
Posts: 199
Joined: Wed Nov 29, 2006 4:07 am

Post by oldskoolPunk »

Hey thanks guys!

There are several optimizations to be made. Like turning those 3 texture look-ups into 1. Also it needs a better interface so you can change lightcolor, bump strength, ect.

Note that I had to re-order the TBN to BTN for it to look right on my screen. I won't pretend to know why.
[EDIT] nvm I had them backwards. I fixed it

I probably wrote [SOLVED] in the title too soon, because the shader is just a bump and not true parallax. But I may or may not continue with it because I am excited to try out my new material! Cya
Last edited by oldskoolPunk on Sun Nov 02, 2008 3:21 am, edited 1 time in total.
Signature? I ain't signin nuthin!
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

Thank you for posting the code, really appreciate it.
Image
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

By the way, I recommend you look into Deferred Shading as well. I spent a few hours experimenting with the first pass, trying to get the values onto a RTT. I'm still learning, tho. Might take some time to get it running on Irrlicht as I'm using RenderMonkey at the moment.
Image
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Post by Mel »

That is awesome! :) it is very likely i try to use in my own project, besides, i was looking for a way to make use of shaders easily. I hope it is not too hard to implement. Is there a Direct3D version of this?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
xsinick
Posts: 18
Joined: Fri Aug 10, 2007 12:05 am

Nice work

Post by xsinick »

Nicework!
How about specular mapping ?
And can you Post you complete code for others to test it and give you feedback?
Post Reply