working on ios perf.
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
[advent.tween :as tween]
|
||||
[advent.steam :as steam]
|
||||
[advent.screens.rooms :as rooms]
|
||||
[advent.screens.shader :refer [v-shader pix-shader]]
|
||||
[advent.screens.fade :refer [fade-screen]]
|
||||
[advent.screens.items :as items]
|
||||
[advent.screens.rooms.dream :as rooms.dream]
|
||||
@@ -61,118 +62,7 @@
|
||||
|
||||
(declare get-selected-inventory-item)
|
||||
|
||||
(def v-shader "attribute vec4 a_position;
|
||||
attribute vec4 a_color;
|
||||
attribute vec2 a_texCoord0;
|
||||
|
||||
uniform mat4 u_projTrans;
|
||||
|
||||
varying vec4 v_color;
|
||||
varying vec2 v_texCoords;
|
||||
|
||||
void main() {
|
||||
v_color = a_color;
|
||||
v_texCoords = a_texCoord0;
|
||||
gl_Position = u_projTrans * a_position;
|
||||
}")
|
||||
|
||||
|
||||
|
||||
(def pix-shader "
|
||||
#ifdef GL_ES
|
||||
#define LOWP lowp
|
||||
precision mediump float;
|
||||
#else
|
||||
#define LOWP
|
||||
#endif
|
||||
|
||||
varying LOWP vec4 v_color;
|
||||
varying vec2 v_texCoords;
|
||||
uniform float multiply_amount;
|
||||
uniform float hue_amount;
|
||||
|
||||
uniform sampler2D u_texture;
|
||||
|
||||
float Epsilon = 1e-3;
|
||||
|
||||
vec3 RGBtoHCV (vec3 RGB)
|
||||
{
|
||||
// Based on work by Sam Hocevar and Emil Persson
|
||||
vec4 P = (RGB.g < RGB.b) ? vec4 (RGB.bg, -1.0, 2.0/3.0) : vec4 (RGB.gb, 0.0, -1.0/3.0);
|
||||
vec4 Q = (RGB.r < P.x) ? vec4 (P.xyw, RGB.r) : vec4 (RGB.r, P.yzx);
|
||||
float C = Q.x - min (Q.w, Q.y);
|
||||
float H = abs ((Q.w - Q.y) / (6.0 * C + Epsilon) + Q.z);
|
||||
return vec3 (H, C, Q.x);
|
||||
}
|
||||
|
||||
vec3 HUEtoRGB(float H)
|
||||
{
|
||||
float R = abs(H * 6.0 - 3.0) - 1.0;
|
||||
float G = 2.0 - abs(H * 6.0 - 2.0);
|
||||
float B = 2.0 - abs(H * 6.0 - 4.0);
|
||||
return clamp(vec3(R,G,B), 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec4 HSLtoRGB(vec3 HSL)
|
||||
{
|
||||
vec3 RGB = HUEtoRGB(HSL.x);
|
||||
float C = (1.0 - abs(2.0 * HSL.z - 1.0)) * HSL.y;
|
||||
vec3 result = (RGB - 0.5) * C + HSL.z;
|
||||
return vec4(result[0], result[1], result[2], 0.0);
|
||||
}
|
||||
|
||||
|
||||
vec4 RGBtoHSL(vec4 RGB)
|
||||
{
|
||||
vec3 HCV = RGBtoHCV(RGB.rgb);
|
||||
float L = HCV.z - HCV.y * 0.5;
|
||||
float S = HCV.y / (1.0 - abs(L * 2.0 - 1.0) + Epsilon);
|
||||
return vec4(HCV.x, S, L, 0.0);
|
||||
}
|
||||
|
||||
vec4 BlendHue(vec4 base, vec4 blend)
|
||||
{
|
||||
if (blend.r == blend.g && blend.g == blend.b) {
|
||||
return base;
|
||||
}
|
||||
else {
|
||||
vec4 baseHSL = RGBtoHSL(base);
|
||||
return HSLtoRGB(vec3(RGBtoHSL(blend).r, baseHSL.g, baseHSL.b));
|
||||
}
|
||||
}
|
||||
|
||||
#define BlendOpacity(base, blend, F, O) (F(base, blend) * O + blend * (1.0 - O))
|
||||
|
||||
|
||||
|
||||
void main ()
|
||||
{
|
||||
|
||||
vec2 sz = vec2 (2048.0, 2048.0);
|
||||
vec3 step = vec3 (1.0 / 4.0, 1.0 / 4.0, 0.0);
|
||||
vec2 tex_pixel = sz * v_texCoords - step.xy / 2.0;
|
||||
|
||||
vec2 corner = floor (tex_pixel) + 1.0;
|
||||
vec2 frac = min ((corner - tex_pixel) * vec2 (4.0, 4.0), vec2 (1.0, 1.0));
|
||||
|
||||
vec4 c1 = texture2D (u_texture, (floor (tex_pixel + step.zz) + 0.5) / sz);
|
||||
vec4 c2 = texture2D (u_texture, (floor (tex_pixel + step.xz) + 0.5) / sz);
|
||||
vec4 c3 = texture2D (u_texture, (floor (tex_pixel + step.zy) + 0.5) / sz);
|
||||
vec4 c4 = texture2D (u_texture, (floor (tex_pixel + step.xy) + 0.5) / sz);
|
||||
|
||||
c1 *= frac.x * frac.y;
|
||||
c2 *= (1.0 - frac.x) * frac.y;
|
||||
c3 *= frac.x * (1.0 - frac.y);
|
||||
c4 *= (1.0 - frac.x) * (1.0 - frac.y);
|
||||
vec4 scaledColor = (c1 + c2 + c3 + c4);
|
||||
|
||||
vec4 multiplied = mix(scaledColor.rgba, v_color.rgba * scaledColor.rgba, multiply_amount * 0.67 );
|
||||
vec4 hued = mix(multiplied, BlendHue(multiplied.rgba, v_color.rgba), hue_amount * 0.67);
|
||||
|
||||
gl_FragColor = vec4(hued.xyz, scaledColor.a);
|
||||
|
||||
}
|
||||
")
|
||||
;
|
||||
|
||||
(defn ensure-on-screen [l]
|
||||
@@ -990,14 +880,14 @@ void main ()
|
||||
(assoc (:state selected-save) :active? true)
|
||||
{:object nil
|
||||
:active? true
|
||||
:last-room :dream
|
||||
:time :intro
|
||||
:last-room :outside-house
|
||||
:time :night
|
||||
:obtained-items #{}
|
||||
:inventory []
|
||||
:plaques-read #{}
|
||||
:clues #{}
|
||||
:mints-eaten 0
|
||||
:seen-intro? false}))
|
||||
:seen-intro? true}))
|
||||
|
||||
(defn fade-in-first-time-if-necessary [screen entities]
|
||||
(if (not (get-in entities [:started? :value]))
|
||||
@@ -1096,7 +986,7 @@ void main ()
|
||||
(.setShader batch shader)
|
||||
(when shader
|
||||
(.setUniformf shader "multiply_amount" (float (or multiply-amount 1.0)))
|
||||
(.setUniformf shader "hue_amount" (float (or hue-amount 1.0))))
|
||||
(.setUniformf shader "hue_amount" (float (or hue-amount 0.0))))
|
||||
|
||||
(.setColor batch (color (:r e 1.0) (:g e 1.0) (:b e 1.0) (:opacity e 1.0)))
|
||||
|
||||
@@ -1954,7 +1844,7 @@ void main ()
|
||||
:anim-start 0
|
||||
:opacity 0.8)
|
||||
:all-items (texture! (texture (pixmap "cursor.png")) :split 18 16)
|
||||
#_:fps #_(->> (assoc (label "" (color :white) ) :x 5 :baseline 0 :opacity 0.1)
|
||||
:fps (->> (assoc (label "" (color :white) ) :y 30 :x 5 :baseline 0 :opacity 0.1)
|
||||
(utils/add-actor-to-stage screen))}))
|
||||
|
||||
:on-render
|
||||
@@ -1985,14 +1875,14 @@ void main ()
|
||||
(grow-hud screen entities :save false)))
|
||||
|
||||
entities (or (process-fsm screen entities) entities)]
|
||||
#_(label! (:fps entities) :set-text (str (game :fps)))
|
||||
(label! (:fps entities) :set-text (str (game :fps)))
|
||||
|
||||
|
||||
|
||||
(render! screen [ (if (and hud-interactable? (not (:already-saved? entities)))
|
||||
(:save entities)
|
||||
(assoc (:save entities) :opacity 0.5))
|
||||
#_(:fps entities)
|
||||
(:fps entities)
|
||||
(if hud-interactable?
|
||||
(:inventory entities)
|
||||
(assoc (:inventory entities) :opacity 0.5))
|
||||
|
||||
Reference in New Issue
Block a user