Page 1 of 1

Shader variables

Posted: Sun Feb 15, 2015 3:24 pm
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

Posted: Sun Feb 15, 2015 3:54 pm
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

Posted: Sun Feb 15, 2015 6:03 pm
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!

Posted: Mon Feb 16, 2015 1:39 pm
by VilleK
I might have fixed the color problem, please try latest beta.

Posted: Mon Feb 16, 2015 3:19 pm
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.

Posted: Mon Feb 16, 2015 4:57 pm
by VilleK
I built it but looks like I forgot to upload it. I'll fix it tomorrow.

Posted: Tue Feb 17, 2015 1:35 pm
by VilleK
Uploaded now.

Posted: Tue Feb 17, 2015 7:49 pm
by Rado1
Thank you.