Jump to content

What GLSL Variables (uniforms) I supplied by Babylon.js


startec
 Share

Recommended Posts

I am basically asking the Babylon.js equivalent of this:

http://stackoverflow.com/questions/15663859/threejs-predefined-shader-attributes-uniforms/15664900#15664900

 

In the tutorials I see that there are some uniforms supplied from the application code  (like uniforms and view matrices) is there a place somewhere where the things that are provided automatically are documented?

Link to comment
Share on other sites

  • 2 years later...

Kosh's link. Based on the CYOS examples, I can verify that the following are available:

// Attributes
attribute vec3 position; //vertex x,y,z
attribute vec3 normal; //normal x,y,z
attribute vec2 uv; //uv (texture map) 2d coordinates

// Uniforms
uniform mat4 world; //convert from model space to world space
uniform mat4 view; //convert world space to camera-relative space
uniform mat4 projection; //flatten camera space to frame view
uniform mat4 worldView; //world and view, pre-multiplied for you
uniform mat4 worldViewProjection; //world, view & projection pre-multiplied
uniform sampler2D textureSampler; //texture data
uniform vec3 cameraPosition; //camera x,y,z
uniform float time; //time

Are there any predefined shader attributes or uniforms that I'm missing?

Edited by SpaceToast
Edited with more uniforms, from digging through built-in shaders
Link to comment
Share on other sites

(Edited out into its own post, because, messiness.) A further discovery I'd love to have verified: It appears that the uniforms above do not need to be declared when creating a shaderMaterial -- Babylon.js supplies them for you. So rather than declaring:

var shaderMaterial = new BABYLON.ShaderMaterial("shader", scene,
   {vertex: "custom", fragment: "custom"},
   {attributes: ["position", "normal", "uv"],
   uniforms: ["world", "worldView", "worldViewProjection", "view", "projection"]}
   );

You can omit the attributes section, unless supplying your own custom data to the shader:

var shaderMaterial = new BABYLON.ShaderMaterial("shader", scene,
   {vertex: "custom", fragment: "custom"},
   {attributes: ["position", "normal", "uv"],
   uniforms: ["capybaras"]}
   );
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...