VilleK wrote:Kjell can you explain a bit more? Can you give an example with suggestions for names of Components and Properties needed to achieve your idea?
Here's what the second suggestion could look like.
The Location property would contain all attributes that are supported by ZGameEditor. So this could include fixed-function OpenGL features such as Normal, Color, SecondaryColor, TexCoord0-7, but also MorphTarget0-?, BoneWeight0-? once those are supported. If you want to add a attribute that doesn't use a build-in feature / you'll use in your own shader, you can define a Custom attribute.
The only question is what you do with the VertexColors / HasTexCoords flags on MeshExpression ( could for example be converted automatically .. or kept as is ), and which attributes are standard ( ideally only Position ).
I'm just thinking here if it would not be better to define a specific component that would contain the vertex format. Then the mesh could refer to it. So if you have several meshes using the same shader then they do not have to have their own copy of the attributes definitions.
VertexFormat
Attributes
Position <<-- These would have the same properties as in Kjells design
Color
Normal
Custom1
Mesh1.VertexFormat = myformat
Mesh2.VertexFormat = myformat
MyShader.VertexFormat = myformat
Then we need ways to define the data for the attributes. Maybe using functions?
VilleK wrote:I'm just thinking here if it would not be better to define a specific component that would contain the vertex format. Then the mesh could refer to it. So if you have several meshes using the same shader then they do not have to have their own copy of the attributes definitions.
That how I'd do my third ( and preferred ) suggestion
Perhaps you can leave the current / a vertex format as the default though? So that when you just want a "regular" mesh you don't have to create & reference a format in your Mesh component. Keeps things simple for beginners.
Then we need ways to define the data for the attributes. Maybe using functions?
I think it would be most convenient if you could just access them like you do now using MeshExpression. So when you use a vertex format that contains the TexCoord2 attribute, you can set it using "this.TexCoord2.X = .." in a MeshExpression.
K
Last edited by Kjell on Mon Apr 22, 2013 11:59 am, edited 1 time in total.
I like your suggestions: (1) VertexFormat component and (2) setting vertex attributes in MeshExpression with syntax "this.TexCoord2.X = .." (this is probably little bit tricky for expression compiler). VertexFormat component should just list user-defined attributes. BTW for each attribute, there should be specified also its type (float, vector or matrix).
Rado1 wrote:I do not know how to use it, but GLSL spec tells it is possible.
It's possible / supported on the GLSL side, but the OpenGL API doesn't have ( proper / true ) support for it. You'd need to pass each column of a 4x4 matrix individually as attributes can only contain 4 components at most, while you'd need 16.
as usually, you are right. I checked glVertexAttribPointer and it allows maximal value for size only 4. So the allowed types should be: float, vec2, vec3, and vec4. It's interesting that OpenGL API is not 100% consistent with GLSL spec.
Kjell wrote:I think it would be most convenient if you could just access them like you do now using MeshExpression. So when you use a vertex format that contains the TexCoord2 attribute, you can set it using "this.TexCoord2.X = .." in a MeshExpression.
But what could be done in a MeshExpression? If it just calculates TexCoord2 based on vertex position that could better be done in the vertex shader directly instead of being stored in CPU memory.
VilleK wrote:But what could be done in a MeshExpression? If it just calculates TexCoord2 based on vertex position that could better be done in the vertex shader directly instead of being stored in CPU memory.
My naive view: MeshExpression computes attributes just once but vertex shader should compute them each time it is invoked. For instance, computing of tangents should not be very trivial and would make shaders more complex. In addition, mesh attributes can be shared by several shaders.
VilleK wrote:But what could be done in a MeshExpression? If it just calculates TexCoord2 based on vertex position that could better be done in the vertex shader directly instead of being stored in CPU memory.
By that reasoning you could question why the current TexCoord, Normal and Color attributes are there as well Anyway, the points Rado1 mentions are valid. Besides .. not everybody will want to use shaders ( for one reason or the other ).
Yes but TexCoord etc are for the fixed function OpenGL. Now we are discussion defining custom vertex formats and this will only work (because they are implemented as attributes) on the programmable pipeline OpenGL that requires shaders for everything anyway.
I'll see what can be done with MeshExpression. I'm thinking it will look a bit clumsy if we need to add properties for "TexCoord2,3,4 etc" and "Custom1,2,3" etc. Also the compiler will need to check the actual type depending on the vertex format. For instance "Custom1" could be a float or a vec2 etc. Which is a non-trivial complication.