Monkey shaders in max error

rubenhonders

22-10-2006 12:15:45

Hey i am trying to use monkey shaders in my project .
i have 3 times try it to get them correct in my project but all 3 times i get the same problem , and i am sure the source files are correct.
problem 1 , if i set the shader active i cannot edit the code


And if i enable the pixel shader i get an error.


here are my codes in rar.
http://home.planet.nl/~honde240/monkeycodes.rar

I hope you can help me , it drives me crazy

rubenhonders

23-10-2006 09:55:08

Is there someone that can help me :cry:

rubenhonders

23-10-2006 10:05:54

Danm i am an asshole , my code was
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


But , i with my asshole head dont know the difference between a , and a .
but after reeding again i have found the right code
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


Now i get no error but into the edit option i did't see any option, please help me

Lioric

23-10-2006 16:26:41

See this thread for the soution to your issue:

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

rubenhonders

26-10-2006 13:47:02

Thanks for your replay but i dont understand it , my english is not so best .

Would you explain what i need to do :oops:

Lioric

26-10-2006 16:42:51

You need to make the shader parameters not globals, but (uniform) function arguments of the main shader method, as noted in the linked post (remove the global paramters and replace the shader function with the function declaration that is in that post)

rubenhonders

29-10-2006 16:42:43

danm i think you gonna laughing me out or you gonna cry , but i dont get it :D
my code
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
}



and if i am correct i need the code
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

To change to
PS_OUTPUT_STRUCT main( PS_INPUT_STRUCT psInStruct,
uniform float4 specular: register(c2),
uniform float Ka: register(c3),
uniform float Kd: register(c4),
uniform float Ks: register(c5),
uniform float specular_power: register(c6),
uniform float bumpiness: register(c7),
uniform float4 ambient: register(c0),
uniform float4 diffuse: register(c1),
uniform sampler base_map: register(s0),
uniform sampler bump_map: register(s1)
)


But if you do that you get a error in max so i think i am doing it
rong :twisted:
Please forgive me for my stupid post but try to stay calm and please help me ;)

Evak

29-10-2006 18:20:17

I think a collection of general purpose simple shaders would be really usefull for the artists amongst us that havent a clue how to code them ourselves.

The monster shader started this by allowing you to adjust some flags for different features without having to code anything yourself. Just turn on the included functions you wanted to use. Unfortunately that was never finished and made feature complete, and no longer works without tweaking, and I don't understand any of the language used to fix it in the various threads.

I'm familiar with fixed functions and simple shader controls and simple max shader controls that basicly let you mix simple shader effects, like mix material type in the diffuse slot for masking 2 textures with a alpha mask and combining those with, bump, specular and reflection maps.

We had those simple controls in our Xbox engine, and it was all that was needed for 80% of materials in the game, other than lighting and FX shaders.

Some simple controls like these would be very useful in ofusion letting people who don't need to wield shaders with a lot of control, just describe a few basic types of materials would be very handy indeed.

masking, bump and specular maps would allow you to describe many things from worn leather, wet to dry sand, worn rusty metal to gauged shiny metal etc.

Any chance of something like this happening somewhere down the road. 3dsmax already does this impressively with its own shader creation tools, only it is too extensive and inefficient plus shader 3 only and not ogre compatible.

Thought I'm mention it because shaders aren't really something thats readily accessible to non coding artists in ogre.

Lioric

09-11-2006 01:25:09

The scene from this tutorial is available and can be downloaded from the Artist's Center, it includes the needed shader files

As posted in other thread, a general purpose shader collection will be in the next versions