SpecBump shaders, not working with oFusion [SOLVED]

Foxer

21-05-2006 18:49:45

I'm having problems with SpecBump maps in Dagon.
Here's a quick link to a previous thread: http://www.ogre3d.org/phpBB2/viewtopic.php?p=150272#150272

I followed the tutorial 5 at oFusion's site, although that's for the previous version - Azathoth which supports cg 1.0 dll's
Dagon in the other hand supports cg 1.4 dll's and there lies my problem.

How must I change the shaders made for Azathoth (work fine with 1.0) to work with Dagon?

I hope someone can help with this, thanks :)

Hornet

21-05-2006 22:16:16

Okey, heres what we think is going on:

oFusion is designed for azeroth, were using dagon. We think theres a porting issue happening between the two versions and were unsure of how to fix it.

Foxer

23-05-2006 14:27:12

Very helpful forum indeed...

BlasterN

23-05-2006 19:42:21

How must I change the shaders made for Azathoth (work fine with 1.0) to work with Dagon?

See porting notes. But i think you cant find info. Are you sure that don't work in Dagoon I use the same in the example and works.
update the driver, maybe solve the problem.

Foxer

23-05-2006 23:56:55

I cant find anything usable..
I used this code in the material file:
material Material_#1203/panel_c
{
technique
{
pass
{
diffuse 1.0 1.0 1.0 1
specular 1.0 1.0 1.0 1 20

vertex_program_ref BumpMap_vs
{
param_named_auto view_proj_matrix worldviewproj_matrix
param_named_auto inv_view_matrix inverse_worldview_matrix
param_named_auto light_position light_position_object_space 0
param_named_auto eye_position camera_position_object_space
}

fragment_program_ref BumpMap_ps
{
param_named bumpiness float 0.6
param_named_auto ambient ambient_light_colour
param_named Ka float 0.3
param_named_auto diffuse light_diffuse_colour 0
param_named Kd float 1
param_named_auto specular light_specular_colour 0
param_named Ks float 1
param_named specular_power float 64
}

texture_unit
{
texture panel_c.jpg
}

texture_unit
{
texture panel_norm.jpg
}
}
}
}


And I used this in the .program file:
//CG Pixel Shader ps_2_0
fragment_program BumpMap_ps cg
{
source BumpMap_ps.source
profiles ps_2_0 arbfp1 fp20
entry_point main

default_params
{
param_named Ka float 0.30
param_named Kd float 1.0
param_named Ks float 1.0
param_named_auto ambient ambient_light_colour
param_named_auto diffuse light_diffuse_colour 0
param_named_auto specular light_specular_colour 0
param_named bumpiness float 1.0
param_named specular_power float 64.0

}
}

//CG Vertex Shader vs_2_0
vertex_program BumpMap_vs cg
{
source BumpMap_vs.source
profiles vs_2_0 arbvp1
entry_point main

default_params
{
param_named_auto view_proj_matrix worldViewProj_matrix
param_named_auto inv_view_matrix inverse_worldView_matrix
param_named_auto light_position light_position_object_space 0
param_named_auto eye_position camera_position_object_space
}
}


And in ogre.log I get this error:

08:14:52: Error in material Material_#1203/panel_c at line 10 of hyperion.material: Invalid vertex_program_ref entry - vertex program BumpMap_vs has not been defined.
08:14:52: Error in material Material_#1203/panel_c at line 18 of hyperion.material: Invalid fragment_program_ref entry - fragment program BumpMap_ps has not been defined.


I just dont get it what's going on...
If anyone can, then please post your BumpMap_ps and BumpMap_vs files made by following Tutorial 5...
If you say they work in the newer version of Ogre, then it must be in those files...
Unless it doesnt work simply because I dont have ambient colour? :lol:
Because, that would be rather awkward...

Thanks for your help BlasterN :roll:

Foxer

24-05-2006 00:08:46

Ok this is one of the similar errors that ogre.log throws at me:

-----------------------------------
Details:
-----------------------------------
Error #: 7
Function: GpuProgramParameters::getParamIndex
Description: Cannot find a parameter named Ka.
File: \OgreDev\Dagon\OgreMain\src\OgreGpuProgram.cpp
Line: 768
Stack unwinding: <<beginning of stack>>
01:45:24: Error at line 19 of BumpMap.program: Invalid param_named attribute - An exception has been thrown!

