kovasb / gamma

glsl shaders made simple
Eclipse Public License 1.0
306 stars 20 forks source link

Invalid output #1

Closed sgrove closed 9 years ago

sgrove commented 9 years ago
(def vertex-position (g/attribute "a_VertexPosition" :vec2))
(def vertex-color (g/attribute "a_VertexColor" :vec4))
(def vtx-time (g/uniform "u_Time" :vec2))
(def v-color (g/varying "vColor" :vec4 :mediump))

(def vertex-shader {v-color         vertex-color
                    (g/gl-position) (g/+
                                     (g/vec4 (g/+ (g/* (g/swizzle vertex-position :x) (g/swizzle vtx-time :y))
                                                  (g/* (g/swizzle vertex-position :y) (g/swizzle vtx-time :x)))
                                             (g/- (g/* (g/swizzle vertex-position :y) (g/swizzle vtx-time :y))
                                                  (g/* (g/swizzle vertex-position :x) (g/swizzle vtx-time :x)))
                                             (g/swizzle vertex-position :z) 0)
                                     (g/vec4 vertex-position 0 1))})

Outputs:

attribute vec4 a_VertexColor;
attribute vec2 a_VertexPosition;
uniform vec2 u_Time;
varying mediump vec4 vColor;
void main(void){
[:nil {:source-id {:tag :id, :id 4572}, :id {:tag :id, :id 4608}}][:nil {:source-id {:tag :id, :id 4573}, :id {:tag :id, :id 4609}}][:nil {:source-id {:tag :id, :id 4574}, :id {:tag :id, :id 4610}}]
vColor = a_VertexColor;
gl_Position = vec4(
  a_VertexPosition.x * u_Time.y + a_VertexPosition.y * u_Time.x,
  a_VertexPosition.y * u_Time.y - a_VertexPosition.x * u_Time.x,
  a_VertexPosition.z,
  0) + vec4(, , );
}

(notice the clojure literals)

Either removing the v-color entry produces valid output:

(def vertex-shader {(g/gl-position) (g/+
                                     (g/vec4 (g/+ (g/* (g/swizzle vertex-position :x) (g/swizzle vtx-time :y))
                                                  (g/* (g/swizzle vertex-position :y) (g/swizzle vtx-time :x)))
                                             (g/- (g/* (g/swizzle vertex-position :y) (g/swizzle vtx-time :y))
                                                  (g/* (g/swizzle vertex-position :x) (g/swizzle vtx-time :x)))
                                             (g/swizzle vertex-position :z) 0)
                                     (g/vec4 vertex-position 0 1))})

=>

attribute vec2 a_VertexPosition;
uniform vec2 u_Time;
void main(void){

gl_Position = vec4(
  a_VertexPosition.x * u_Time.y + a_VertexPosition.y * u_Time.x,
  a_VertexPosition.y * u_Time.y - a_VertexPosition.x * u_Time.x,
  a_VertexPosition.z,
  0) + vec4(a_VertexPosition, 0, 1);
}

Or changing one of the x or y (but not z or w) ops:

(def vertex-shader {v-color         vertex-color
                    (g/gl-position) (g/+
                                     (g/vec4 1
                                              ;; Could also change the g/- call below
                                             (g/- (g/* (g/swizzle vertex-position :y) (g/swizzle vtx-time :y))
                                                  (g/* (g/swizzle vertex-position :x) (g/swizzle vtx-time :x)))
                                             (g/swizzle vertex-position :z) 0)
                                     (g/vec4 vertex-position 0 1))})

=>

attribute vec4 a_VertexColor;
attribute vec2 a_VertexPosition;
uniform vec2 u_Time;
varying mediump vec4 vColor;
void main(void){

vColor = a_VertexColor;
gl_Position = vec4(
  1,
  a_VertexPosition.y * u_Time.y - a_VertexPosition.x * u_Time.x,
  a_VertexPosition.z,
  0) + vec4(a_VertexPosition, 0, 1);
}

I don't get any warnings, so it's a bit hard to track down what I'm doing wrong.

kovasb commented 9 years ago

Thanks for the detailed report. This is not a known issue. Looking into it.

kovasb commented 9 years ago

Pretty weird. Seems to be related to the size of the tree.

(def vertex-shader { (g/gl-position) (g/vec4 0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1)})

has the same problem, but works if you remove an elt from the vec4

kovasb commented 9 years ago

Ok so this was a rather stupid bug. I had forgotten I have a hard-coded recursion limit from early dev days..