Page 1 of 1

Passing vec* variables to shaders + "vector" props

Posted: Tue May 28, 2013 3:39 pm
by Rado1
Some (probably related) feature requests:

1. Is there a way to pass uniform variables of type vec* and references to vec* variables to shaders? If not, this feature request is valid; if yes, please explain how. For now, I always use shader variables such as mousePositionX and mousePositionY and in shader code write: vec2 mousePosition = vec2(mousePositionX, mousePositionY); ... this is too cumbersome.

2. It would also be nice to use references to RenderSetColor.Color, Material.Color, Model.Position, etc. (I called them "vector" properties) as uniform shader variables of type vec4 or vec3.

3. In ZGE expressions properties such Material.Color can be assigned to vec4 variables, and vice versa. Also accessing Material.Color[0] can return R value (this was already proposed by Kjell).

Posted: Mon Oct 14, 2013 11:34 am
by VilleK
About 1: Yes you can send vec* variables to shaders.

Assume you have a vec3 variable like this:
<Variable Name="uAttractPos" Type="7"/>

And a ShaderVariable like this:
<ShaderVariable VariableName="AttractPos" VariableRef="uAttractPos"/>

Then you can declare this in your shader:
uniform vec3 AttractPos;

Posted: Tue Oct 15, 2013 6:10 pm
by Rado1
Thanks Ville. Could you please also explain how to pass arrays of vectors as uniforms? Should I use ArrayKind Texture1D? Actually, I haven't tried it yet, I'm just asking because I plan to use it in near future.

Posted: Wed Oct 16, 2013 9:17 am
by VilleK
Vec* arrays as uniforms are not supported yet, just arrays of mat4 (ArrayKind=Mat4). But it is easy for me to add. Just remind me again when you need it and I'll fix it.

Posted: Wed Oct 16, 2013 10:16 pm
by Rado1
VilleK wrote:But it is easy for me to add. Just remind me again when you need it and I'll fix it.
Great! I'm going to implement GLES Phong shader for multiple lights and want to pass light positions + diffuse/specular colors + intensities as array(s). I would really appreciate this possibility.