scaling objects with a shader material added

The place for artists, modellers, level designers et al to discuss their approaches for creating content for OGRE.
Post Reply
stewypeza
Gnoblar
Posts: 16
Joined: Thu Feb 09, 2006 4:20 pm

scaling objects with a shader material added

Post by stewypeza »

Hi all

Im having trouble applying shader materials to objects without a .skeleton file.

The ogrehead.mesh model i can scale and position fine without a shader material applied to it but as soon as i apply the material it ignors the scaling and positioning of the model. This only works with models which have a .skeleton file with the mesh.

Is there a way to get aorund this or..

Im using oFusion with max to export the models to .mesh format. Is there a way oFusion can export a .skeleton file as well.

The shader material i am trying to add is exported from rendermonkey.

Thanks

stuart
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Post by haffax »

What kind of shader is involved? Pixel shader, vertex shader, both? What is it supposed to do?

Main difference between skinned and unskinned models is, that the former are in world space and the latter are in object space when handed over to the GPU. So you maybe don't transform the vertices in your vertex shader at all?
team-pantheon programmer
creators of Rastullahs Lockenpracht
stewypeza
Gnoblar
Posts: 16
Joined: Thu Feb 09, 2006 4:20 pm

Post by stewypeza »

what it is, is..

i have created the shader seperately in rendermonkey and exported it using the rendermonkey ogre exporter. It is just pixel shader stuff tho.

Then using max7 i have created an object and all i want to do is to export the model so i can get it in the .mesh format. I couldn;t get the original ogre exporter to work so i am using the oFusion to export the scene but just using the .mesh file from the export.

Then in the ogreSDK itself i am just creating the entity from the .mesh model as usual. and appying the exported material from rendermonkey as usual using ..

->setmaterial(Examples/Velvet)

This works and i can see the model with the correct material but if i want to scale the model or repositon it, it wont let me with this material applied. But if i remove the material then i can scale and reposition the object fine.

If i replace my exported model with the ninja, then i can apply my exported material to it and can also scale and reposition it. (This is what i wan tbut with my models)

I found that its the mdoels with a .skeleton file which can be applied with my texture and also be scaled etc.

I dont know if im doing somethign wrong or how i can get .skeleton file withmy exported models from max so may models can also work properly. Or if the problem can be solved in an entirely different way
?

Thanks for your help

Stuart
Lioric
Google Summer of Code Mentor
Google Summer of Code Mentor
Posts: 295
Joined: Fri Aug 06, 2004 10:25 pm

Post by Lioric »

Shaders get the data from the mesh stream buffers, and scale is not part of the mesh but is part of the node matrix, and seems your vertex shaders is not using node data as a parameter

You can add a scale parameter to your shader and update it with the current node scale
stewypeza
Gnoblar
Posts: 16
Joined: Thu Feb 09, 2006 4:20 pm

Post by stewypeza »

I did think it was to do with the shader material but as it works with the ninja mesh and the robot, i figured it was to do with the mesh rather than the shader?
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Post by haffax »

stewypeza, the reason is what I wrote in my earlier post. What part is unclear?
team-pantheon programmer
creators of Rastullahs Lockenpracht
stewypeza
Gnoblar
Posts: 16
Joined: Thu Feb 09, 2006 4:20 pm

Post by stewypeza »

Well it seems to me that u are saying that the shaders are the problem but if these shaders work with the models that come with the ogre SDK then im thinking it is to do with my exported models rather than the shaders?
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Re: scaling objects with a shader material added

Post by haffax »

stewypeza wrote:The ogrehead.mesh model i can scale and position fine without a shader material applied to it but as soon as i apply the material it ignors the scaling and positioning of the model. This only works with models which have a .skeleton file with the mesh.
This is what you said as a problem description. My answer above applies to this.

What part is unclear?
team-pantheon programmer
creators of Rastullahs Lockenpracht
stewypeza
Gnoblar
Posts: 16
Joined: Thu Feb 09, 2006 4:20 pm

Post by stewypeza »

im sorry. i must not understand what you wrote. Could you explain again but more simply for simple ole me

thanks
User avatar
haffax
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4823
Joined: Fri Jun 18, 2004 1:40 pm
Location: Berlin, Germany
x 8
Contact:

Post by haffax »

A mesh without a skeleton is saved in a buffer within its local coordinate system and in this way turned in to the vertex shader. The position, orientation and scale of the model is determined with its modelview matrix. The vertex shader needs to apply this to the input vertices in the vertex shader.

This doesn't apply to a software skinned model with a skeleton. Here the vertices have to be transformed by Ogre on the CPU anyway, so to save the GPU some work it also applies the modelview matrix, cause it doesn't come with any extra cost. So the vertices the vertex shader sees are already tranformed.

What you need are two versions of your vertex shader (and thus two materials). One for meshes with a skeleton and one for meshes without. The one for meshes with skeletons can stay how it is, the one for meshes without has to be changed so, that the modelview and projection matrix are applied. In glsl this is as simple as adding the line: gl_Position = ftransform();
In hlsl you have to multiply the incoming vertices with the worldviewproj_matrix matrix. See Ogre manual section 3.1.5 for how to change your material accordingly, glsl doesn't need a change, hlsl needs to have the worldviewproj_matrix added as an auto parameter.

If you don't understand what I am talking about, you need to read some documentation on shaders, else working with them will be nearly impossible.
team-pantheon programmer
creators of Rastullahs Lockenpracht
LaKing
Kobold
Posts: 26
Joined: Sat Jan 01, 2005 9:38 pm
Location: Hungary
Contact:

Post by LaKing »

im haveing the same problem now. Well, im new to materials, and have some questions wich i will start a thread for.

Haveing 2 materials for a .mesh doesent seems to be right. My preferred solution would be to have a .skeleton for each .mesh. I tryed to create an empty .skeleton, but it didnt work. I saw the main tags in the XMl, they been all empty. What do i need to do in blender to link it with my model, besides creating an armature?

Is there any way to create a generic .skeleton, wich actually does nothing, but works with all modells?

Or is there any command to tell Ogre to act with a modell like with an emty skeleton?

thx
LaKing
Kobold
Posts: 26
Joined: Sat Jan 01, 2005 9:38 pm
Location: Hungary
Contact:

Post by LaKing »

As for editing material files in DX9 i see that replaceing
param_indexed_auto 0 viewproj_matrix
with
param_indexed_auto 0 worldviewproj_matrix
helps in some cases, ..
isnt that a bug in the RmOgre exporter?

and another question:
Are parameters associative? I mean are the parameters passed to the shader programs ordered?
Post Reply