The Internet Moon

2D / 3D Rotate

Rotation: zValue: Session Token:

Click here!

Instructions

attribute vec3 aVertexPosition; attribute vec3 aVertexNormal; attribute vec2 aTextureCoord; uniform mat4 uMVMatrix; uniform mat4 uPMatrix; uniform mat3 uNMatrix; varying vec2 vTextureCoord; varying vec3 vTransformedNormal; varying vec4 vPosition; void main(void) { vPosition = uMVMatrix * vec4(aVertexPosition, 1.0); gl_Position = uPMatrix * vPosition; vTextureCoord = aTextureCoord; vTransformedNormal = uNMatrix * aVertexNormal; }

precision mediump float; const int DM_PRESENTATION = 0; //const int DM_SELECTION = 1; const int SS_FREE = 1; const int SS_AVAILABLE = 2; const int SS_RESERVED = 3; const int SS_OWNED = 4; const int SS_SELECTED = 5; const int SS_EDITABLE = 6; const int SS_HIGHLIGHT = 7; varying vec2 vTextureCoord; varying vec3 vTransformedNormal; varying vec4 vPosition; uniform float uMaterialShininess; uniform bool uShowSpecularHighlights; uniform bool uUseLighting; uniform vec3 uAmbientColor; uniform vec3 uPointLightingLocation; uniform vec3 uPointLightingSpecularColor; uniform vec3 uPointLightingDiffuseColor; uniform bool uDoHighlight; uniform vec3 uHighlightColor; uniform int anaMode; uniform vec4 leftR, rightR, leftG, rightG, leftB, rightB; uniform sampler2D leftImage; uniform vec2 leftImageSize; uniform sampler2D uSampler; uniform sampler2D uState; uniform int mode; // 0 - apresentacao, 1 - selection, 2 - selection disabled free. int getKey(float alpha) { if (alpha < 0.500980392) { if (alpha < 0.250490196) { if (alpha < 0.125245098) { return alpha < 0.062622549 ? 0 : 1; } else { return alpha < 0.187867647 ? 2 : 3; } } else { if (alpha < 0.375735294) { return alpha < 0.313112745 ? 4 : 5; } else { return alpha < 0.438357843 ? 6 : 7; } } } else { if (alpha < 0.751470588) { if (alpha < 0.626225490) { return alpha < 0.563602941 ? 8 : 9; } else { return alpha < 0.688848039 ? 10 : 11; } } else { if (alpha < 0.876715686) { return alpha < 0.814093137 ? 12 : 13; } else { return alpha < 0.939338235 ? 14 : 15; } } } } vec4 textureColor() { vec4 ret = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t)); if (mode == DM_PRESENTATION) { return ret; } vec4 state = texture2D(uState, vec2(vTextureCoord.s, vTextureCoord.t)); ret.a = state.r; return ret; } vec4 fragmentColor() { vec4 texColor = textureColor(); if (uDoHighlight) { return vec4(texColor.rgb * uHighlightColor, 1.0); } vec3 lightWeighting; if (!uUseLighting) { lightWeighting = vec3(1.0, 1.0, 1.0); } else { vec3 lightDirection = normalize(uPointLightingLocation - vPosition.xyz); vec3 normal = normalize(vTransformedNormal); float specularLightWeighting = 0.0; if (uShowSpecularHighlights) { vec3 eyeDirection = normalize(-vPosition.xyz); vec3 reflectionDirection = reflect(-lightDirection, normal); specularLightWeighting = pow(max(dot(reflectionDirection, eyeDirection), 0.0), uMaterialShininess); } float diffuseLightWeighting = max(dot(normal, lightDirection), 0.0); lightWeighting = uAmbientColor + uPointLightingSpecularColor * specularLightWeighting + uPointLightingDiffuseColor * diffuseLightWeighting; } return vec4(texColor.rgb * lightWeighting, 1.0); } vec4 anaglyphColor(vec4 L, vec4 R) { vec4 left = vec4(1.0, L.g, L.b, 1.0); // Left eye is full red and actual green and blue vec4 right = vec4(R.r, 1.0, 1.0, 1.0); // Right eye is full green and blue and actual red return vec4(left.rgb * right.rgb, 1.0); } vec4 anaglyphColorOld(vec4 L, vec4 R) { return vec4( dot(L, leftR) + dot(R, rightR) / 1000.0, dot(L, leftG) + dot(R, rightG) / 1000.0, dot(L, leftB) + dot(R, rightB) / 1000.0, (L.a + R.a) / 1.0 ); } vec4 presentationScene() { if (anaMode == 0) { return fragmentColor(); } if (anaMode == 1) { // Gera 70% do vermelho. vec4 result = fragmentColor(); result.r *= 0.7; return result; } vec4 inputColor = texture2D(leftImage, gl_FragCoord.xy / leftImageSize); inputColor = gl_FragColor; if (anaMode == 1) { if (inputColor.a == 0.0) { // Sem coincidencia, faz mixagem com preto. return anaglyphColor(fragmentColor(), vec4(0.0, 0.0, 0.0, 1.0)); //return fragmentColor(); } // O pixel jah tinha a imagem do olho direito, faz mixagem. vec4 result = anaglyphColor(fragmentColor(), inputColor); result.a = 0.0; // Marca como resolvido. return result; } if (anaMode == 2) { if (inputColor.a != 0.0) { // Sem coincidencia, faz mixagem com preto. return anaglyphColor(vec4(0.0, 0.0, 0.0, 1.0), inputColor); } // Jah foi resolvido. Eh soh corrigir o alpha. inputColor.a = 1.0; return inputColor; } return vec4(0.0, 0.0, 0.0, 0.0); } vec4 colorByKey(int key, vec3 texColor) { if (key == SS_EDITABLE) { // color return vec4(texColor, 1.0); } float gray = 0.2 + (texColor.r * 0.2126 + texColor.g * 0.7152 + texColor.b * 0.0722); if (key == SS_AVAILABLE || (mode == 2 && key == SS_FREE)) { // green return vec4(gray * 0.4, gray * 0.6, gray * 0.4, 1.0); } if (key == SS_OWNED) { // dark gray return vec4(gray * 0.5, gray * 0.5, gray * 0.5, 1.0); } if (key == SS_FREE) { // blue return vec4(gray * 0.3, gray * 0.5, gray * 0.8, 1.0); } if (key == SS_RESERVED) { // red return vec4(gray * 0.85, gray * 0.2, gray * 0.2, 1.0); } if (key == SS_SELECTED) { // light purple return vec4(gray * 1.1, gray * 0.5, gray * 0.9, 1.0); } return vec4(0.0, 0.0, 0.0, 1.0); } vec4 selectionScene() { vec4 texColor = textureColor(); int key = getKey(texColor.a); texColor = colorByKey(key, texColor.rgb); if (!uDoHighlight) { return texColor; } return vec4(texColor.rgb * uHighlightColor, 1.0); } void main() { if (mode == DM_PRESENTATION) { gl_FragColor = presentationScene(); } else { gl_FragColor = selectionScene(); } }