From 055e35257856a2254ba0055b98c355b7480da338 Mon Sep 17 00:00:00 2001 From: Laurent Le Brun Date: Sat, 31 Dec 2022 22:18:26 +0100 Subject: [PATCH] Simple vec when all arguments are equal vec2(1,1) => vec2(1) --- README.md | 9 ++++++++- src/rewriter.fs | 11 +++++++++++ tests/real/from-the-seas-to-the-stars.frag.expected | 4 ++-- tests/real/leizex.expected | 2 +- tests/real/mandelbulb.expected | 4 ++-- tests/real/ohanami.frag.expected | 2 +- tests/real/sult.expected | 2 +- .../the_real_party_is_in_your_pocket.frag.expected | 8 ++++---- tests/real/valley_ball.glsl.expected | 2 +- tests/real/yx_long_way_from_home.frag.expected | 4 ++-- tests/unit/vectors.frag.expected | 2 +- 11 files changed, 34 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 88a5c3c9..b3285971 100644 --- a/README.md +++ b/README.md @@ -480,18 +480,25 @@ stored the result of a computation), so be careful with it. ### Vector constructors -Calls to `vec2`, `vec3`, and `vec4` can be simplified using swizzles. +- Calls to `vec2`, `vec3`, and `vec4` can be simplified using swizzles. +- Remove useless constructor, when the argument is already a vec using swizzles. +- If all arguments are equal (but not function calls), use only one argument. +- Replace floats with ints, as it is safe inside the vec constructors. Input: ```glsl vec4(v1.x, v1.z, v2.r, v2.t); vec2(v1.xx); +vec2(1.2, 1.2); +vec2(1.); ``` Output: ```glsl vec4(v1.xz,v2.xy); v1.xx; +vec2(1.2); +vec2(1); ```