Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error C1008: undefined variable "translateBefore4" #18

Open
ghost opened this issue Mar 23, 2019 · 1 comment
Open

error C1008: undefined variable "translateBefore4" #18

ghost opened this issue Mar 23, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Mar 23, 2019

Compiled the following program.

makeFrame (time :: Float)
          (vertexstream :: PrimitiveStream Triangle ((Vec 4 Float)))

          = imageFrame (emptyDepthImage 1, emptyColorImage navy)
  `overlay` fragments
  where
    projmat = perspective 0.1 100.0 (30 * pi / 180) 1.0
          .*. lookat (V3 3.0 1.3 0.3) (V3 0.0 0.0 0.0) (V3 0.0 1.0 0.0)
          .*. rotMatrixY (pi / 24.0 * time)
          .*. translateBefore4 (V3 0.5 0.5 0.5)

    fragments =
          vertexstream
        & mapPrimitives (\((x)) -> (scale 0.5 (projmat *. x), x))
        & rasterizePrimitives (TriangleCtx CullNone (PolygonLine 1.0) NoOffset LastVertex) ((Smooth))
        & accumulateWith (DepthOp Less True, ColorOp NoBlending (V4 True True True True))

cube = map (\v -> V4 v%x v%y v%z 1)
    [ V3 0 0 0, V3 1 0 0, V3 0 1 0
    , V3 0 1 0, V3 1 1 0, V3 1 0 0
    , V3 0 0 0, V3 0 0 1, V3 0 1 1
    , V3 0 0 0, V3 0 1 0, V3 0 1 1
    , V3 1 0 0, V3 1 0 1, V3 1 1 1
    , V3 1 0 0, V3 1 1 0, V3 1 1 1
    , V3 0 0 0, V3 0 0 1, V3 1 0 0
    , V3 0 0 1, V3 1 0 1, V3 1 0 0
    , V3 0 1 0, V3 0 1 1, V3 1 1 0
    , V3 0 1 1, V3 1 1 1, V3 1 1 0
    , V3 0 0 1, V3 1 0 1, V3 0 1 1
    , V3 0 1 1, V3 1 1 1, V3 1 0 1
    ]

cubeStream = fetchArrays @Triangle ((cube))

main = renderFrame $
   makeFrame (Uniform "time")
             cubeStream

The generated vertex shader

#version 330 core
vec4 texture2D(sampler2D s,vec2 uv) {
    return texture(s,uv);
}
uniform float time;
in vec4 vi1;
smooth out vec4 vo1;
vec4 ext0_Float_3(vec3 z0) {
    return vec4 ((z0).x,(z0).y,(z0).z,0.0);
}
vec3 neg_VecSFloat3(vec3 z0) {
    return - (z0);
}
mat4 lookat(vec3 z0,vec3 z1,vec3 z2) {
    return (transpose (mat4 (ext0_Float_3 (normalize (cross (z2
                                                            ,normalize ((z0) - (z1)))))
                            ,ext0_Float_3 (cross (normalize ((z0) - (z1))
                                                 ,normalize (cross (z2,normalize ((z0) - (z1))))))
                            ,ext0_Float_3 (normalize ((z0) - (z1)))
                            ,vec4 (0.0,0.0,0.0,1.0)))) * (translateBefore4 (neg_VecSFloat3 (z0)));
}
mat4 perspective(float z0,float z1,float z2,float z3) {
    return mat4 (vec4 (((2.0) * (z0)) / (((z3) * ((z0) * (tan
                      ((z2) / (2.0))))) - ((0.0) - ((z3) * ((z0) * (tan ((z2) / (2.0)))))))
                      ,0.0
                      ,0.0
                      ,0.0)
                ,vec4 (0.0
                      ,((2.0) * (z0)) / (((z0) * (tan ((z2) / (2.0)))) - ((0.0) - ((z0) * (tan
                      ((z2) / (2.0))))))
                      ,0.0
                      ,0.0)
                ,vec4 ((((z3) * ((z0) * (tan ((z2) / (2.0))))) + ((0.0) - ((z3) * ((z0) * (tan
                      ((z2) / (2.0))))))) / (((z3) * ((z0) * (tan
                      ((z2) / (2.0))))) - ((0.0) - ((z3) * ((z0) * (tan ((z2) / (2.0)))))))
                      ,(((z0) * (tan ((z2) / (2.0)))) + ((0.0) - ((z0) * (tan
                      ((z2) / (2.0)))))) / (((z0) * (tan ((z2) / (2.0)))) - ((0.0) - ((z0) * (tan
                      ((z2) / (2.0))))))
                      ,(0.0) - (((z1) + (z0)) / ((z1) - (z0)))
                      ,-1.0)
                ,vec4 (0.0,0.0,(0.0) - ((((2.0) * (z1)) * (z0)) / ((z1) - (z0))),0.0));
}
mat4 rotMatrixY(float z0) {
    return mat4 (vec4 (cos (z0),0.0,(0.0) - (sin (z0)),0.0)
                ,vec4 (0.0,1.0,0.0,0.0)
                ,vec4 (sin (z0),0.0,cos (z0),0.0)
                ,vec4 (0.0,0.0,0.0,1.0));
}
vec4 scale(float z0,vec4 z1) {
    return (z1) * (vec4 (z0,z0,z0,1.0));
}
mat4 translateBefore4(vec3 z0) {
    return mat4 (vec4 (1.0,0.0,0.0,0.0)
                ,vec4 (0.0,1.0,0.0,0.0)
                ,vec4 (0.0,0.0,1.0,0.0)
                ,vec4 ((z0).x,(z0).y,(z0).z,1.0));
}
void main() {
    gl_Position = scale (0.5
                        ,((((perspective (0.1,100.0,0.5235987755982988,1.0)) * (lookat (vec3 (3.0
                                                                                             ,1.3
                                                                                             ,0.3)
                                                                                       ,vec3 (0.0,0.0,0.0)
                                                                                       ,vec3 (0.0,1.0,0.0)))) * (rotMatrixY
                        ((0.1308996938995747) * (time)))) * (translateBefore4 (vec3 (0.5
                                                                                    ,0.5
                                                                                    ,0.5)))) * (vi1));
    vo1 = vi1;
}

Manually placing translateBefore4 before lookat in the generated vertex shader resolves the issue.

@csabahruska
Copy link
Member

It seems that CoreToIR's fixFuncs function does not calculate the dependency graph correctly. Instead of a custom implementation it would be better to use Data.Graph.topSort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant