Skip to content

Commit

Permalink
readd select shaders.
Browse files Browse the repository at this point in the history
Removing them was just for an experiment, I didn't intent to push the
change.
  • Loading branch information
biasmv committed Jul 4, 2015
1 parent bc9cad9 commit 39645e3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/gfx/shaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,46 @@ void main(void) {\n\
gl_PointSize = pointSize * 200.0 / abs(distToCamera); \n\
vertSelect = attrSelect;\n\
}',

SELECT_VS : '\n\
precision ${PRECISION} float;\n\
uniform mat4 projectionMat;\n\
uniform mat4 modelviewMat;\n\
uniform float pointSize;\n\
attribute vec3 attrPos;\n\
attribute float attrObjId;\n\
\n\
varying float objId;\n\
\n\
void main(void) {\n\
gl_Position = projectionMat * modelviewMat * vec4(attrPos, 1.0);\n\
float distToCamera = vec4(modelviewMat * vec4(attrPos, 1.0)).z;\n\
gl_PointSize = pointSize * 200.0 / abs(distToCamera); \n\
objId = attrObjId;\n\
}',

SELECT_FS : '\n\
precision ${PRECISION} float;\n\
\n\
varying float objId;\n\
uniform int symId;\n\
\n\
int intMod(int x, int y) { \n\
int z = x/y;\n\
return x-y*z;\n\
}\n\
void main(void) {\n\
// ints are only required to be 7bit...\n\
int integralObjId = int(objId+0.5);\n\
int red = intMod(integralObjId, 256);\n\
integralObjId/=256;\n\
int green = intMod(integralObjId, 256);\n\
integralObjId/=256;\n\
int blue = intMod(integralObjId, 256);\n\
int alpha = symId;\n\
gl_FragColor = vec4(float(red), float(green), \n\
float(blue), float(alpha))/255.0;\n\
}',
// hemilight vertex shader
LINES_VS : '\n\
attribute vec3 attrPos;\n\
Expand Down
3 changes: 2 additions & 1 deletion src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ Viewer.prototype = {
lines : c.initShader(shaders.LINES_VS, shaders.LINES_FS, p),
text : c.initShader(shaders.TEXT_VS, shaders.TEXT_FS, p),
selectLines : c.initShader(shaders.SELECT_LINES_VS,
shaders.SELECT_LINES_FS, p)
shaders.SELECT_LINES_FS, p),
select : c.initShader(shaders.SELECT_VS, shaders.SELECT_FS, p)
};

this._boundDraw = utils.bind(this, this._draw);
Expand Down

0 comments on commit 39645e3

Please sign in to comment.