Jump to content

[SOLVED] - GLSL Matrix Syntax Help


MackeyK24
 Share

Recommended Posts

I really need help understanding the GLSL versions of the provided BABYLON uniforms. I have seen them called so many different names depending on who's docs your reading.

The ONLY ONE I know for sure is in babylon.js when you say 'worldViewProjection' that is the GLSL computation of 'gl_ProjectionMatrix * gl_ModelViewMatrix' or you can use the built-in shortcut 'gl_ModelViewProjectionMatrix'

I need someone who know BABYLON JS GLSL Stuff to PLEASE PLEASE PLEASE... Tell me what the others equal in GLSL terms:

view = gl_???

projection = gl_??? (maybe its: gl_ProjectionMatrix )

viewProjection = gl_??? * gl_???

world = gl_???

worldView = gl_???

worldViewProjection = 'gl_ProjectionMatrix * gl_ModelViewMatrix' or can be simplified as just 'gl_ModelViewProjectionMatrix'

I am sorry i don't know the GLSL stuff, but if i can someone who does to simple fill out the five 'gl_???' place holders above...

Ill be your friend for life :)

Note: I and trying yo create a block of code that will run in both unity using GLSL stuff and BABYLON JS using native uniforms.

By Babylon Macros:

//BABYLON-VERTEX-MACROS-START
attribute vec3 position;
vec4 GL_POSITION_ATTRIBUTE() { return vec4(position, 1.0); }
attribute vec3 normal;
vec3 GL_NORMAL_ATTRIBUTE() { return normal; }
attribute vec2 uv;
vec2 GL_UV_ATTRIBUTE() { return uv; }
attribute vec2 uv2;
vec2 GL_UV2_ATTRIBUTE() { return uv2; }
attribute vec2 uv3;
vec2 GL_UV3_ATTRIBUTE() { return uv3; }
attribute vec2 uv4;
vec2 GL_UV4_ATTRIBUTE() { return uv4; }
attribute vec2 uv5;
vec2 GL_UV5_ATTRIBUTE() { return uv5; }
attribute vec2 uv6;
vec2 GL_UV6_ATTRIBUTE() { return uv6; }
attribute vec4 color;
vec4 GL_COLOR_ATTRIBUTE() { return color; }
uniform mat4 view;
mat4 GL_VIEW_UNIFORM() { return view; }
uniform mat4 projection;
mat4 GL_PROJECTION_UNIFORM() { return projection; }
uniform mat4 viewProjection;
mat4 GL_VIEWPROJECTION_UNIFORM() { return viewProjection; }
uniform mat4 world;
mat4 GL_WORLD_UNIFORM() { return world; }
uniform mat4 worldView;
mat4 GL_WORLDVIEW_UNIFORM() { return worldView; }
uniform mat4 worldViewProjection;
mat4 GL_WORLDVIEWPROJECTION_UNIFORM() { return worldViewProjection; }
//BABYLON-VERTEX-MACROS-END

My GLSL Equivalent  Macros (as you can see I still need the gl_??? parts):

//BABYLON-VERTEX-MACROS-START
vec4 GL_POSITION_ATTRIBUTE() { return gl_Vertex; }
vec3 GL_NORMAL_ATTRIBUTE() { return gl_Normal; }
vec2 GL_UV_ATTRIBUTE() { return vec2(gl_MultiTexCoord0.xy); }
vec2 GL_UV2_ATTRIBUTE() { return vec2(gl_MultiTexCoord1.xy); }
vec2 GL_UV3_ATTRIBUTE() { return vec2(gl_MultiTexCoord2.xy); }
vec2 GL_UV4_ATTRIBUTE() { return vec2(gl_MultiTexCoord3.xy); }
vec2 GL_UV5_ATTRIBUTE() { return vec2(gl_MultiTexCoord4.xy); }
vec2 GL_UV6_ATTRIBUTE() { return vec2(gl_MultiTexCoord5.xy); }
vec4 GL_COLOR_ATTRIBUTE() { return gl_Color; }
mat4 GL_VIEW_UNIFORM() { return gl_???; }
mat4 GL_PROJECTION_UNIFORM() { return gl_??? ; }
mat4 GL_VIEWPROJECTION_UNIFORM() { return gl_???; }
mat4 GL_WORLD_UNIFORM() { return gl_???; }
mat4 GL_WORLDVIEW_UNIFORM() { return gl_???; }
mat4 GL_WORLDVIEWPROJECTION_UNIFORM() { return gl_ModelViewProjectionMatrix; }
//BABYLON-VERTEX-MACROS-END

I know some GLSL guy look at that GLSL BLOCK and see those gl_??? and know exactly with those be... no problem for him. If you are that guy, please help me :)

 

Link to comment
Share on other sites

hi

this is work flow for any 3d Engine when wanna render in ViewPort For each Model

MODELING COORDINATES    >  WORLD COORDINATES   >  VIEW COORDINATES   >  VIEWPORT COORDINATES

>> World coordinates are the global coordinate system that takes into account all objects in the scene.

*** world  

>> View coordinates are the coordinate system that incorporates a virtual camera's view of the scene.

*** View 

