progress on getting ios version working well.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
(ns advent.screens.shader)
|
||||
(ns advent.screens.shader
|
||||
(:require [advent.utils :as utils]))
|
||||
|
||||
(def v-shader "attribute vec4 a_position;
|
||||
|
||||
(def v-shader (constantly "attribute vec4 a_position;
|
||||
attribute vec4 a_color;
|
||||
attribute vec2 a_texCoord0;
|
||||
|
||||
@@ -13,10 +15,56 @@ void main() {
|
||||
v_color = a_color;
|
||||
v_texCoords = a_texCoord0;
|
||||
gl_Position = u_projTrans * a_position;
|
||||
}")
|
||||
}"))
|
||||
|
||||
|
||||
(def pix-shader "
|
||||
(def mobile-pix-shader
|
||||
"
|
||||
#ifdef GL_ES
|
||||
#define LOWP lowp
|
||||
#define HIGHP highp
|
||||
precision mediump float;
|
||||
#else
|
||||
#define LOWP
|
||||
#define HIGHP
|
||||
#endif
|
||||
|
||||
varying vec4 v_color;
|
||||
varying HIGHP vec2 v_texCoords;
|
||||
uniform HIGHP float multiply_amount;
|
||||
uniform HIGHP float hue_amount;
|
||||
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
vec4 toGrayscale(in vec4 color)
|
||||
{
|
||||
float average = (color.r + color.g + color.b) / 3.0;
|
||||
return vec4(average, average, average, color.a);
|
||||
}
|
||||
|
||||
vec4 colorize(in vec4 grayscale, in vec4 color)
|
||||
{
|
||||
return (grayscale * color);
|
||||
}
|
||||
|
||||
|
||||
void main ()
|
||||
{
|
||||
vec4 scaledColor = texture2D(u_texture, v_texCoords);
|
||||
|
||||
vec4 grayscale = toGrayscale(scaledColor);
|
||||
vec4 colorizedOutput = mix(scaledColor, colorize(grayscale, v_color.rgba), hue_amount);
|
||||
|
||||
vec4 multiplied = mix(colorizedOutput.rgba, v_color.rgba * scaledColor.rgba, multiply_amount);
|
||||
|
||||
gl_FragColor = vec4(multiplied.rgb, scaledColor.a * v_color.a);
|
||||
|
||||
}
|
||||
"
|
||||
)
|
||||
|
||||
(def desktop-pix-shader
|
||||
"
|
||||
#ifdef GL_ES
|
||||
#define LOWP lowp
|
||||
#define HIGHP highp
|
||||
@@ -64,6 +112,7 @@ void main ()
|
||||
c3 *= frac.x * (1.0 - frac.y);
|
||||
c4 *= (1.0 - frac.x) * (1.0 - frac.y);
|
||||
vec4 scaledColor = (c1 + c2 + c3 + c4);
|
||||
vec4 scaledColor = texture2D(u_texture, v_texCoords);
|
||||
|
||||
vec4 grayscale = toGrayscale(scaledColor);
|
||||
vec4 colorizedOutput = mix(scaledColor, colorize(grayscale, v_color.rgba), hue_amount);
|
||||
@@ -74,3 +123,11 @@ void main ()
|
||||
|
||||
}
|
||||
")
|
||||
|
||||
|
||||
(defn pix-shader []
|
||||
(if utils/mobile?
|
||||
mobile-pix-shader
|
||||
desktop-pix-shader
|
||||
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user