-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into kivutar/gl
- Loading branch information
Showing
14 changed files
with
267 additions
and
126 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
package video | ||
|
||
// source of the shader to draw circles | ||
var circleFragmentShader = ` | ||
#version 330 | ||
#if __VERSION__ >= 130 | ||
#define COMPAT_VARYING in | ||
#define COMPAT_ATTRIBUTE in | ||
#define COMPAT_TEXTURE texture | ||
#define COMPAT_FRAGCOLOR FragColor | ||
out vec4 COMPAT_FRAGCOLOR; | ||
#else | ||
#define COMPAT_VARYING varying | ||
#define COMPAT_ATTRIBUTE attribute | ||
#define COMPAT_TEXTURE texture2D | ||
#define COMPAT_FRAGCOLOR gl_FragColor | ||
#endif | ||
uniform sampler2D tex; | ||
uniform vec4 color; | ||
in vec2 fragTexCoord; | ||
out vec4 outputColor; | ||
COMPAT_VARYING vec2 fragTexCoord; | ||
float circle(in vec2 _st, in float _radius) { | ||
float circle(vec2 _st, float _radius) { | ||
vec2 dist = _st - vec2(0.5); | ||
return 1.-smoothstep(_radius-(_radius*0.05), _radius+(_radius*0.05), dot(dist,dist)*4.0); | ||
} | ||
void main() { | ||
outputColor = vec4(color.rgb, circle(fragTexCoord.xy, 0.125)); | ||
COMPAT_FRAGCOLOR = vec4(color.rgb, circle(fragTexCoord.xy, 0.125)); | ||
} | ||
` + "\x00" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
package video | ||
|
||
var darkenFragmentShader = ` | ||
#version 330 | ||
#if __VERSION__ >= 130 | ||
#define COMPAT_VARYING in | ||
#define COMPAT_ATTRIBUTE in | ||
#define COMPAT_TEXTURE texture | ||
#define COMPAT_FRAGCOLOR FragColor | ||
out vec4 COMPAT_FRAGCOLOR; | ||
#else | ||
#define COMPAT_VARYING varying | ||
#define COMPAT_ATTRIBUTE attribute | ||
#define COMPAT_TEXTURE texture2D | ||
#define COMPAT_FRAGCOLOR gl_FragColor | ||
#endif | ||
uniform sampler2D tex; | ||
uniform float mask; | ||
uniform vec4 texColor; | ||
in vec2 fragTexCoord; | ||
COMPAT_VARYING vec2 fragTexCoord; | ||
out vec4 outputColor; | ||
vec4 grayscale(in vec4 c) { | ||
vec4 grayscale(vec4 c) { | ||
float average = (c.r + c.g + c.b) / 3.0; | ||
return vec4(average, average, average, 1.0); | ||
} | ||
vec4 darken(in vec4 c) { | ||
return vec4(c.r/4, c.g/4, c.b/4, 1.0); | ||
vec4 darken(vec4 c) { | ||
return vec4(c.r/4.0, c.g/4.0, c.b/4.0, 1.0); | ||
} | ||
void main() { | ||
vec4 color = texture(tex, fragTexCoord); | ||
outputColor = texColor * mix(color, darken(grayscale(color)), mask); | ||
vec4 color = COMPAT_TEXTURE(tex, fragTexCoord); | ||
COMPAT_FRAGCOLOR = texColor * mix(color, darken(grayscale(color)), mask); | ||
} | ||
` + "\x00" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package video | ||
|
||
var vertexShader = ` | ||
#if __VERSION__ >= 130 | ||
#define COMPAT_VARYING out | ||
#define COMPAT_ATTRIBUTE in | ||
#define COMPAT_TEXTURE texture | ||
#define COMPAT_FRAGCOLOR FragColor | ||
out vec4 COMPAT_FRAGCOLOR; | ||
#else | ||
#define COMPAT_VARYING varying | ||
#define COMPAT_ATTRIBUTE attribute | ||
#define COMPAT_TEXTURE texture2D | ||
#define COMPAT_FRAGCOLOR gl_FragColor | ||
#endif | ||
COMPAT_ATTRIBUTE vec2 vert; | ||
COMPAT_ATTRIBUTE vec2 vertTexCoord; | ||
COMPAT_VARYING vec2 fragTexCoord; | ||
void main() { | ||
fragTexCoord = vertTexCoord; | ||
gl_Position = vec4(vert, 0, 1); | ||
} | ||
` + "\x00" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
package video | ||
|
||
var demulFragmentShader = ` | ||
#version 330 | ||
#if __VERSION__ >= 130 | ||
#define COMPAT_VARYING in | ||
#define COMPAT_ATTRIBUTE in | ||
#define COMPAT_TEXTURE texture | ||
#define COMPAT_FRAGCOLOR FragColor | ||
out vec4 COMPAT_FRAGCOLOR; | ||
#else | ||
#define COMPAT_VARYING varying | ||
#define COMPAT_ATTRIBUTE attribute | ||
#define COMPAT_TEXTURE texture2D | ||
#define COMPAT_FRAGCOLOR gl_FragColor | ||
#endif | ||
uniform sampler2D tex; | ||
uniform float mask; | ||
uniform vec4 texColor; | ||
in vec2 fragTexCoord; | ||
COMPAT_VARYING vec2 fragTexCoord; | ||
out vec4 outputColor; | ||
vec4 demultiply(in vec4 c) { | ||
vec4 demultiply(vec4 c) { | ||
return vec4(c.rgb/c.a, c.a); | ||
} | ||
void main() { | ||
vec4 color = demultiply(texture(tex, fragTexCoord)); | ||
outputColor = texColor * color; | ||
vec4 color = demultiply(COMPAT_TEXTURE(tex, fragTexCoord)); | ||
COMPAT_FRAGCOLOR = texColor * color; | ||
} | ||
` + "\x00" |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package video | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/go-gl/gl/all-core/gl" | ||
) | ||
|
||
func newProgram(GLSLVersion uint, vertexShaderSource, fragmentShaderSource string) (uint32, error) { | ||
vertexShaderSource = fmt.Sprintf("#version %d\n", GLSLVersion) + vertexShaderSource | ||
fragmentShaderSource = fmt.Sprintf("#version %d\n", GLSLVersion) + fragmentShaderSource | ||
|
||
vertexShader, err := compileShader(vertexShaderSource, gl.VERTEX_SHADER) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
fragmentShader, err := compileShader(fragmentShaderSource, gl.FRAGMENT_SHADER) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
program := gl.CreateProgram() | ||
|
||
gl.AttachShader(program, vertexShader) | ||
gl.AttachShader(program, fragmentShader) | ||
gl.LinkProgram(program) | ||
|
||
var status int32 | ||
gl.GetProgramiv(program, gl.LINK_STATUS, &status) | ||
if status == gl.FALSE { | ||
var logLength int32 | ||
gl.GetProgramiv(program, gl.INFO_LOG_LENGTH, &logLength) | ||
|
||
log := strings.Repeat("\x00", int(logLength+1)) | ||
gl.GetProgramInfoLog(program, logLength, nil, gl.Str(log)) | ||
|
||
return 0, fmt.Errorf("failed to link program: %v", log) | ||
} | ||
|
||
gl.DeleteShader(vertexShader) | ||
gl.DeleteShader(fragmentShader) | ||
|
||
return program, nil | ||
} | ||
|
||
func compileShader(source string, shaderType uint32) (uint32, error) { | ||
shader := gl.CreateShader(shaderType) | ||
|
||
csources, free := gl.Strs(source) | ||
gl.ShaderSource(shader, 1, csources, nil) | ||
free() | ||
gl.CompileShader(shader) | ||
|
||
var status int32 | ||
gl.GetShaderiv(shader, gl.COMPILE_STATUS, &status) | ||
if status == gl.FALSE { | ||
var logLength int32 | ||
gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &logLength) | ||
|
||
log := strings.Repeat("\x00", int(logLength+1)) | ||
gl.GetShaderInfoLog(shader, logLength, nil, gl.Str(log)) | ||
|
||
return 0, fmt.Errorf("failed to compile %v: %v", source, log) | ||
} | ||
|
||
return shader, nil | ||
} |
Oops, something went wrong.