Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperLicht
set matrix as shader inparameter

codemastermike
Registered User
Quote
2011-10-25 16:00:50

Should you set a matrix as a inparameter for a shader, with the uniformMatrix4fv function?

Because I try to set a matrix (see example below) and the program doesnt run after the last row. I dont get any error messages or anything, it just exits the function, seemingly without setting the Matrix inside the shader.

Pseudo code:

var renderer = CurrentGameEngine.getRenderer();
var InMatrixLocation = renderer.gl.getUniformLocation(TestShader, "InMatrix");
renderer.gl.uniformMatrix4fv(InMatrixLocation, false, TestMatrix);


And also, I read in a earlier post that there would be more support for shaders with lighting and such. Is there a way to get the normal transform matrix directly from the engine, or do I have to set it manually?


niko
Moderator
Quote
2011-10-26 07:49:14

Your problem maybe is that your TestMatrix isn't in the format WebGL wants it to be. You can use the renderers internal function for converting CopperLicht matrix to a WebGL matrix:
var newmatrix = renderer.getMatrixAsWebGLFloatArray(yourCLMatrix);

Set it then using something like this:
renderer.gl.uniformMatrix4fv(location, false, newmatrix);


If you define a variable named
uniform mat4 normaltransform;

in your shader, copperlicht will set this for you.


codemastermike
Registered User
Quote
2011-10-27 08:49:09

Yes, converting the matrix into a WebGL matrix makes it work just fine! Thanks!

But I still cant get the

uniform mat4 normaltransform;


matrix to work in the vertex shader. It seems it must be setting the value to null or so, because the object is (in this case) complete green, but with my own matrix inparameter, it displays the color values correctly.

Basicly what I do with the matrix, is that I normalize it with the normal, something like this pseudo code:


uniform mat4 normaltransform;
attribute vec4 vNormal;

void main(void)
{
normal = normalize(normaltransform * vNormal);
}


I will keep on using my own matrix, since that seems to work just fine. But I just wanted to mention it to you.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internation?l" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact