Bump/Parallax Mapping -anyone have a working GLSL example?

All topics about ZGameEditor goes here.

Moderator: Moderators

User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hej,
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.

Image

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 ).

K
User avatar
VilleK
Site Admin
Posts: 2277
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Something like that would be interesting.

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.

Code: Select all

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?

Code: Select all

vec3[] data = getMeshData(mesh1, location);
...
setMeshData(mesh1, location, data);
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hej Ville,
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.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Ville, Kjell,

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).
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Rado1,
Rado1 wrote:BTW for each attribute, there should be specified also its type (float, vector or matrix).
What? Matrix? I wonder what you'd want to use that for :shock:

K
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Kjell wrote:What? Matrix? I wonder what you'd want to use that for :shock:
I do not know how to use it, but GLSL spec tells it is possible.
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Rado1,
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.

K
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Hi Kjell,

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.
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Rado1,
Rado1 wrote:So the allowed types should be: float, vec2, vec3, and vec4.
Don't forget ( unsigned ) byte :wink: Unless a character uses more then 256 bones ( very unlikely ), that's the optimal type to pass bone indices.

K
User avatar
VilleK
Site Admin
Posts: 2277
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

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.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

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.
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hej Ville,
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 :roll: Anyway, the points Rado1 mentions are valid. Besides .. not everybody will want to use shaders ( for one reason or the other ).

K
User avatar
VilleK
Site Admin
Posts: 2277
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

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.
Post Reply