Created
June 2, 2013 03:12
-
-
Save dermotbalson/5692491 to your computer and use it in GitHub Desktop.
transparent
This file contains 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
function setup() | |
m1=CreateMesh("Planet Cute:Character Princess Girl") | |
m2=CreateMesh("Planet Cute:Character Pink Girl") | |
m2.shader = shader(TransparentShader.vertexShader, TransparentShader.fragmentShader) | |
m3=CreateMesh("Cargo Bot:Starry Background") | |
end | |
function CreateMesh(imgName) | |
local img=readImage(imgName) | |
local m=mesh() | |
m.texture=img | |
local u=m:addRect(-img.width/2,-img.height/2,img.width,img.height) | |
m:setRectTex(u,0,0,1,1) | |
m:setColors(color(255)) | |
return m | |
end | |
function draw() | |
background(220) | |
perspective() | |
camera(0,20,200,0,0,0) | |
pushMatrix() | |
translate(0,0,-200) | |
m1:draw() | |
popMatrix() | |
pushMatrix() | |
translate(100,0,-200) | |
m2:draw() | |
popMatrix() | |
pushMatrix() | |
translate(120,20,-250) | |
m3:draw() | |
popMatrix() | |
end | |
TransparentShader = { | |
vertexShader = [[ | |
// | |
// A basic vertex shader | |
// | |
//This is the current model * view * projection matrix | |
// Codea sets it automatically | |
uniform mat4 modelViewProjection; | |
//This is the current mesh vertex position, color and tex coord | |
// Set automatically | |
attribute vec4 position; | |
attribute vec4 color; | |
attribute vec2 texCoord; | |
//This is an output variable that will be passed to the fragment shader | |
varying lowp vec4 vColor; | |
varying highp vec2 vTexCoord; | |
void main() | |
{ | |
//Pass the mesh color to the fragment shader | |
vColor = color; | |
vTexCoord = texCoord; | |
//Multiply the vertex position by our combined transform | |
gl_Position = modelViewProjection * position; | |
} | |
]], | |
fragmentShader = [[ | |
// | |
// A basic fragment shader | |
// | |
//Default precision qualifier | |
precision highp float; | |
//This represents the current texture on the mesh | |
uniform lowp sampler2D texture; | |
//The interpolated vertex color for this fragment | |
varying lowp vec4 vColor; | |
//The interpolated texture coordinate for this fragment | |
varying highp vec2 vTexCoord; | |
void main() | |
{ | |
lowp vec4 col=texture2D(texture, vTexCoord); | |
if (col.a<0.2) discard; | |
else gl_FragColor = col * vColor; | |
} | |
]]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment