More elements for ManualObjects.

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
mkultra333
Gold Sponsor
Gold Sponsor
Posts: 1869
Joined: Sun Mar 08, 2009 5:25 am
x 20

More elements for ManualObjects.

Post by mkultra333 » Wed Nov 27, 2013 6:58 am

[Edit: I mention ManualObjects not supporting tangents in this first post. That's wrong, they do support tangent, so ignore that. Just focus on the specular part.]

This is in 1.8.1, so I don't know if it's still relevant to 1.9.

I construct my map from manual objects and then convert to mesh later, it's just much easier than constructing a mesh from scratch. I decided to do some memory optimizing for my map, converting the normal and tangent to diffuse and specular colours, so that they'd each take only 4 bytes instead of 12 bytes.

Problem was, ManualObjects will only take a diffuse colour, not a specular one. At least, as far as I can tell. It would have been a major pain to re-write my map construction function to build a mesh from scratch rather than use a manual object. So I went to the Ogre source and modified it. It was actually very simple to enable adding specular as well as diffuse colouring, I basically just copied what was already being done for diffuse. (It might now matter whether I add diffuse or spec first... since I always add diffuse first, it isn't a problem.) So far my addition seems to work fine, and the resulting meshes are indeed more compact.

Several times I've run into the hassle of manual objects not supporting enough elements. They seem to only support position, colour, normal and uv. From looking at the source code, and doing my own modification, it seems very easy to improve on this, and allow the user to add things like specular colour or tangents as well.

I think the current ManualObject type is overly sparse. I understand that it's supposed to be simple, but there's such a big jump between what you can do with meshes and what you can do with manual objects, and there needn't be. Creating manual objects is much simpler and more convenient that constructing a mesh, so it'd be very handy if you could add things like specular colour and maybe tangents as well.

It wouldn't really make ManualObjects any more complicated for new users, since they can simply ignore adding specular and tangent if they want.

So anyhow, a vote for adding specular and maybe tangent to the ManualObjects. It's a very easy fix and adds a lot to the usefulness of manual objects.
Last edited by mkultra333 on Wed Nov 27, 2013 2:44 pm, edited 1 time in total.
0 x
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.

User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4291
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 2
Contact:

Re: More elements for ManualObjects.

Post by spacegaier » Wed Nov 27, 2013 10:58 am

Isn't your scenario something that could be handled by the generic extension possibility of setUserData(Ogre::Any data). Implemented by MovableObject and ManualObject inherits it:

http://www.ogre3d.org/docs/api/html/cla ... 30e9d0ec81
0 x
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...

User avatar
mkultra333
Gold Sponsor
Gold Sponsor
Posts: 1869
Joined: Sun Mar 08, 2009 5:25 am
x 20

Re: More elements for ManualObjects.

Post by mkultra333 » Wed Nov 27, 2013 11:27 am

Isn't your scenario something that could be handled by the generic extension possibility of setUserData(Ogre::Any data).
Did you mean "setUserAny?" (As opposed to "setUserData") That's what that link refers to.

Hmm, I don't think so. The diffuse (normal) and specular (tangent) are different from vertex to vertex, and need to be read by the HLSL vertex program, just like UV data. Plus it just seems simpler to be able to set a diffuse AND specular value for each vertex, since you can already set a diffuse.

I can't say I really understand setUserAny. How would you use it to set per-vertex ubyte values that can be read by the vertex shader? Can you give some sample code?
0 x
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.

User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7147
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 16

Re: More elements for ManualObjects.

Post by Kojack » Wed Nov 27, 2013 11:38 am

setUserData lets you attach a single value to an entire mesh (like an id number or pointer) which ogre will ignore (since only the user needs to know what it means).

What mkultra333 is talking about is missing flexible vertex format elements. The ManualObject class provides diffuse colour, position, normal, tangent and 8 texture coordinate sets per vertex. But vertex buffers actually support more options like specular colour, bone indices, bone weightings, point size, and post transformed positions.
So for example it's currently impossible to create a ManualObject that supports skeleton animation or point sprites with individual sizes rather than a global size. (They can be made with a SimpleRenderable or manually making a mesh, but those require a lot more code and setting up than the friendly ManualObject class)
.
ManualObject really shouldn't be limited to a subset of half of what ogre can otherwise do with the more annoying manual setting up of hardware buffers and element types.
0 x

User avatar
mkultra333
Gold Sponsor
Gold Sponsor
Posts: 1869
Joined: Sun Mar 08, 2009 5:25 am
x 20

Re: More elements for ManualObjects.

Post by mkultra333 » Wed Nov 27, 2013 11:48 am

Yeah, what Kojack said.

Actually I didn't realise ManualObject already supported tangent, probably because you can't get ogre to automatically generate tangents on a manual object but you can on a mesh, another area I think ManualObjects are missing out unnecessarily. (Although it isn't difficult to convert to a mesh and then generate the tangents, so that one never bothered me much.)

That still leaves poor VES_BINORMAL out in the cold though, along with VES_SPECULAR, VES_BLEND_WEIGHTS and VES_BLEND_INDICES.

It was really the lack of VES_SPECULAR that impacted me, so at the very least I think that should be added, especially given how easy it is to add. But once down that path, there's probably no reason not to add the others too.
0 x
"In theory there is no difference between practice and theory. In practice, there is." - Psychology Textbook.

User avatar
spacegaier
OGRE Team Member
OGRE Team Member
Posts: 4291
Joined: Mon Feb 04, 2008 2:02 pm
Location: Germany
x 2
Contact:

Re: More elements for ManualObjects.

Post by spacegaier » Wed Nov 27, 2013 1:56 pm

mkultra333 wrote:The diffuse (normal) and specular (tangent) are different from vertex to vertex, and need to be read by the HLSL vertex program, just like UV data.
Yes, the idea was that you'd pass it a structure/class (according to the documentation that should work) that for each vertex has the additional information (basically an array of sorts). Wasn't aware of the shader part. But can't one (at least in theory...not saying that this whole concept here is the most feasible in retrospect ;) ) read the values each frame from the UserAny array and update the shader params based on them? Just a theoretical idea...
0 x
Ogre Admin [Admin, Dev, PR, Finance, Wiki, etc.] | BasicOgreFramework | AdvancedOgreFramework
Don't know what to do in your spare time? Help the Ogre wiki grow! Or squash a bug...

scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 2

Re: More elements for ManualObjects.

Post by scrawl » Wed Nov 27, 2013 2:31 pm

spacegaier wrote:read the values each frame from the UserAny array and update the shader params based on them?
No. The per-vertex values need to be part of the vertex declaration. You can't just throw them at the shader, they need to be set up in advance.
0 x

Post Reply