Shader variables

All topics about ZGameEditor goes here.

Moderator: Moderators

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

Shader variables

Post by Rado1 »

Hi,

this question is mainly for Ville and Kjell but I think that everybody can profit from answer(s).
Could you please make a summary of all shader variables (types, names and short semantics) currently supported by ZGE?

These I know:

Code: Select all

uniform mat4 modelViewProjectionMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform mat3 normalMatrix;
uniform mat4 textureMatrix; //Holds the current texture matrix (updated via RenderText or Material.TextureX/Y/Scale properties
uniform vec4 globalColor; //The current color that is set using RenderSetColor or Material.Color

attribute vec4 position; //vertex position
attribute vec4 color; //vertex color (does it work?)
attribute vec2 texCoord; //vertex texture coordinate
attribute vec3 normal; //vertex normal

// textures in fragment shader
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform sampler2D tex3;
...
Is this list correct and complete?

How, for instance, to obtain color of particle (including alpha)?

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

Post by Kjell »

Hi Rado1,

Perhaps you could clarify that this thread is only relevant when you're targeting OpenGL 3.3 ( Core ) or ES 2.0. When you're targeting legacy OpenGL you can use everything ( from this cheat sheet ) of course. Just so that newbies who stumble upon this thread won't get confused :wink:

Anyway, the list you've posted is complete. There is however a problem / bug with the color attribute. When you set the particle colors in RenderParticles, you actually have to divide the vec4 by 255 in your shader to get the proper color values. I suspect Ville has used a incorrect type parameter somewhere.

+ And imo vec4 position should be called vertex ( since it's gl_Vertex in legacy OpenGL as well ).

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

Post by Rado1 »

Thanks Kjell for answering. I want to create some shaders to Android app, so you are right, I refer to OpenGL 3.3 / ES 2.0.

I also tried rendering of particles with color divided by 255 - it works, thanks for the hint. But this should be fixed anyway!
User avatar
VilleK
Site Admin
Posts: 2356
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

I might have fixed the color problem, please try latest beta.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

VilleK wrote:I might have fixed the color problem, please try latest beta.
Ville, have you already built it? The current version still needs division by 255.
User avatar
VilleK
Site Admin
Posts: 2356
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

I built it but looks like I forgot to upload it. I'll fix it tomorrow.
User avatar
VilleK
Site Admin
Posts: 2356
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

Uploaded now.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Thank you.
Post Reply