-----------------------------------
Details:
-----------------------------------
Error #: 7
Function: GpuProgramParameters::getParamIndex
Description: Cannot find a parameter named Ka.
File: \OgreDev\Dagon\OgreMain\src\OgreGpuProgram.cpp
Line: 768
Stack unwinding: <<beginning of stack>>
01:45:24: An exception has been thrown!


After that it brings other errors exactly the same, the only difference is that the parameters go from Kd to specular_power...

Lioric

24-05-2006 17:40:34

Is this issue with GL and D3D9 render systems?

You will test this by creating a simple nop shader (a shader that does nothing) with the similar structure (the parameters and arguments) to those shaders you need to work, and then start to add fragments of the code until you find why what part is presenting the issue

The bump shader examples uses a struct(s) as the main method arguments, test by changing the parameters to be declared in the main method arguments, i.e.

vertex shader:

mainEntryPoint(float4 position: POSITION, ...)


fragment shader:

mainEntryPoint(float2 bump_map : TEXCOORD0,
uniform float4 specular,
...
)

Foxer

24-05-2006 19:26:54

Doesnt really help that much really, I dont have much experience with OGRE (2 weeks tops).

Could anyone please paste the code used in the BumpSpec_vs and BumpSpec_ps, BumpSpec.program file that do work with the newer release - Dagon.

Thanks :)

Evak

24-05-2006 20:32:45

hmm, I just tried the specbump tutorials and am having the same problem as you.

Foxer

24-05-2006 21:56:02

Alot of people get the same error message. We have about 10 people on utterly different PC's (dominated by ATI cards though) having the exact same problem, so it's definently not the graphics card.

And as I said before, the shaders worked fine with the previous version of nVidia's CG (1.0), but not with the latest in Dagon (1.4).

So, therefore the shaders made with that tutorial just wont work...

Could Lioric help?

BlasterN

24-05-2006 23:00:53

//CG Pixel Shader ps_2_0
fragment_program tutorial_BumpMap_ps cg
{
source tutorial_BumpMap_ps.source
profiles ps_2_0 arbfp1 fp20
entry_point main

default_params
{
param_named Ka float 0.30
param_named Kd float 1.0
param_named Ks float 1.0
param_named_auto ambient ambient_light_colour
param_named_auto diffuse light_diffuse_colour 0
param_named_auto specular light_specular_colour 0
param_named bumpiness float 1.0
param_named specular_power float 64.0

}
}

//CG Vertex Shader vs_2_0
vertex_program tutorial_BumpMap_vs cg
{
source tutorial_BumpMap_vs.source
profiles vs_2_0 arbvp1
entry_point main

default_params
{
param_named_auto view_proj_matrix worldViewProj_matrix
param_named_auto inv_view_matrix inverse_worldView_matrix
param_named_auto light_position light_position_object_space 0
param_named_auto eye_position camera_position_object_space
}
}



//float4 specular: register(c2);
//float Ka: register(c3);
//float Kd: register(c4);
//float Ks: register(c5);
//float specular_power: register(c6);
//float bumpiness: register(c7);
//float4 ambient: register(c0);
//float4 diffuse: register(c1);
sampler base_map: register(s0);
sampler bump_map: register(s1);
struct PS_INPUT_STRUCT
{
float2 bump_map: TEXCOORD0;
float3 light_vector: TEXCOORD1;
float3 half_angle: TEXCOORD2;
};

struct PS_OUTPUT_STRUCT
{
float4 color0: COLOR0;
};

//**---------------------------------------------------------
//** Function: main
//** Description: Declare the main entry point for the shader
//** Input: PS_INPUT_STRUCT, derived from the output of
//** the associated vertex shader
//** Returns: PS_OUTPUT_STRUCT
//**---------------------------------------------------------
PS_OUTPUT_STRUCT main( PS_INPUT_STRUCT psInStruct,
uniform float Ka,
uniform float Kd,
uniform float Ks,
uniform float specular_power,
uniform float bumpiness,
uniform float4 ambient,
uniform float4 diffuse,
uniform float4 specular )
{
PS_OUTPUT_STRUCT psOutStruct; //** Declare the output struct

//**------------------------------------------------------
//** Retreive the base color and bump components from the
//** respective textures, based on the passed bump coords.
//**------------------------------------------------------
float3 base = tex2D( base_map, psInStruct.bump_map );
float3 bump = tex2D( bump_map, psInStruct.bump_map );

//**----------------------------------------------------
//** Normalize the passed vectors from the vertex shader
//**----------------------------------------------------
float3 normalized_light_vector = normalize( psInStruct.light_vector );
float3 normalized_half_angle = normalize( psInStruct.half_angle );

//**--------------------------------------------------------
//** "Smooth out" the bump based on the bumpiness parameter.
//** This is simply a linear interpolation between a "flat"
//** normal and a "bumped" normal. Note that this "flat"
//** normal is based on the texture space coordinate basis.
//**--------------------------------------------------------
float3 smooth = { 0.5f, 0.5f, 1.0f };
bump = lerp( smooth, bump, bumpiness );
bump = normalize( ( bump * 2.0f ) - 1.0f );

//**---------------------------------------------------------
//** These dot products are used for the lighting model
//** equations. The surface normal dotted with the light
//** vector is denoted by n_dot_l. The normal vector
//** dotted with the half angle vector is denoted by n_dot_h.
//**---------------------------------------------------------
float4 n_dot_l = dot( bump, normalized_light_vector );
float4 n_dot_h = dot( bump, normalized_half_angle );

//**--------------------------------------
//** Calculate the resulting pixel color,
//** based on our lighting model.
//** Ambient + Diffuse + Specular
//**--------------------------------------
psOutStruct.color0.rgb =
( base * ambient * Ka ) +
( base * diffuse * Kd * max( 0.0f, n_dot_l ) ) +
( specular * Ks * pow( max( 0.0f, n_dot_h ), specular_power ) );
psOutStruct.color0.a = 1.0f; //** Set the alpha component manually

return psOutStruct; //** Return the resulting output struct
}



//float4x4 view_proj_matrix: register(c0);
//float4 light_position: register(c8);
//float4 eye_position: register(c9);
//float4x4 inv_view_matrix;
struct VS_INPUT_STRUCT
{
float4 position: POSITION;
float3 normal: NORMAL;
float2 texcoord0: TEXCOORD0;
float3 tangent: TEXCOORD1;
};

struct VS_OUTPUT_STRUCT
{
float4 position: POSITION;
float2 bump_map: TEXCOORD0;
float3 light_vector: TEXCOORD1;
float3 half_angle: TEXCOORD2;
};

//**---------------------------------------------------------
//** Function: main
//** Description: Declare the main entry point for the shader
//** Input: VS_INPUT_STRUCT, derived from the stream
//** mapping parameters defined in the workspace
//** Returns: VS_OUTPUT_STRUCT
//**---------------------------------------------------------
VS_OUTPUT_STRUCT main( VS_INPUT_STRUCT vsInStruct,
uniform float4x4 view_proj_matrix,
uniform float4 light_position,
uniform float4 eye_position,
uniform float4x4 inv_view_matrix )
{
VS_OUTPUT_STRUCT vsOutStruct; //** Declare the output struct

//**-----------------------------------------------------------
//** Calculate the pixel position using the perspective matrix.
//**-----------------------------------------------------------
vsOutStruct.position = mul( view_proj_matrix, vsInStruct.position );

//**----------------------------------------------
//** Pass the bump and base texture coords through
//**----------------------------------------------
vsOutStruct.bump_map = vsInStruct.texcoord0;

//**----------------------------------------------
//** Calculate the Binormal vector
//**----------------------------------------------
float3 binormal = cross(vsInStruct.tangent, vsInStruct.normal);

//**--------------------------------------------
//** Calculate the light vector in object space,
//** and then transform it into texture space.
//**--------------------------------------------
float3 temp_light_position = mul( inv_view_matrix, light_position );
float3 temp_light_vector = temp_light_position - vsInStruct.position;
vsOutStruct.light_vector.x = dot( temp_light_vector, vsInStruct.tangent );
vsOutStruct.light_vector.y = dot( temp_light_vector, binormal );
vsOutStruct.light_vector.z = dot( temp_light_vector, vsInStruct.normal );

//**-------------------------------------------
//** Calculate the view vector in object space,
//** and then transform it into texture space.
//**-------------------------------------------
float3 temp_eye_position = mul( inv_view_matrix, eye_position );
float3 temp_view_vector = temp_eye_position - vsInStruct.position;
float3 temp_view_vector2;
temp_view_vector2.x = dot( temp_view_vector, vsInStruct.tangent );
temp_view_vector2.y = dot( temp_view_vector, binormal );
temp_view_vector2.z = dot( temp_view_vector, vsInStruct.normal );

//**-------------------------
//** Calculate the half angle
//**-------------------------
vsOutStruct.half_angle = vsOutStruct.light_vector + temp_view_vector2;

return vsOutStruct; //** Return the resulting output struct
}



material Material_#361/gold
{
technique
{
pass
{
vertex_program_ref tutorial_BumpMap_vs
{
}

fragment_program_ref tutorial_BumpMap_ps
{
}

texture_unit
{
texture RustySteel.jpg
}

// Base bump map
texture_unit
{
texture NMBumpsOut.png
colour_op replace
}

}
}
}


Edited. WORKS! I tested, Geforce 6600GT

BlasterN

24-05-2006 23:16:18

I Ok edited. Now works 100%.

Changes.
All params in the entry header. nfz said in the past.
float matrixs param in the last place in the header.
remove diffuse-specular in the material ( why are you using it ? )
All param_named_auto into the program instead the .material, i dont test ir in the material, should work but I dont have time to test everything.

Foxer

25-05-2006 07:51:06

Thank You! It works like a charm :)

Really appreciate your help :roll:

Evak

26-05-2006 07:49:58

hey that worked great, wish I were a better programmer. Seems like it shouldn't be too hard to add a specular map using an greyscale alpha type map to adjust the specularity.

Anyway this works great, thanks for the post Blaster :). Hope someday we can convert the Max created FX HLSL shaders to Ogre ones, and make the whole basic shader materials a lot easier. I'm still from the old school of blendmodes and passes, and this shader stuff is quite comples for me.

BlasterN

27-05-2006 11:39:07

see this. maybe your dreams came true in a short time ^^

http://www.ogre3d.org/phpBB2/viewtopic.php?t=20112

Evak

03-06-2006 06:42:45

BTW I'm having a problem with the above shader in that it doesn't seem to be recieving the specular highlight from the actual light source in the scene, but relative to the player instead.

so when viewing a brick texture on my building, I can view it from any side, and the specular sheen always comes from the top left as I turn in that direction. Even when looking at the shadow side of the building.

BlasterN

04-06-2006 19:30:48

maybe you have to turn on clockwise culling in the material. Or some params must be _object_space.

I cant test it now, I only have my laptop here (PIII 450 ^^)
I'll get my new computer in around two weeks.

BTW: i think that shader can only be used in closed polygons.

Evak

04-06-2006 20:33:31

ah thanks for the tips. you might be right, the lighting seemed ok on a sphere and basic curved primitives. I'll have to look into it some more see if I can figure anything out.

I'm not at all familiar with coding shaders as previous engine I have used, used simple max materials with the bump. specular and mask max material types mix shaders that could be combined and used on at the time Xbox hardware.

Nudel

06-07-2006 17:16:29

BTW I'm having a problem with the above shader in that it doesn't seem to be recieving the specular highlight from the actual light source in the scene, but relative to the player instead.

so when viewing a brick texture on my building, I can view it from any side, and the specular sheen always comes from the top left as I turn in that direction. Even when looking at the shadow side of the building.

got the same problem. did you find a solution?

Evak

06-07-2006 17:40:05

http://www.ogre3d.org/phpBB2/viewtopic. ... 4&start=50

i found this worked a lot better in ofusion, but i am having a few problems in our dagon engine. looking into that as soon as my damned keyboard stops locking CTRL on :(

its near the end of the thread, one of Liorics posts with source.

BTW the monster shader works fine in Dagon. Somehow my .material ended up with an extra space, which is why it wouldn't work previously