Skip to content

Commit 9c8140b

Browse files
committed
Bug: Prevent 'uniform' variables having their names GOLFed.
These aren't allowed to be modified, as they are initialized from the shader's host code.
1 parent 62ab917 commit 9c8140b

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

ShaderShrinker/Shrinker.Parser/SyntaxNodes/SyntaxNodeExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ public static bool HasEntryPointFunction(this SyntaxNode rootNode) =>
103103
/// </summary>
104104
public static IEnumerable<string> FindUserDefinedNames(this SyntaxNode root)
105105
{
106-
var names = root.GlobalVariables().Select(o => o.Name).ToList();
106+
var nonUniformGlobals = root.GlobalVariables().Where(o => (o.Parent as VariableDeclarationSyntaxNode)?.VariableType.IsUniform != true);
107+
var names = nonUniformGlobals.Select(o => o.Name).ToList();
107108

108109
var functionDefinitions = root.FunctionDefinitions().ToList();
109110
names.AddRange(functionDefinitions.Select(o => o.Name));

ShaderShrinker/UnitTests/GolfTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public void CheckGolfingCodeNames(
7575
"void f(float n) { } void g() { vec2 vector = vec2(1); f(vector.x); }|void f(float n) { } void g() { vec2 v = vec2(1); f(v.x); }",
7676
"void f(vec2 a) { } void g() { vec2 vector = vec2(1); f(vector); }|void f(vec2 a) { } void g() { vec2 v = vec2(1); f(v); }",
7777
"struct S { int num; }; void f() { int num; S s; s.num = 1; }|struct S { int num; }; void f() { int n; S s; s.num = 1; }",
78-
"#define NUM 1.0\nfloat f() { return NUM; }|#define N 1.0 float f() { return N; }"
78+
"#define NUM 1.0\nfloat f() { return NUM; }|#define N 1.0 float f() { return N; }",
79+
"uniform float iTime; double main() { return iTime; }|uniform float iTime; double main(){ return iTime; }"
7980
)]
8081
string codeAndGolfed)
8182
{
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
// Processed by 'GLSL Shader Shrinker' (Shrunk by 303 characters)
1+
// Processed by 'GLSL Shader Shrinker' (Shrunk by 198 characters)
22
// (https://github.com/deanthecoder/GLSLShaderShrinker)
33

44
#version 410 core
55

66
precision mediump float;
7-
uniform float a;
8-
uniform vec2 e;
9-
uniform sampler1D t;
7+
uniform float fGlobalTime;
8+
uniform vec2 v2Resolution;
9+
uniform sampler1D texFFT;
1010
layout(location = 0)out vec4 o;
11-
vec4 p(vec2 v, float b) {
12-
float c = .5 + sin(v.x * 10.) + cos(sin(b + v.y) * 20.);
13-
return vec4(sin(c * .2 + cos(b)), c * .15, cos(c * .1 + b / .4) * .25, 1);
11+
vec4 p(vec2 v, float t) {
12+
float c = .5 + sin(v.x * 10.) + cos(sin(t + v.y) * 20.);
13+
return vec4(sin(c * .2 + cos(t)), c * .15, cos(c * .1 + t / .4) * .25, 1);
1414
}
1515

1616
void main() {
1717
vec2 m,
18-
u = vec2(gl_FragCoord.x / e.x, gl_FragCoord.y / e.y);
18+
u = vec2(gl_FragCoord.x / v2Resolution.x, gl_FragCoord.y / v2Resolution.y);
1919
u -= .5;
20-
u /= vec2(e.y / e.x, 1);
20+
u /= vec2(v2Resolution.y / v2Resolution.x, 1);
2121
m.x = atan(u.x / u.y) / 3.14;
2222
m.y = 1 / length(u) * .2;
2323
float d = m.y,
24-
f = texture(t, d).r * 100;
25-
m.x += sin(a) * .1;
26-
m.y += a * .25;
27-
o = f + clamp(p(m * 3.14, a) / d, 0., 1.);
24+
f = texture(texFFT, d).r * 100;
25+
m.x += sin(fGlobalTime) * .1;
26+
m.y += fGlobalTime * .25;
27+
o = f + clamp(p(m * 3.14, fGlobalTime) / d, 0., 1.);
2828
}

0 commit comments

Comments
 (0)