Problem with "Using Render Monkey Shaders" Tutor.

Danny

07-09-2006 14:53:18

Hi, I'm making the tutorial of the RenderMonkey and have a problem. After doing everything what the tutorial says, does not appear none of the parameters of the Shader. Why?.

Archive (tutorial_BumpMap.program):

//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
}
}

Archive (tutorial_BumpMap_ps.source):

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 )
{
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
}

Archive (tutorial_BumpMap_vs.source):

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 )
{
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
}

Lioric

07-09-2006 17:05:45

See this thread for the solution:

http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=2056&highlight=render+monkey

Danny

10-09-2006 19:46:18

Thank you very much by your aid. I have been able to do the tutorial loading the previous Ogre engine version.