Skip to content

Commit

Permalink
Using mediump precision in shaders for maximum compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Dec 3, 2011
1 parent e472bbf commit 9760906
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/scenejs/drawList/drawList.js
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,9 @@ var SceneJS_DrawList = new (function() {
geo.normalBuf ? "t" : "f",
geo.uvBuf ? "t" : "f",
geo.uvBuf2 ? "t" : "f",
geo.colorBuf ? "t" : "f"]).join("");
geo.colorBuf ? "t" : "f",
geo.primitive
]).join("");

/* Identify what GLSL is required for the current state soup elements
*/
Expand Down Expand Up @@ -1265,7 +1267,7 @@ var SceneJS_DrawList = new (function() {
var countDestroyed = 0;
var flags;
var tagCore;
var _picking = picking;
var _picking = picking; // For optimised lookup

/* Tag matching
*/
Expand Down Expand Up @@ -1301,7 +1303,7 @@ var SceneJS_DrawList = new (function() {
continue;
}

/* Skip unmatched tags
/* Skip unmatched tags. Visible node caching helps prevent this being done on every frame.
*/
if (tagMask) {
tagCore = node.tagState.core;
Expand Down Expand Up @@ -1331,7 +1333,7 @@ var SceneJS_DrawList = new (function() {
nodeRenderer.renderNode(node); // Render node if opaque or in picking mode
}

visibleCacheBin[states.lenVisibleCacheBin++] = node; // Build visible node cache
visibleCacheBin[states.lenVisibleCacheBin++] = node; // Cache visible node
}

if (countDestroyed > 0) {
Expand All @@ -1357,7 +1359,6 @@ var SceneJS_DrawList = new (function() {
};



/*===================================================================================================================
*
* SHADERS
Expand Down Expand Up @@ -1465,9 +1466,7 @@ var SceneJS_DrawList = new (function() {
var normals = this._hasNormals();

var src = [
"#ifdef GL_ES",
" precision highp float;",
"#endif",
"precision mediump float;",
"attribute vec3 SCENEJS_aVertex;",
"attribute vec3 SCENEJS_aNormal;",

Expand Down Expand Up @@ -1586,9 +1585,8 @@ var SceneJS_DrawList = new (function() {
var normals = this._hasNormals();

var src = [
"#ifdef GL_ES",
" precision highp float;",
"#endif"];
"precision mediump float;"
];

src.push("vec4 packDepth(const in float depth) {");
src.push(" const vec4 bitShift = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);");
Expand Down Expand Up @@ -1681,7 +1679,7 @@ var SceneJS_DrawList = new (function() {
}

src.push(" if (SCENEJS_uRayPickMode) {");
src.push(" float zNormalizedDepth = (SCENEJS_uZNear - SCENEJS_vViewVertex.z) / abs(SCENEJS_uZFar - SCENEJS_uZNear);");
src.push(" float zNormalizedDepth = (SCENEJS_uZNear - SCENEJS_vViewVertex.z) / (SCENEJS_uZFar- SCENEJS_uZNear);");
src.push(" gl_FragColor = packDepth(zNormalizedDepth); ");

src.push(" } else {");
Expand Down Expand Up @@ -1747,9 +1745,7 @@ var SceneJS_DrawList = new (function() {
var morphing = morphState.morph && true;

var src = [
"#ifdef GL_ES",
" precision highp float;",
"#endif"
"precision mediump float;",
];

src.push("attribute vec3 SCENEJS_aVertex;"); // Model coordinates
Expand Down Expand Up @@ -1980,9 +1976,7 @@ var SceneJS_DrawList = new (function() {

var src = ["\n"];

src.push("#ifdef GL_ES");
src.push(" precision highp float;");
src.push("#endif");
src.push("precision mediump float;");


if (clipping || fragmentHooks.worldPos) {
Expand Down

0 comments on commit 9760906

Please sign in to comment.