hlsl shader help [SOLVED!]

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!
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

Are you trying to do something like Doom3?
Image

This image is from one of my past bug reports so ignore the weird stuff - the main subject is the Marine character in the centre. http://irrlicht.sourceforge.net/phpBB2/ ... highlight=

I had the four diffusemap/heightmap/normalmap/glossmap combined onto the character, it I remember correctly, but I'll have to retrieve the project from my backups to see how far I got. I remember that the "new" animation system was being planned so I stopped work on this.
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

what vertex type are you using in irrlicht

The tangent and bi tangent seem to be zero and hence no normal perturbation.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

Also you can try and put specular mask in alpha channel of
diffuse texture (for example) so something, instead of (in pixel shader):

Code: Select all

//specular color
  float4 specCol = specularColor*specMap;
do :

Code: Select all

//specular color
  float4 specCol = specularColor*colorMap.a;
EDIT: Just saw it doesnt affect output, it looks like it mising something like
on last line:

C *= colorMap*surfColor*specCol;
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

OMG, now I FINALLY know why. I had forgotten about

Code: Select all

createMeshWithTangents()
until i browsed through belfegor's code. Oh man..... :oops:

Last time, I was using TGM's 4light normalmap shader which doesn't require tangents to be built in irrlicht, and since then forgotten about this.

Thank you everyone for your great help, I had learnt alot of stuff about shaders and vertexes.

BTW, I fixed the specularmap and updated the code in my first post.
DevilSnake
Posts: 6
Joined: Wed Oct 17, 2007 6:27 pm
Location: Germany
Contact:

Post by DevilSnake »

i have a little question, and i don't want to create a new thread.
i would like to load a effect file. there are the functions to load a material from a file, e.g.:

Code: Select all

addHighLevelShaderMaterialFromFiles
my problem is now, i have a fx-file. in this file, there are structs, variables, and functions. finally, there is a technique:

Code: Select all

Technique Low
{
    Pass P1
    {
        Cullmode = CCW;
        
        VertexShader = compile vs_1_1 VertexShader_Low();
        PixelShader  = NULL;
    }
}
is that possible to load such a "system" or must do i have fragments? :wink:
mfg
DevilSnake
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

DevilSnake wrote:is that possible to load such a "system"
No, you can not use .fx effects "system" with current irrlicht.
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

Someone made a patch some months ago so that Effect files could be used. You'd need to search the forums for it.

The tricky thing about Effect files is that they can hold device state - changing state "behind Irrlicht's back" may lead to Irrlicht's internal device state becoming out-of-sync. You can have the DX9 Effect interface save state, but that in itself may reduce performance.
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

I did it with small edit in CD3D9Driver class, something like (might forgat correct names):

Code: Select all

void CD3D9Driver::preCustomRender()
{
   setVertexShader((E_VERTEX_TYPE)666);
   set3DRenderMode();
}

and

void CD3D9Driver::setVertexShader(E_VERTEX_TYPE newType)
{
   if(newType != LastVertexType)
      LastVetexType = newType;
   ...
   case 666:
      break;
   ...
}
and then (for example when you make custom scene node) in render function:

Code: Select all

void render()
{
     ...
     Driver->setMaterial(Material);
     Driver->preCustomRender();//call this so it doesnt break things up

     D3DXMATRIXA16 World(AbsoluteTransformation.pointer());

     ...
     Effect->SetTechnique(...);
     Effect->SetVector(...);
     Effect->SetMatrix("World", &World);
     Effect->CommitChanges();

     ....
}
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

Hello,

Actually I've got another problem: The light vector seems to be out of sync when I rotate the mesh in the x and y vector. The z vector works however. I'm sure there's something to do with the vertex shader, and I can't get it right with any formular. Here's the orginal vertex shader:

Code: Select all

v2f vsmain(in a2v In) 
{ 
v2f Out = (v2f)0; 
    Out.worldNormal = mul(In.normal, worldIT).xyz; 
    Out.worldTangent = mul(In.tangent, worldIT).xyz; 
    Out.worldBinormal = mul(In.binormal, worldIT).xyz; 
    //can use either positive or negative y format normal maps 
    //comment out this if statement to save 6 instructions! 
     //Out.worldTangent = -Out.worldTangent; 
    float3 worldSpacePos = mul(In.position, world); 
    Out.lightVec = lightPosition - worldSpacePos; 
   Out.texCoord.xy = In.texCoord; 
    Out.eyeVec = viewInv[3].xyz - worldSpacePos; 
    Out.position = mul(In.position, wvp); 
    return Out; 
} 
BTW, I've got a question. The mesh's normals that uses the shader isn't smooth. Perhaps it's caused by irrlicht tangents?

Thanks again. :D
DevilSnake
Posts: 6
Joined: Wed Oct 17, 2007 6:27 pm
Location: Germany
Contact:

Post by DevilSnake »

i, i've a second question. that question concerns the world-view-projetion matrix.

i have always written:
all = world * view * projection;
but in irrlicht, that doesn't run. here, i have to write:
all = projection * view * world;

what's the reason for this "occurence"?
thanks for helping :wink:
mfg
DevilSnake
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

jingquan wrote:BTW, I've got a question. The mesh's normals that uses the shader isn't smooth. Perhaps it's caused by irrlicht tangents
As i said you can not achive good results from irrlicht current vertex types
(at least i have not seen that anybody has do it).
DevilSnake wrote:but in irrlicht, that doesn't run. here, i have to write:
all = projection * view * world;

what's the reason for this "occurence"?
Yes, in irrlicht you must do it that way.
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

Any other good recommendation to replace irrlicht vertex type?
belfegor
Posts: 383
Joined: Mon Sep 18, 2006 7:22 pm
Location: Serbia

Post by belfegor »

Add one in irrlicht source. Or do it outside of irrlicht dll as i did
(but you cant use irrlicht material/shader system then).
Small FPS demo made using Irrlicht&NewtonDEMO
InfoHERE
Its at very early stage but i think im crazy enough to finish it all alone.
jingquan
Posts: 222
Joined: Sun Aug 20, 2006 4:10 am
Contact:

Post by jingquan »

jingquan wrote:Hello,

Actually I've got another problem: The light vector seems to be out of sync when I rotate the mesh. I'm sure there's something to do with the vertex shader, and I can't get it right with any formular. Here's the orginal vertex shader:

Code: Select all

v2f vsmain(in a2v In) 
{ 
v2f Out = (v2f)0; 
    Out.position = mul(In.position, wvp); 

    float3 tangent  = float3(abs(In.normal.y) + abs(In.normal.z), abs(In.normal.x), 0);
    float3 binormal = float3(0, abs(In.normal.z), abs(In.normal.x) + abs(In.normal.y));

    Out.worldNormal = mul(In.normal, worldIT).xyz; 
    Out.worldTangent = mul(tangent, worldIT).xyz; 
    Out.worldBinormal = mul(binormal, worldIT).xyz; 

    Out.texCoord.xy = In.texCoord;

    float3 worldSpacePos = mul(In.position, world); 
    Out.lightVec = lightPosition - worldSpacePos;
    Out.eyeVec = viewInv[3].xyz - worldSpacePos; 
    return Out; 
} 
Thanks again. :D
Bump, sry I still cannot figure out how to correct the lighting on a rotating mesh.
Post Reply