如何将统一矩阵发送到 Haskell 中的着色器?
How do I send a uniform matrix to a shader in Haskell?
尝试在着色器中的顶点上进行矩阵乘法以进行变换,但是呃,没有。
目前,我得到了这个:
curMatrix <- get ((matrix $ Just $ Modelview 0)::StateVar(GLmatrix GLfloat))
mc <- getMatrixComponents ColumnMajor curMatrix
setUniform p "uModelViewMatrix" mc
setUniform 是 GLUtil 包中的一个函数。我需要将数组转换为 Vec4 (Vec4),还是有其他方法?
谢谢!
编辑:
我最终这样做了:
getMat :: [GLfloat] -> [V4 GLfloat]
getMat (a11:a12:a13:a14:
a21:a22:a23:a24:
a31:a32:a33:a34:
a41:a42:a43:a44:_) = [(V4 a11 a12 a13 a14),
(V4 a21 a22 a23 a24),
(V4 a31 a32 a33 a34),
(V4 a41 a42 a43 a44)]
嗯,这似乎没有用!
编辑 2:我所说的它不起作用的意思是,我将它设置为一个统一变量,但现在我的对象已经消失了!
Haskell 的 OpenGL 绑定(当前为 2.11.1.0)不公开统一矩阵值的函数。这已在错误跟踪器上多次报告:
- https://github.com/haskell-opengl/OpenGL/issues/68
- https://github.com/haskell-opengl/OpenGL/issues/33
- https://github.com/haskell-opengl/OpenGL/issues/14
也就是说,如果您的数据类型满足类型 Storable
的实例,例如来自 ekmett/linear, you can just use the raw pointer to the proper OpenGLRaw bindings call. See an example here 的 M44 Float
类型。
成功了!它不起作用的主要原因是因为我也没有使用投影矩阵。
请不要为了我的 bad/confusing 变量名而用棍子打我。
mvMatrix <- get ((matrix $ Just $ Modelview 0)::StateVar(GLmatrix GLfloat))
pMatrix <- get ((matrix $ Just Projection)::StateVar(GLmatrix GLfloat))
mv <- getMatrixComponents ColumnMajor mvMatrix
pm <- getMatrixComponents ColumnMajor pMatrix
let mvm = getMat mv
let pM = getMat pm
let mvmp = mvm !*! pM
setUniform p "uModelViewMatrix" mvmp
我的 getMat 函数如下:
getMat :: [GLfloat] -> V4 (V4 GLfloat)
getMat (a11:a12:a13:a14:
a21:a22:a23:a24:
a31:a32:a33:a34:
a41:a42:a43:a44:_) = V4 (V4 a11 a12 a13 a14)
(V4 a21 a22 a23 a24)
(V4 a31 a32 a33 a34)
(V4 a41 a42 a43 a44)
我正在使用线性包。 !*!
中缀函数是矩阵乘法。
这完全符合我的要求,太棒了!希望它能帮助其他人!
尝试在着色器中的顶点上进行矩阵乘法以进行变换,但是呃,没有。
目前,我得到了这个:
curMatrix <- get ((matrix $ Just $ Modelview 0)::StateVar(GLmatrix GLfloat))
mc <- getMatrixComponents ColumnMajor curMatrix
setUniform p "uModelViewMatrix" mc
setUniform 是 GLUtil 包中的一个函数。我需要将数组转换为 Vec4 (Vec4),还是有其他方法?
谢谢!
编辑:
我最终这样做了:
getMat :: [GLfloat] -> [V4 GLfloat]
getMat (a11:a12:a13:a14:
a21:a22:a23:a24:
a31:a32:a33:a34:
a41:a42:a43:a44:_) = [(V4 a11 a12 a13 a14),
(V4 a21 a22 a23 a24),
(V4 a31 a32 a33 a34),
(V4 a41 a42 a43 a44)]
嗯,这似乎没有用!
编辑 2:我所说的它不起作用的意思是,我将它设置为一个统一变量,但现在我的对象已经消失了!
Haskell 的 OpenGL 绑定(当前为 2.11.1.0)不公开统一矩阵值的函数。这已在错误跟踪器上多次报告:
- https://github.com/haskell-opengl/OpenGL/issues/68
- https://github.com/haskell-opengl/OpenGL/issues/33
- https://github.com/haskell-opengl/OpenGL/issues/14
也就是说,如果您的数据类型满足类型 Storable
的实例,例如来自 ekmett/linear, you can just use the raw pointer to the proper OpenGLRaw bindings call. See an example here 的 M44 Float
类型。
成功了!它不起作用的主要原因是因为我也没有使用投影矩阵。
请不要为了我的 bad/confusing 变量名而用棍子打我。
mvMatrix <- get ((matrix $ Just $ Modelview 0)::StateVar(GLmatrix GLfloat))
pMatrix <- get ((matrix $ Just Projection)::StateVar(GLmatrix GLfloat))
mv <- getMatrixComponents ColumnMajor mvMatrix
pm <- getMatrixComponents ColumnMajor pMatrix
let mvm = getMat mv
let pM = getMat pm
let mvmp = mvm !*! pM
setUniform p "uModelViewMatrix" mvmp
我的 getMat 函数如下:
getMat :: [GLfloat] -> V4 (V4 GLfloat)
getMat (a11:a12:a13:a14:
a21:a22:a23:a24:
a31:a32:a33:a34:
a41:a42:a43:a44:_) = V4 (V4 a11 a12 a13 a14)
(V4 a21 a22 a23 a24)
(V4 a31 a32 a33 a34)
(V4 a41 a42 a43 a44)
我正在使用线性包。 !*!
中缀函数是矩阵乘法。
这完全符合我的要求,太棒了!希望它能帮助其他人!