Skip to content

Commit

Permalink
Add zfast-lcd shader (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
kivutar authored Jun 2, 2021
1 parent 912ac62 commit 92ee9c3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion menu/scene_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ var incrCallbacks = map[string]callbackIncrement{
settings.Save()
},
"VideoFilter": func(f *structs.Field, direction int) {
filters := []string{"Raw", "Smooth", "Pixel Perfect", "CRT"}
filters := []string{"Raw", "Smooth", "Pixel Perfect", "CRT", "LCD"}
v := f.Value().(string)
i := utils.IndexOfString(v, filters)
i += direction
Expand Down
48 changes: 48 additions & 0 deletions video/lcd_frag_shader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package video

var zfastLCDFragmentShader = `
#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 vec2 OutputSize;
uniform vec2 TextureSize;
uniform vec2 InputSize;
uniform sampler2D Texture;
COMPAT_VARYING vec2 fragTexCoord;
#define BORDERMULT 14.0
#define GBAGAMMA 1.0
void main() {
vec2 texcoordInPixels = fragTexCoord.xy * TextureSize.xy;
vec2 centerCoord = floor(texcoordInPixels.xy)+vec2(0.5,0.5);
vec2 distFromCenter = abs(centerCoord - texcoordInPixels);
vec2 invSize = 1.0/TextureSize.xy;
float Y = max(distFromCenter.x,(distFromCenter.y));
Y=Y*Y;
float YY = Y*Y;
float YYY = YY*Y;
float LineWeight = YY - 2.7*YYY;
LineWeight = 1.0 - BORDERMULT*LineWeight;
vec3 colour = COMPAT_TEXTURE(Texture, invSize*centerCoord).rgb*LineWeight;
if (GBAGAMMA > 0.5)
colour.rgb*=0.6+0.4*(colour.rgb); //fake gamma because the pi is too slow!
COMPAT_FRAGCOLOR = vec4(colour.rgb , 1.0);
}
` + "\x00"
11 changes: 11 additions & 0 deletions video/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Video struct {
defaultProgram uint32 // default program used for the game quad
sharpBilinearProgram uint32 // sharp bilinear program used for the game quad
zfastCRTProgram uint32 // fast CRT program used for the game quad
zfastLCDProgram uint32 // fast LCD program used for the game quad
roundedProgram uint32 // program to draw rectangles with rounded corners
borderProgram uint32 // program to draw rectangles borders
circleProgram uint32 // program to draw textured circles
Expand Down Expand Up @@ -139,6 +140,11 @@ func (video *Video) Configure(fullscreen bool) {
panic(err)
}

video.zfastLCDProgram, err = newProgram(vertexShader, zfastLCDFragmentShader)
if err != nil {
panic(err)
}

video.roundedProgram, err = newProgram(vertexShader, roundedFragmentShader)
if err != nil {
panic(err)
Expand Down Expand Up @@ -211,6 +217,7 @@ func (video *Video) Configure(fullscreen bool) {
// Smooth: linear
// Pixel Perfect: sharp-bilinear
// CRT: zfast-crt
// LCD: zfast-lcd
func (video *Video) UpdateFilter(filter string) {
gl.BindTexture(gl.TEXTURE_2D, video.texID)
switch filter {
Expand All @@ -226,6 +233,10 @@ func (video *Video) UpdateFilter(filter string) {
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
video.program = video.zfastCRTProgram
case "LCD":
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
video.program = video.zfastLCDProgram
case "Raw":
fallthrough
default:
Expand Down

0 comments on commit 92ee9c3

Please sign in to comment.