Last active
February 2, 2018 16:05
-
-
Save tgfrerer/6009069 to your computer and use it in GitHub Desktop.
circle mask shader - use these with openGL 2.0
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
#include "testApp.h" | |
//-------------------------------------------------------------- | |
void testApp::setup(){ | |
mPlayer.loadMovie("test_movie.mov"); | |
circleShader.load("circle_mask"); | |
mPlayer.play(); | |
} | |
//-------------------------------------------------------------- | |
void testApp::update(){ | |
mPlayer.update(); | |
} | |
//-------------------------------------------------------------- | |
void testApp::draw(){ | |
circleShader.begin(); | |
mPlayer.getTextureReference().draw(ofVec2f(0,0)); | |
circleShader.end(); | |
} |
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
#version 120 | |
#extension GL_ARB_texture_rectangle : enable | |
uniform sampler2DRect tex; | |
void main() | |
{ | |
float texWidth=1920.0; // width in pixels | |
float texHeight=1080.0; // height in pixels | |
float edge = 500 / texWidth; // value in pixels, i.e. circle will have a 500 px radius | |
float edgewidth = 10.0 / texWidth; // value in pixels, i.e. will give you a 10 px blurred edge… | |
float heightWidthRatio = texHeight / texWidth; | |
vec2 normalizedTexCoord = (vec2(gl_TexCoord[0].x / texWidth, gl_TexCoord[0].y / texHeight ) ) - vec2(0.5, 0.5) ; | |
normalizedTexCoord.y = normalizedTexCoord.y * heightWidthRatio; | |
float opacity = clamp(0.0,1.0,1.0 - smoothstep(edge, edge+edgewidth, (length(normalizedTexCoord)))); | |
gl_FragColor = vec4((gl_Color * texture2DRect(tex, gl_TexCoord[0].xy)).rgb,opacity); | |
} |
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
#version 120 | |
#extension GL_ARB_texture_rectangle : enable | |
void main() | |
{ | |
gl_FrontColor = gl_Color; | |
gl_TexCoord[0] = gl_MultiTexCoord0; | |
gl_Position = ftransform(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case someone else ends up trying to use this code as an example, there is a mistake here with the use of clamp. The arguments are in the wrong order. I also had to change the last line.
Here is the last two lines fixed: