Page 1 of 1
GLES 2.0 Shader Uniforms
Posted: Tue Mar 26, 2013 9:00 am
by jazz
I notice in the ES 2.0 example, uniform mat4 mvp is predefined. Is there way to receive model, view, and projection separately? Thought about doing it separately, however, ShaderVariable seems to only support one value.
If not, I guess I could just call gl functions myself. Is there a way to get the handle of zge shaders, or must I compile my own shader to be able to pass my own data.
-jazz
Posted: Tue Mar 26, 2013 12:06 pm
by VilleK
The ES2.0 support is brand new so we can add anything you want as long as you can make a good explanation of why it is needed
Shader does not expose the handle yet, I will update the beta so that you can get it via Shader.Handle property.
I haven't done any serious shader writing. When is it necessary to get the matrices separately?
Posted: Tue Mar 26, 2013 12:49 pm
by Kjell
Hej Ville,
VilleK wrote:Shader does not expose the handle yet, I will update the beta so that you can get it via Shader.Handle property.
That alone won't really help him. There's no matrix type nor math build-in and you can't access the internal matrices either.
Personally I use the individual "build-in" matrices all the time .. in fact, i often even split the ModelView matrix into a separate Model and View matrix ( Direct3D-style ) to pull off certain effects.
K
Posted: Tue Mar 26, 2013 3:39 pm
by jazz
Hey Guys,
VilleK wrote:The ES2.0 support is brand new so we can add anything you want as long as you can make a good explanation of why it is needed

Yeah, the Android and ES2.0 support is what really attracted me to zge! Great work! Can't wait for ios support! (Maybe Kjell can show us how he ported for the time being

)
As Kjell mentioned, I think separate Model, View, and Projection matrices or simply having ModelView and Projection matrices increases the flexibility in creating effects. Especially in ES2.0, where the lack of features can be compensated with "tricks."
But probably the biggest reason is to be able to transform normals within the shader.
Kjell wrote:That alone won't really help him. There's no matrix type nor math build-in and you can't access the internal matrices either.
This would be fantastic! But not sure how long it would take to integrate into zge. I think simply having a shader handle and separate matrices at the moment would greatly increase the power of ES2.0 in zge.
Posted: Tue Mar 26, 2013 4:32 pm
by Kjell
Hi jazz,
jazz wrote:Maybe Kjell can show us how he ported for the time being
There are a couple of
resources available on compiling for iOS using FreePascal. I basically wrote a ultra-minimal wrapper ( ES 1.1 based .. without any platform specific features ) in Xcode just as a proof of concept.
jazz wrote:As Kjell mentioned, I think separate Model, View, and Projection matrices or simply having ModelView and Projection matrices increases the flexibility in creating effects.
I'd stick to the fixed-function design and go with Projection, ModelView and ModelViewProjection .. even if that means i'm shooting myself in the foot
jazz wrote:I think simply having a shader handle and separate matrices at the moment would greatly increase the power of ES2.0 in zge.
What kind of data are you planning to "push" to your shader(s) using the shader handle then?
K
Posted: Tue Mar 26, 2013 4:56 pm
by VilleK
And which naming standard should we use?
projection
Projection
projectionMatrix
ProjectionMatrix
etc?
Posted: Tue Mar 26, 2013 5:24 pm
by Kjell
Hmm,
VilleK wrote:And which naming standard should we use?
Good question. There's certainly no standard among various engines for this. Some engines omit the gl_ prefix, others use their own prefix, and some ( Unity ) even use the pre-processor to "fold" the uniforms back to their fixed-function gl_ prefixed equivalent.
Anyway, i don't have a strong preference towards one or the other ( out of the 4 options ), all are fine by me.
K
Posted: Tue Mar 26, 2013 11:01 pm
by jazz
Kjell wrote:There are a couple of
resources available on compiling for iOS using FreePascal. I basically wrote a ultra-minimal wrapper ( ES 1.1 based .. without any platform specific features ) in Xcode just as a proof of concept.
Great! Will check it out. Looks fun.
Kjell wrote:I'd stick to the fixed-function design and go with Projection, ModelView and ModelViewProjection .. even if that means i'm shooting myself in the foot

Yeah, basically trying port some stuff from another project. I haven't really tried going to the fixed pipeline, but the programmable pipeline is too fun to look away. lol.
Kjell wrote:What kind of data are you planning to "push" to your shader(s) using the shader handle then?
Just some vectors. But looking at the expression documentation, can't I also use glUniformMatrix4fv with DefinedArray?
VilleK wrote:And which naming standard should we use?
I think any would work. I personally prefer "projection." But I always thought "ProjectionMatrix" was better for those who are new or begin to use shaders.
Posted: Tue Mar 26, 2013 11:11 pm
by Kjell
Hi jazz,
jazz wrote:Just some vectors.
If you just want to pass some arbitrary vectors you might as well use the ValueArrayRef property of the ShaderVariable component. This allows you to push a array worth of floats as a sampler1D to a shader.
jazz wrote:But looking at the expression documentation, can't I also use glUniformMatrix4fv with DefinedArray?
Yes you can, but where is this matrix ( data ) coming from? You cannot use "glGetFloatv(GL_PROJECTION_MATRIX, data)" in ES 2.0 obviously.
K
Posted: Tue Mar 26, 2013 11:34 pm
by jazz
Kjell wrote:If you just want to pass some arbitrary vectors you might as well use the ValueArrayRef property of the ShaderVariable component. This allows you to push a array worth of floats as a sampler2D to a shader.
This seems kinda ugly though, lol. I would have to write specific glsl code for zge. Also, wouldn't this be a performance hit? I have to sample to retrieve my vector values right. I think I would prefer just calling glfunctions directly.
Kjell wrote:Yes you can, but where is this matrix ( data ) coming from? You cannot use "glGetFloatv(GL_PROJECTION_MATRIX, data)" in ES 2.0 obviously
Oh no. If Ville exposes the handles, couldn't I do:
Create an Array in zge call "data."
int matrixHandle = glGetUniformLocation(shaderHandle, "matixName");
glUniformMatrix4fv(matrixHandle, 1, 0, data);
right?
Posted: Tue Mar 26, 2013 11:42 pm
by Kjell
Hi jazz,
jazz wrote:This seems kinda ugly though, lol. I would have to write specific glsl code for zge. Also, wouldn't this be a performance hit? I have to sample to retrieve my vector values right. I think I would prefer just calling glfunctions directly.
It is pretty ugly yes. The values actually used to be passed as plain uniform data ( so you could map it to mat4, float[] etc. without problems ), but Ville changed it to Sampler1D ( which is preferred for large quantities of data ).
jazz wrote:If Ville exposes the handles, couldn't I do:
Create an Array in zge call "data."
int matrixHandle = glGetUniformLocation(shaderHandle, "matixName");
glUniformMatrix4fv(matrixHandle, 1, 0, data);
right?
Yes yes .. but i'm asking where the values in your data array come from. I assume you're not just going to pass 16 zeros, right?
K
Posted: Tue Mar 26, 2013 11:59 pm
by jazz
Hey Kjell,
Oh, I think see what you're asking me, how would I send the model, view, and projection? I was actually talking about just sending an arbitrary matrix that I filled with data.
I'm still new to zge. But since you mention it, could one calculate these matrices in expressions onUpdate()? All attributes needed to create them are exposed or known.
But I mean I would still really like Ville to expose internal matrices, or predefine the model, view, projection separately in ES shaders.
Posted: Wed Mar 27, 2013 12:07 am
by Kjell
Hi jazz,
jazz wrote:I was actually talking about just sending an arbitrary matrix that I filled with data.
Ah alright, then you should be fine yes. I thought you might wanted to send projection or modelView matrices since you mentioned those in the OP
jazz wrote:But since you mention it, could one calculate these matrices in expressions onUpdate()? All attributes needed to create them are exposed.
Sure, you can calculate them ( again ) yourself, but as mentioned .. there's no matrix type nor math build in, so you need to do all calculations & stack logic ( for modelView ) from scratch.
K