>> Viewport coordinates are the coordinate system that describes the camera projection for the scene (for example, orthographic or perspective) and fits the projected scene into screen space. This projection takes the scene from a 3D to a 2D projection so that it can be displayed on the screen. The textured spinning box example uses a perspective projection, which will make closer objects look larger than further ones, just as in the real world.

*** Projection

---------

world > View > Projection

or Model  ( without Global Information about Transform Matrix of Model )  View Projection  => View Projection 

without projection we have  (World  , View , WorldView )

  WorldViewProjection  = ProjectionMatrix*ModelViewMatrix

 

 

 

 

Link to comment
Share on other sites

So if you had to write the some of the macros above:

GL_VIEW_UNIFORM for example, what what the 'gl_???' calculations for that one (please include the formula: what does babylon js 'view' and so on need to be)

I AM SO SORRY TO KEEP ASKING. But please include the 'code' for each GL_XXX_UNIFORM (using GLSL attributes like : gl_ProjectionMatrix * gl_ModelViewMatrix)

Link to comment
Share on other sites

Willing to pay someone to finish these 5 little GLSL function (that are actually need to run in unity). I can send the payment immediately. I simply don't know GLSL (All though i very much appreciate the pseudo code above... it does not tell me what the GL_VIEW_UNIFORM function should be doing to actually return the view... whether that is via already computed in in some built-in gl_ uniform or whether it should be computed, and if so... Can please write the function to compute). I need these five computations to be written for me since i am not smart enough to figure out this low level GLSL matrix conversion or even know all the right terminology.

I mean in babylon js there is a 'view' and 'projection' and 'viewProjection' uniform.

BUT I SEARCHED ALL OVER the internet for GLSL stuff... AND NO WHERE IS THERE ANYTHING SIMPLY CALLED 'view' or 'viewModel'

THAT LEADS ME TO BELIEVE that programmer is supplying some calculation to the shader via a uniform (called 'view' and only specific to babylonjs)... So somewhere that has got to be something like: 'view' = something * something (or something like that...)

I AM GIVING UP ON THIS GLSL Stuff... But i will pay someone to simply write the 5 calculations listed above... Name your price... We can work it out...

You can also reach me email: [email protected]

I have paypal and can send dough immediately :)

mat4 GL_VIEW_UNIFORM() {
  return 'please write me!!!';
}

mat4 GL_PROJECTION_UNIFORM() {
  return 'please write me!!!';
}

mat4 GL_VIEWPROJECTION_UNIFORM() {
  return 'please write me!!!';
}

mat4 GL_WORLD_UNIFORM() {
  return 'please write me!!!';
}

mat4 GL_WORLDVIEW_UNIFORM() {
  return 'please write me!!!';
}

Keep in mind these are supposed to be the GLSL version of these babylon js function:

uniform mat4 view;
mat4 GL_VIEW_UNIFORM() {
  return view;
}

uniform mat4 projection;
mat4 GL_PROJECTION_UNIFORM() {
  return projection;
}

uniform mat4 viewProjection;
mat4 GL_VIEWPROJECTION_UNIFORM() {
  return viewProjection;
}

uniform mat4 world;
mat4 GL_WORLD_UNIFORM() {
  return world;
}

uniform mat4 worldView;
mat4 GL_WORLDVIEW_UNIFORM() {
 return worldView;
}

uniform mat4 worldViewProjection;
mat4 GL_WORLDVIEWPROJECTION_UNIFORM() {
  return worldViewProjection;
}

And for reference this is what i got so far for GLSL Unity mode:

vec4 GL_POSITION_ATTRIBUTE() { return gl_Vertex; }
vec3 GL_NORMAL_ATTRIBUTE() { return gl_Normal; }
vec2 GL_UV_ATTRIBUTE() { return vec2(gl_MultiTexCoord0.xy); }
vec2 GL_UV2_ATTRIBUTE() { return vec2(gl_MultiTexCoord1.xy); }
vec2 GL_UV3_ATTRIBUTE() { return vec2(gl_MultiTexCoord2.xy); }
vec2 GL_UV4_ATTRIBUTE() { return vec2(gl_MultiTexCoord3.xy); }
vec2 GL_UV5_ATTRIBUTE() { return vec2(gl_MultiTexCoord4.xy); }
vec2 GL_UV6_ATTRIBUTE() { return vec2(gl_MultiTexCoord5.xy); }
vec4 GL_COLOR_ATTRIBUTE() { return gl_Color; }
mat4 GL_VIEW_UNIFORM() { return gl_???; }
mat4 GL_PROJECTION_UNIFORM() { return gl_??? ; }
mat4 GL_VIEWPROJECTION_UNIFORM() { return gl_???; }
mat4 GL_WORLD_UNIFORM() { return gl_???; }
mat4 GL_WORLDVIEW_UNIFORM() { return gl_???; }
mat4 GL_WORLDVIEWPROJECTION_UNIFORM() { return gl_ModelViewProjectionMatrix; }

So i think i got all the conversion for the attributes... just need those five uniform functions WRITTEN FOR ME ... Thank Again ... I hope to do business with somebody :)

P.S.

Sorry to flood the forums with this GLSL problems... If it don't work out and i still can't get anyone to write this computations... Ill just pull that feature from the Unity Exporter Tool For Babylons JS... Wont flood anymore... At least about this GLSL stuff.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...