Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save bileschi/9d1f0064c1266862c6a0ba49da136c38 to your computer and use it in GitHub Desktop.

Select an option

Save bileschi/9d1f0064c1266862c6a0ba49da136c38 to your computer and use it in GitHub Desktop.
Error from transpose of 1D tensor
1
2 precision highp float;
3 precision highp int;
4 varying vec2 resultUV;
5 const vec2 halfCR = vec2(0.5, 0.5);
6
7 bool isNaN(float val) {
8 float v1 = val * val;
9 float v2 = val * val;
10 return v1 == v2 ? false : true;
11 }
12
13 bool hasNaN(vec4 values) {
14 vec4 v1 = values * values;
15 vec4 v2 = values * values;
16 return any(notEqual(v1, v2));
17 }
18
19 float getNaN(vec4 values) {
20 return dot(vec4(1), values);
21 }
22
23 int round(float value) {
24 return int(floor(value + 0.5));
25 }
26
27 int imod(int x, int y) {
28 return x - y * (x / y);
29 }
30
31 const vec2 randomConst = vec2(
32 23.14069263277926, // e^pi (Gelfond's constant)
33 2.665144142690225 // 2^sqrt(2) (Gelfond–Schneider constant)
34 );
35
36 float random(float seed) {
37 return fract(cos(dot(resultUV * seed, randomConst)) * 12345.6789);
38 }
39
40
41 vec2 UVfrom1D(int texNumR, int texNumC, int index) {
42 int texR = index / texNumC;
43 int texC = index - texR * texNumC;
44 return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
45 }
46
47
48 vec2 UVfrom2D(int texNumR, int texNumC, int numC, int row, int col) {
49 int index = row * numC + col;
50 int texR = index / texNumC;
51 int texC = index - texR * texNumC;
52 return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
53 }
54
55
56 vec2 UVfrom3D(int texNumR, int texNumC, int stride0,
57 int stride1, int row, int col, int depth) {
58 // Explicitly use integer operations as dot() only works on floats.
59 int index = row * stride0 + col * stride1 + depth;
60 int texR = index / texNumC;
61 int texC = index - texR * texNumC;
62 return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
63 }
64
65
66 vec2 UVfrom4D(int texNumR, int texNumC, int stride0,
67 int stride1, int stride2, int row, int col, int depth,
68 int depth2) {
69 // Explicitly use integer operations as dot() only works on floats.
70 int index = row * stride0 + col * stride1 + depth * stride2 + depth2;
71 int texR = index / texNumC;
72 int texC = index - texR * texNumC;
73 return (vec2(texC, texR) + halfCR) / vec2(texNumC, texNumR);
74 }
75
76
77
78 float sampleTexture(sampler2D textureSampler, vec2 uv) {
79 return texture2D(textureSampler, uv).r;
80 }
81
82
83 void setOutput(float val) {
84 gl_FragColor = vec4(val, 0, 0, 0);
85 }
86
87 uniform sampler2D A;
88
89 int getOutputCoords() {
90 return int(resultUV.y * 6.0);
91 }
92
93
94 float getAFlat(int index) {
95 vec2 uv = vec2(0.5, (float(index) + 0.5) / 6.0);
96 return sampleTexture(A, uv);
97 }
98
99 float getA(int index) {
100 return getAFlat(index);
101 }
102
103 float getAAtOutCoords() {
104 return sampleTexture(A, resultUV);
105 }
106
107
108 void main() {
109 int resRC = getOutputCoords();
ERROR: 0:110: 'x' : field selection requires structure or vector on left hand side
%c 110 setOutput(getA(resRC.x));
111 }
112
An error occured
Failed to compile fragment shader.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment