Lighting quality on Obj models

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!
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Lighting quality on Obj models

Post by robmar »

Thanks for that, I´ve read up a little and it is the vertex shading. Having more triangles improves it of course, but the solution is a fragment/pixel shader. I sort of thought that Irrlicht has one as default, but will add one now. If anyone is interested I can post it when its done.
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Re: Lighting quality on Obj models

Post by ent1ty »

Yeah it's kinda strange that there's a parallax shader but not a simple smooth shading one isn't it :-P
irrRenderer 1.0
Height2Normal v. 2.1 - convert height maps to normal maps

Step back! I have a void pointer, and I'm not afraid to use it!
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Lighting quality on Obj models

Post by robmar »

Yep, very odd, that is unless there is one hiding in there somewhere! The bump map shader must have all the maths needed I guess.

Anyway, have a good complete example and will try to implement that one.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Re: Lighting quality on Obj models

Post by Klunk »

there's always a no bump bumpmap

Image

as a quick test.
Klunk
Posts: 264
Joined: Mon Jan 10, 2011 5:21 pm

Re: Lighting quality on Obj models

Post by Klunk »

you may still find that if the normals in the model are not handle correctly you'll still not get the desired result.

Image
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Lighting quality on Obj models

Post by robmar »

In the Irrlicht "Features" page it mentions Pixel shaders are installed, but digging through the Irrlicht source code, as I couldn´t find any documentation, there only seems to be pixel shaders for normal maps, height meshes, and then with 2 lights.

So is there really no pixel shader for normal rendering?

I tested with this shader and it works well.

I think I must have missed something though because with all these experts behind Irrlicht for sure there must be a default pixel shader... right?

Code: Select all

 
// Phong shader - tested with Irrlicht 1.7.3
/*
 
Pixel shader with lighting.
 
Source: Posted on November 13, 2008 by brooknovak
http://brooknovak.wordpress.com/2008/11/13/hlsl-per-pixel-point-light-using-phong-blinn-lighting-model/
keywords: Phong
date: 20130104
 
*/
 
// HLSL Vertex shader
 
float4x4 mWorld;
float4x4 mWorldViewProj: WorldViewProjection;
float4x4 mView : WorldView;
float4x4 mWorldInverseTranspose;
 
float3 CameraPos;
float   fAlpha;
float3  LightPosition;  // (0.0, 10.0, 4.0)
float3  lightVec;
 
float3 LightDiffuseColor; // intensity multiplier
float3 LightSpecularColor; // intensity multiplier
float LightDistanceSquared;
float3 AmbientLightColor;
 
float3 EmissiveColor;
float3 SpecularColor;
float3 DiffuseColor;
 
float SpecularPower;
 
texture _texture;
 
sampler Texture =
sampler_state
{
 Texture= <_texture>;
};
 
struct VS_INPUT
{
    float4 position:POSITION;
    float3 normal:NORMAL0;
    float2 TexCoord:TEXCOORD0;  
};
 
struct VS_OUTPUT
{
    float4 position:POSITION;
    float2 TexCoord:TEXCOORD0;  
    float3 normal:TEXCOORD1;
    float3 WorldPos : TEXCOORD2;    
};
 
 
struct PS_OUTPUT
{
    float4 color:COLOR;
};
 
VS_OUTPUT mainVS(VS_INPUT In)
{
    VS_OUTPUT Out;
 
    Out.position = mul(In.position, mWorldViewProj);
    float4 posWorld = mul(In.position, mWorld);
 
    float4 worldPos = mul(In.position, mView);
 
    Out.TexCoord = In.TexCoord; 
 
    // Passing information on to do both specular AND diffuse calculation in pixel shader
    Out.normal = mul(In.normal, (float3x3)mWorld);
    Out.WorldPos = posWorld;
 
    return Out;
}
 
PS_OUTPUT mainPS(VS_OUTPUT In)
{   
    PS_OUTPUT Out;
 
  // Phong relfection is ambient + light-diffuse + spec highlights.
  // I = Ia*ka*Oda + fatt*Ip[kd*Od(N.L) + ks(R.V)^n]
  // Ref: http://www.whisqu.se/per/docs/graphics8.htm
  // and http://en.wikipedia.org/wiki/Phong_shading
 
  // Get light direction for this fragment
  float3 lightDir = normalize(In.WorldPos - LightPosition); // per pixel diffuse lighting
 
  // Note: Non-uniform scaling not supported
  float diffuseLighting = saturate(dot(In.normal, -lightDir));
 
  // Introduce fall-off of light intensity
  diffuseLighting *= (LightDistanceSquared / dot(LightPosition - In.WorldPos, LightPosition - In.WorldPos));
 
  // Using Blinn half angle modification for perofrmance over correctness
  float3 h = normalize(normalize(CameraPos - In.WorldPos) - lightDir);
 
  float specLighting = pow(saturate(dot(h, In.normal)), SpecularPower);
 
  float4 col = tex2D(Texture, In.TexCoord);
 
// These should be set externally if needed
LightDiffuseColor = float3( 1.0,1.0,1.0 );
LightSpecularColor = float3( 0.0,0.0,0.0 );
 
float3 col3 = float3( EmissiveColor +
    (col.xyz * DiffuseColor * LightDiffuseColor * diffuseLighting * 0.6) + // Use light diffuse vector as intensity multiplier
    (SpecularColor * LightSpecularColor * specLighting * 0.5) + // Use light specular vector as intensity multiplier
    (col.xyz * + AmbientLightColor) // Add ambient color
    );
 
  Out.color = float4(saturate( col3 ), col.w);
  return Out;
}
 
 
technique TechniqueWithTexture
{
  pass Pass1
  {
    VertexShader = compile vs_2_0 mainVS();
    PixelShader = compile ps_2_0 mainPS();
  }
}
 
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Lighting quality on Obj models

Post by mongoose7 »

The only pixel shader *in* Irrlicht is the parallax-mapping shader. There is an example shader in the data folder for Example 10.

Currently, Irrlicht has only three "experts" and only one of them understands shaders. So it is nice that you would want them working on your problem.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Lighting quality on Obj models

Post by robmar »

:roll: I´m not expecting them to work on "my" problem, I´m only trying to achieve quality shading, and I posted the pixel shader I got to work.

Thanks for the feedback, I took a look at what you mentioned, D3D9.HLSL, and its a one-light basic pixel shader.

It would be easy to replace the old asm vertex shader for a pixel shader, would like to know in which file its "hidden" without having to dig through the files.

I´d also like to make it work with the 1,7,3 shadows, which are rough n ready but 30 times faster than the 1.8 shadows (unusable for anything but simple models).

I guess that when an external shader is loaded, for some reason the shadow map pass does not occur.

But what´s the method to get the shadows back on using an external shader?
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Lighting quality on Obj models

Post by mongoose7 »

There is no "shadow map pass" in Irrlicht. Irrlicht does *not* use shadow mapping. The parallax *pixel* shader is probably a string in a .cpp file. It is written in assembler. I don't know anything about Irrlicht shadows, but I find it difficult to imagine there being a substantial change. How has the code changed from 1.7 to 1.8?
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Lighting quality on Obj models

Post by robmar »

Shadows were re-written for 1.8, but although they are more accurately calculated, they overload the CPU immediately on anything but really simple models.

I looked through drawall, and there is a discrete call to render shadows, so I guess in there it looks at the materials type. So just adding a new custom render EMT_??? should do it.... I hope!
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Lighting quality on Obj models

Post by mongoose7 »

Just put default with EMT_SOLID.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Lighting quality on Obj models

Post by robmar »

Meaning? I don't understand..
mongoose7
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: Lighting quality on Obj models

Post by mongoose7 »

switch (materialType) { default: case EMT_SOLID: { <code> } case EMT_...: ... }

With shaders, the materialType is a reference to the shader, so you cannot set the materialType to something else. So you have the specified EMT_XXX values, and shaders take values not in this range.
robmar
Posts: 1125
Joined: Sun Aug 14, 2011 11:30 pm

Re: Lighting quality on Obj models

Post by robmar »

Yes but better to add a new material type to Irrlicht for user-shaders. Will give it a try today and post the results.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Lighting quality on Obj models

Post by hybrid »

Please check example 10 how to add user-shaders. These add new material numbers, you can name them EMT_whatever you want.
The other shaders are stored in the shader material renderer files in source/Irrlicht. The user shaders are stored either in the cpp file of the example or in separate hlsl/glsl files in media.
Post Reply