hlsl - using camPos to get fog

Started by
16 comments, last by suliman 11 years ago

You didn't supplied correct matrix on Irrlicht side and didn't define in shader. Put these changes:


...
core::matrix4 worldViewProj;
core::matrix4 world;
                worldViewProj = driver->getTransform(video::ETS_PROJECTION);
                worldViewProj *= driver->getTransform(video::ETS_VIEW);
                worldViewProj *= driver->getTransform(video::ETS_WORLD);
                world = driver->getTransform(video::ETS_WORLD);
if (UseHighLevelShaders){
                        services->setVertexShaderConstant("matViewProjection", worldViewProj.pointer(), 16);
services->setVertexShaderConstant("World", world.pointer(), 16);
....


float4x4 matViewProjection : register( c0 ); 
float4x4 World : register( c4 ); 
float3 camPos : register( c8 );



// This should be your mesh vertex elements
// so this is questionable
struct VS_INPUT 
{ 
   float4 Position : POSITION0; 
   float2 alphamap : TEXCOORD0; 
   float2 tex : TEXCOORD1; 
}; 



struct VS_OUTPUT 
{ 
   float4 Position : POSITION0; 
   float4 WorldPos : TEXCOORD0; // you cannot have 2 POSITION0!!!
   float2 alphamap : TEXCOORD1; 
   float2 tex : TEXCOORD2; 
}; 


PS_OUTPUT ps_main(in VS_OUTPUT input)
{
...
float Depth = distance( camPos, input.WorldPos.xyz );
...
}

and uncomment relevant stuff in shader

Advertisement

Hmm i do one change at a time and see when the shader breaks:

If i put

float4x4 matViewProjection : register( c0 );
float4x4 World : register( c4 );
float3 camPos : register( c8 );

it breaks. If i comment the first line away it works again. Same thing with changing VS_OUTPUT the way you suggests above; it breaks the shader. Here, if i comment out the WorldPos line the shader works again...


ruct VS_OUTPUT 
{ 
   float4 Position : POSITION0; 
   float4 WorldPos : TEXCOORD0; // unless i comment this line out the shader breaks. Even though it is not used anywhere in the code
   float2 alphamap : TEXCOORD1; 
   float2 tex : TEXCOORD2; 
};
 

You need to see debug output to be able to tell what is wrong. What vertex elements your terrain mesh have?

Could you possibly send me your whole source with media, so i can resolve this in 5 minutes instead of guessing couple of days now?

of course, see the attached file. I still dont find a log with shader errors...

Ok. Give me some time...

EDIT: Done.

irrlichtterrainsplatting.png

you missed this on Irrlicht side, even i posted it above


world          = driver->getTransform(video::ETS_WORLD);

Also, you dont need this:


driver->setFog(...)

http://pastebin.com/d22tjM7H

http://pastebin.com/TsQuyC9j

There was debug output in console window!

Now you should play with fog start/end values.

Nice!
It works exactly as intended now. Im very greatful.

On a sidenote, your edited hlsl code results in 800 FPS whereas I had only 150 before. Do you know where this big gain comes from? Did this correct something wasteful i had before in the code?

Again, thanks a lot belfegor

Erik

Do you know where this big gain comes from?

Irrlicht was printing into console (this is slow!) every frame because you had some errors, and that was the reason for slowdown.

ah the irony. Anyway thanks a lot for your help

Erik

This topic is closed to new replies.

Advertisement