Horde3D

Next-Generation Graphics Engine
It is currently 26.11.2024, 12:02

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Vertex Colors?
PostPosted: 02.01.2011, 16:11 
Offline

Joined: 08.11.2010, 10:46
Posts: 35
Geometry does not seem to have vertex colors.
I'm working on something where I need each vertex to have a color, and I need to also combine it with a texture.

Is there a way to set vertex colors for geometry or mesh?


Top
 Profile  
Reply with quote  
 Post subject: Re: Vertex Colors?
PostPosted: 02.01.2011, 17:10 
Offline

Joined: 11.09.2010, 20:21
Posts: 44
Location: Germany
I started a similar discussion some time ago:

viewtopic.php?f=1&t=1244

So just use the skinning data or second texture coordinate or wait for a new version (which could take a while).


Top
 Profile  
Reply with quote  
 Post subject: Re: Vertex Colors?
PostPosted: 03.01.2011, 02:30 
Offline

Joined: 15.02.2009, 02:13
Posts: 161
Location: Sydney Australia
Hi vikingcode,

Here's the patch to make the collada converter use the vertex colours from a dae file and export it into the tangent stream. This isn't ideal as now you can't use normal mapping and it also limits vertex colours to RGB (no A support here, sorry) but hopefully this helps you (for me the vertex coloured objects don't need normal maps so it is OK at the moment). I added a flag to the converter -vertColorsAsTan to enable this, when disabled it should export like normal.

In your GLSL shader you pretty much just add this to your vertex program:
Code:
attribute vec3 tangent;
varying vec3 vertColor;

void main(void)
{
    vertColor = tangent;
}

And in your fragment program:
Code:
varying vec3 vertColor;

void main(void)
{
    gl_FragColor.rgb = vertColor.rgb;
}

Of course you just append that to an existing shader, or do it in another way however you see fit, the important thing is the data is now in the tangent attribute... :)

Ideally I think horde will move to a more custom way of defining vertex streams in future, I remember Marciano or Volker talking about this but I'm not 100% sure. Hope this helps, or inspires you to make your own implementation (hopefully better than this).


Attachments:
colladaconverter_vertcolor_patch.zip [4.3 KiB]
Downloaded 731 times

_________________
-Alex
Website
Top
 Profile  
Reply with quote  
 Post subject: Re: Vertex Colors?
PostPosted: 04.01.2011, 18:10 
Offline

Joined: 08.11.2010, 10:46
Posts: 35
Rauy wrote:
So just use the skinning data or second texture coordinate
What is the skinning data, or where is that? In a model? The other post mentioned in a static mesh, but I don't understand, or couldn't find the parameter.
When you say 2nd texture coordinate, are you referring to the texture coordinates in a geometry resource (GeoVertStaticStream)?
Whichever of these methods I choose, will I need to modify and use a shader to implement it? (something like what MistaED explained?)
I'm new to shaders, but I'll get right to that ... next.

MistaED wrote:
Here's the patch to make the collada converter use the vertex colours from a dae file and export it into the tangent stream. This isn't ideal as now you can't use normal mapping and it also limits vertex colours to RGB
I need the alpha value, but thanks anyway.
I may not need the normal mapping for this project but I don't want to and will not mess around like that if it prohibits other functionality. I say that because I don't want to have to specialise things for each project. I intend to use the game engine that accompanies Horde3D in a standard way. That's the whole reason I am using such a highly abstracted engine.


Top
 Profile  
Reply with quote  
 Post subject: Re: Vertex Colors?
PostPosted: 04.01.2011, 18:45 
Offline

Joined: 11.09.2010, 20:21
Posts: 44
Location: Germany
You will always need to use specialized shaders if you want a specific feature not implemented by the Horde3D standard shaders, like vertex colors (these shaders mainly exist for example purposes anyway).

With skinning data and 2nd texture coordinate I mean the skinning weights and bone indices and the 2nd texCoord from the .geo resource, which are per-vertex attributes and can thus be used as per-vertex colors (although I think the texCoord only has 2 components, so it won't suffice).

A static mesh means a mesh that does not use skinning and thus does not need the per-vertex skinning weights and bone indices, which can therefore both be used for custom attributes (like colors). If you need skinning but don't need any textures, you can use the 1st and 2nd texture coordinates combined, which would give you your 4 components of color, but you have to combine them in the shader yourself.

At the moment you won't get around such "misuses" of predefined vertex attributes, otherwise you have to wait for a future version with a more flexible attribute system. But as I don't think vertex colors are such a heavily used feature you could drive quite good with using the skinning data. Or consider just using a texture instead of vertex colors, but that means you have to parameterize your model if there are no texture coordinates.


Top
 Profile  
Reply with quote  
 Post subject: Re: Vertex Colors?
PostPosted: 06.01.2011, 03:18 
Offline

Joined: 08.11.2010, 10:46
Posts: 35
Rauy wrote:
(although I think the texCoord only has 2 components, so it won't suffice)
Rauy wrote:
If you need skinning but don't need any textures, you can use the 1st and 2nd texture coordinates combined, which would give you your 4 components of color, but you have to combine them in the shader yourself.

Ok I think I understand. I will work on understanding shaders.
Thanks for the help.


Top
 Profile  
Reply with quote  
 Post subject: Re: Vertex Colors?
PostPosted: 08.01.2011, 03:42 
Offline

Joined: 15.02.2009, 02:13
Posts: 161
Location: Sydney Australia
I can make my patch work with replacing the skin weights stream instead of messing with the tangent stream, it's an easy tweak which I'll try to do later today when I get some time. Like Rauy said it will work for static geometry (or even stuff with morph targets) but it won't work with joints skinning this way but you will get alpha due to skin weights being vec4 not vec3.
vikingcode wrote:
I need the alpha value, but thanks anyway.
I may not need the normal mapping for this project but I don't want to and will not mess around like that if it prohibits other functionality. I say that because I don't want to have to specialise things for each project. I intend to use the game engine that accompanies Horde3D in a standard way. That's the whole reason I am using such a highly abstracted engine.

This isn't modifying horde3d internals, the .geo format is the same it is just holding different data from the collada file and in any abstracted engine you will most likely be making your own shaders or making custom tweaks to the existing shaders to accommodate special cases anyway. The shaders that horde does come with are a great base to start adding to though (and if you notice in the model.shader there's define flags like "_Fxx_Something" which can be used to add features to existing shaders and then you can just add this flag to a material file so it only works on those geometries with that specific shader so it won't interfere with other objects. So you could have something like "_F06_VertexColors" and then add the specific shader codes under it.

I recommend you read the documentation here for better explanations :)

_________________
-Alex
Website


Top
 Profile  
Reply with quote  
 Post subject: Re: Vertex Colors?
PostPosted: 12.01.2011, 01:20 
Offline

Joined: 08.11.2010, 10:46
Posts: 35
MistaED wrote:
This isn't modifying horde3d internals, the .geo format is the same it is just holding different data
No, I understand. I said "I don't want to have to specialise things.."
For example, I'd prefer not to use the texture coordinates and skinning weights to represent vertex colors, because I may need them later. Even for a different project I don't want to do things differently. I already have enough crap to memorize.
I don't know if that is pedantic, but I prefer not to use any hack techniques for simple features. It messes with my peace of mind.. :twisted: :lol:
I don't mind hacking if it involves more code and creating a new function or something like that..

But I sincerely thank you for your help/advice.

And I have to hack it for now anyway don't I? So I was wasting my time talking. :lol:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group