Created
July 11, 2016 09:33
-
-
Save edankwan/dc3684bdce7c8d9d242d6a9aae5906b4 to your computer and use it in GitHub Desktop.
Idea of using instancing with pixel discard in WebGL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vertex shader | |
attribute float a_eyeOffset; | |
varying float v_eyeOffset; | |
... | |
vec4 mvPosition = modelViewPosition * vec4(position, 1.0); | |
mvPosition.x -= a_eyeOffset; | |
gl_Position = projectionMatrix * mvPosition; | |
gl_Position.x = gl_Position.x * 0.5 + sign(a_eyeOffset) * 0.5 * gl_Position.w; | |
v_eyeOffset = a_eyeOffset; | |
// fragment shader | |
uniform vec2 u_screenResolution; | |
varying float v_eyeOffset; | |
... | |
void main() { | |
if((step(0.5, gl_FragCoord.x / u_screenResolution.x) - 0.5) * v_eyeOffset < 0.0) discard; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment