lambdacube3d / lambdacube-compiler

LambdaCube 3D is a Haskell-like purely functional language for GPU. Try it out:
http://lambdacube3d.com
Other
86 stars 9 forks source link

Question: pass several vertex attributes to rasterizePrimitives #2

Closed NCrashed closed 8 years ago

NCrashed commented 8 years ago

Hi, I cannot find example with several attributes passed to fragment shader. All my own attempts failed.

Could you give modified Cube.lc example where, for instance, normals are passed to fragment shader along with color info?

csabahruska commented 8 years ago

Due to a type inference bug in the 0.4 release the fragment shader type must be explicitly written. It will be fixed in the following releases. (in the 0.7 release we plan to represent tuples as heterogeneous lists, which will fix the problem) The following code passes the position and uv coordinates to the fragment shader:

makeFrame (projmat :: Mat 4 4 Float)
          (vertexstream :: PrimitiveStream Triangle (Vec 4 Float,Vec 2 Float))

          = imageFrame (emptyDepthImage 1, emptyColorImage navy)
  `overlay` fragments
  where
    fragments =
          vertexstream
        & mapPrimitives (\(x,uv) -> (scale 0.5 (projmat *. x), x, uv))
        & rasterizePrimitives (TriangleCtx CullNone PolygonFill NoOffset LastVertex) (Smooth,Smooth)
        & mapFragments ((\(x,uv) -> x) :: (Vec 4 Float,Vec 2 Float) -> Vec 4 Float)
        & accumulateWith (DepthOp Less True, ColorOp NoBlending (V4 True True True True))

main = renderFrame $
   makeFrame (Uniform "MVP")
             (fetch_ "stream4" (Attribute "position4", Attribute "vertexUV"))
NCrashed commented 8 years ago

Thank you! That saved my day.