xml3d / xml3d.js

The WebGL/JS implementation of XML3D
Other
75 stars 25 forks source link

XML3D Shaders: default uniforms #179

Closed Arsakes closed 8 years ago

Arsakes commented 8 years ago

Where can I find the list of uniforms defined for xml3d shaders? Surely some of them are predefined.

To be precise: I'm looking for inversion of modelView matrix. It would be great if I could bypass computing it in shader.

csvurt commented 8 years ago

Hi,

these aren't documented anywhere right now, but you can look at the source code to see what's defined:

SceneRenderPass Phong shader

Of course if you're writing your own RenderPass you can define any uniforms that you want, but these are the ones that get supplied to the shader during the built in scene render pass.

Arsakes commented 8 years ago

Great thanks, modelViewMatrixN is transpose of an inverse of modelView - right? Also have a question which is maybe slighlty out of scope, how can I check which version of shading language (opengl es) I'm using?

csvurt commented 8 years ago

Yeah they're the vertex normal versions of the matrices, so inverted transpose.

About the version, it should always be the same since WebGL 1.0 is the only supported API right now. It's basically OpenGL ES 2.0 and GLSL ES 1.0. But you can check this by creating a webgl context and reading out the version constants:

var canvas = document.createElement("canvas");
var gl = canvas.getContext("webgl");
gl.VERSION
gl.SHADING_LANGUAGE_VERSION

edit: sorry I misunderstood the first question, you're right they're the inverted transpose

csvurt commented 8 years ago

FYI, just remembered there are a few more uniforms set in the forward render pass which is what kicks off the scene render passes. So these should be available in your shader too:

systemUniforms["viewMatrix"] = c_worldToViewMatrix;
systemUniforms["viewInverseMatrix"] = c_viewToWorldMatrix;
systemUniforms["projectionMatrix"] = c_projectionMatrix;
systemUniforms["cameraPosition"] = scene.getActiveView().getWorldSpacePosition();
systemUniforms["coords"] = [target.width, target.height, 1];
Arsakes commented 8 years ago

Great! Thanks those are precisely uniforms I've needed. For future: Can I set my own arbitrary global uniforms and pass them to shader each frame? (By global I mean accessible from every shader - not the ones set per material like: ambientIntensity etc.)