Normal Mapping and no fog, but i need fog... help

Posted By: dead_poet

Normal Mapping and no fog, but i need fog... help - 12/14/05 23:22

whys the fog-calculation not working in the following pixelshader part of my normal mapping shader?

i already tried playing with the vertexshaderconstant[12] but nothinh got it to work

bold out the fog-part for you, please help!

Code:
         VertexShaderConstant[0]=<matWorldViewProj>;
VertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[9]= <vecFog>;
vertexShaderConstant[10]=<vecSunDir>;
vertexShaderConstant[11]=<vecLight>;
VertexShaderConstant[12]={0.5f, 0.5f, 10.0f, 10.0f};

VertexShader =
asm
{
vs_1_1 // Declarations

dcl_position v0
dcl_normal v3
dcl_texcoord0 v7
dcl_texcoord1 v8

m4x4 oPos, v0, c0 // Transform position to clip space

m3x3 r3, v8, c4 // Tranform normal and tangent to world space
m3x3 r5, v3, c4

mul r0, r3.zxy, r5.yzx // Compute binormal
mad r4, r3.yzx, r5.zxy, -r0

dp3 r0.x, r3.xyz, -c10 // Transform (Sun)light vector to tangent space
dp3 r0.y, r4.xyz, -c10
dp3 r0.z, r5.xyz, -c10

dp3 r0.w, r0, r0 // Normalize transformed light vector
rsq r0.w, r0.w
mul r0, r0, r0.w

mad r0, r0, c12.x, c12.x // Put light vector in range from 0 to 1
mul r0, r0, c12.y // Adjust the intensity
add oD0.xyz,r0,c11 // Add environment light then send it down the diffuse pipe

// Fog calculations
mov r1.w,c9.w
dp4 r0,v0,c6 // distance to camera position
add r0,r0,-c9.x // distance-fog_start

//float3 PositionWorld = mul(inPos, matWorld);
//float ofog = 1 - (distance(PositionWorld, vecViewPos) - vecFog.x) * (vecFog.z*1.5);
//Out.Fog = ofog;
mad r0.x,-r0.x,c9.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start))
max oFog,r0.x,c12.w // clamp with custom max value

// Pass the texture coordinates through
mov oT0, v7
mov oT1, v7
};



Code:
 //float3 PositionWorld = mul(inPos, matWorld);
//float ofog = 1 - (distance(PositionWorld, vecViewPos) - vecFog.x) * (vecFog.z*1.5);
//Out.Fog = ofog;
mad r0.x,-r0.x,c9.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start))
max oFog,r0.x,c12.w // clamp with custom max value




thanks in advance
Posted By: Steempipe

Re: Normal Mapping and no fog, but i need fog... help - 12/15/05 00:34

Do you actually have a fog color, and range, setup in the project??
Posted By: dead_poet

Re: Normal Mapping and no fog, but i need fog... h - 12/15/05 11:08

of course...

Quote:


Camera.fog_start = 2000;
Camera.fog_end = 7000;
D3D_FogColor1.red = 193;
D3D_FogColor1.green = 205;
D3D_FogColor1.blue = 215;
fog_color = 1;




Posted By: zefor

Re: Normal Mapping and no fog, but i need fog... h - 12/15/05 13:49

Is this on a model? Try checking "No Fog" under the models properties.
Posted By: dead_poet

Re: Normal Mapping and no fog, but i need fog... h - 12/15/05 13:57

yep, its on a model!

tried switching nofog no success
Posted By: zefor

Re: Normal Mapping and no fog, but i need fog... h - 12/15/05 14:52

In the wiki under "shaders" "Shader hints" there is something about implementing fog in shaders. Worth a try?
Posted By: dead_poet

Re: Normal Mapping and no fog, but i need fog... h - 12/15/05 14:57

tried but too bad thats for hsls shaders...

any shaderfreak spotted an error in my shader?
Posted By: Steempipe

Re: Normal Mapping and no fog, but i need fog... h - 12/15/05 15:37

What version of the engine are you running??
Posted By: dead_poet

Re: Normal Mapping and no fog, but i need fog... h - 12/15/05 16:11

6.31.4 pro, newest non-beta version
Posted By: Matt_Aufderheide

Re: Normal Mapping and no fog, but i need fog... h - 12/15/05 20:38

this could be your problem:
dp4 r0,v0,c6 // distance to camera position

you dont have c6 defined it seems.. try defining c6 as vecViewPos
Posted By: Steempipe

Re: Normal Mapping and no fog, but i need fog... help - 12/15/05 20:56

On the other hand, you can try this also. In the blue ink.


Code:

VertexShaderConstant[0]=<matWorldViewProj>;
VertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[9]= <vecFog>;
vertexShaderConstant[10]=<vecSunDir>;
vertexShaderConstant[11]=<vecLight>;
VertexShaderConstant[12]={0.5f, 0.5f, 10.0f, 10.0f};
VertexShaderConstant[14]=<matWorldView>;

VertexShader =
asm
{
vs_1_1 // Declarations

dcl_position v0
dcl_normal v3
dcl_texcoord0 v7
dcl_texcoord1 v8

m4x4 oPos, v0, c0 // Transform position to clip space

m3x3 r3, v8, c4 // Tranform normal and tangent to world space
m3x3 r5, v3, c4

mul r0, r3.zxy, r5.yzx // Compute binormal
mad r4, r3.yzx, r5.zxy, -r0

dp3 r0.x, r3.xyz, -c10 // Transform (Sun)light vector to tangent space
dp3 r0.y, r4.xyz, -c10
dp3 r0.z, r5.xyz, -c10

dp3 r0.w, r0, r0 // Normalize transformed light vector
rsq r0.w, r0.w
mul r0, r0, r0.w

mad r0, r0, c12.x, c12.x // Put light vector in range from 0 to 1
mul r0, r0, c12.y // Adjust the intensity
add oD0.xyz,r0,c11 // Add environment light then send it down the diffuse pipe

// Fog calculations
mov r1.w,c9.w
dp4 r0,v0,c16 // distance to camera position
add r0,r0,-c9.x // distance-fog_start

//float3 PositionWorld = mul(inPos, matWorld);
//float ofog = 1 - (distance(PositionWorld, vecViewPos) - vecFog.x) * (vecFog.z*1.5);
//Out.Fog = ofog;
mad r0.x,-r0.x,c9.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start))
max oFog,r0.x,c12.w // clamp with custom max value

// Pass the texture coordinates through
mov oT0, v7
mov oT1, v7
};



Posted By: dead_poet

Re: Normal Mapping and no fog, but i need fog... h - 12/15/05 22:02

nice, the matrix-thingy got it to work, thanks a lot, dude.
© 2024 lite-C Forums