Add MatrixHelper folder

This commit is contained in:
jgk
2021-03-19 21:54:34 +01:00
parent bd7a5c3533
commit 598061d277
3 changed files with 81 additions and 34 deletions
+31 -27
View File
@@ -1,6 +1,6 @@
#version 430 core
layout (points) in;
layout (triangle_strip, max_vertices = 12) out;
layout (triangle_strip, max_vertices = 11) out;
uniform vec2 lightPos;
uniform mat4 perpMat;
@@ -15,20 +15,6 @@ float isLHS (vec2 startV, vec2 testV)
{
return sign( -startV.x * testV.y + startV.y * testV.x);
}
void emitLine (vec2 pa)
{
gl_Position = vec4 (pa, 0, 1);
EmitVertex();
gl_Position = shift (vec4 (pa,0,1)); //vec4 (pa + (200 * (pa - lightPosa)), 0 , 1);
EmitVertex();
}
mat4 perspective =
mat4 (1,0,0,0
,0,1,0,0
,0,0,1,1
,0,0,0,1
) ;
// construct a box with opening on bottom face
void main()
@@ -43,18 +29,28 @@ vec4 p5 = shift(p1);
vec4 p6 = shift(p2);
vec4 p7 = vec4 (p6.xy,-0.5,1);
vec4 p8 = vec4 (p5.xy,-0.5,1);
gl_Position = perpMat * p4; EmitVertex();
gl_Position = perpMat * p3; EmitVertex();
gl_Position = perpMat * p7; EmitVertex();
gl_Position = perpMat * p8; EmitVertex();
gl_Position = perpMat * p5; EmitVertex();
gl_Position = perpMat * p3; EmitVertex();
gl_Position = perpMat * p1; EmitVertex();
gl_Position = perpMat * p4; EmitVertex();
gl_Position = perpMat * p2; EmitVertex();
gl_Position = perpMat * p7; EmitVertex();
gl_Position = perpMat * p6; EmitVertex();
gl_Position = perpMat * p5; EmitVertex();
vec4 a1 = perpMat * p1;
vec4 a2 = perpMat * p2;
vec4 a3 = perpMat * p3;
vec4 a4 = perpMat * p4;
vec4 a5 = perpMat * p5;
vec4 a6 = perpMat * p6;
vec4 a7 = perpMat * p7;
vec4 a8 = perpMat * p8;
gl_Position = a4; EmitVertex();
gl_Position = a3; EmitVertex();
gl_Position = a7; EmitVertex();
gl_Position = a8; EmitVertex();
gl_Position = a5; EmitVertex();
gl_Position = a3; EmitVertex();
gl_Position = a1; EmitVertex();
gl_Position = a4; EmitVertex();
gl_Position = a2; EmitVertex();
gl_Position = a7; EmitVertex();
gl_Position = a6; EmitVertex();
// gl_Position = a5; EmitVertex();
EndPrimitive();
} else {}
}
@@ -82,3 +78,11 @@ vec4 p8 = vec4 (p5.xy,-0.5,1);
// gl_Position = perspective * worldMat * p7; EmitVertex();
// gl_Position = perspective * worldMat * p6; EmitVertex();
// gl_Position = perspective * worldMat * p5; EmitVertex();
//void emitLine (vec2 pa)
//{
// gl_Position = vec4 (pa, 0, 1);
// EmitVertex();
// gl_Position = shift (vec4 (pa,0,1)); //vec4 (pa + (200 * (pa - lightPosa)), 0 , 1);
// EmitVertex();
//}
+43
View File
@@ -0,0 +1,43 @@
module MatrixHelper
where
import Geometry
import Linear.Matrix
import Linear.V4
import Graphics.Rendering.OpenGL (GLfloat)
perspectiveMatrix :: Float -> Float -> Point2 -> Point2 -> Point2 -> [GLfloat]
perspectiveMatrix rot zoom (tranx,trany) (winx,winy) (viewFromx,viewFromy) =
let scalMat = Linear.Matrix.transpose $
V4 (V4 (2*zoom/winx) 0 0 (0::GLfloat))
(V4 0 (2*zoom/winy) 0 0)
(V4 0 0 1 0)
(V4 0 0 0 1)
rotMat = Linear.Matrix.transpose $
V4 (V4 (cos rot) (sin (-rot)) 0 0)
(V4 (sin rot) (cos rot) 0 0)
(V4 0 0 1 0)
(V4 0 0 0 1)
tranMat3 = Linear.Matrix.transpose $
V4 (V4 1 0 0 0)
(V4 0 1 0 0)
(V4 0 0 1 0)
(V4 (-tranx) (-trany) 0 1)
tranMat2 = Linear.Matrix.transpose $
V4 (V4 1 0 0 0)
(V4 0 1 0 0)
(V4 0 0 1 0)
(V4 (viewFromx-tranx) (viewFromy-trany) 0 1)
perMat = Linear.Matrix.transpose $
V4 (V4 1 0 0 0)
(V4 0 1 0 0)
(V4 0 0 1 1)
(V4 0 0 0 1)
tranMat1 = Linear.Matrix.transpose $
V4 (V4 1 0 0 0)
(V4 0 1 0 0)
(V4 0 0 1 0)
(V4 (-viewFromx) (-viewFromy) 0 1)
wmat = scalMat !*! rotMat !*! tranMat2 !*! perMat !*! tranMat1
vToL (V4 a b c d) = [a,b,c,d]
in concatMap vToL $ vToL wmat
+7 -7
View File
@@ -76,10 +76,12 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints
) :: IO (GLmatrix GLfloat)
uniform ( (fromJust $ _shaderCustomUnis $ _wallShadowShader pdata) !! 1)
$= pmat
cullFace $= Just Back
drawShader (_wallShadowShader pdata) nWalls
depthMask $= Disabled
blendFuncSeparate $= ((Zero,Zero),(Zero, OneMinusSrcAlpha))
blendFunc $= (Zero, OneMinusSrcAlpha)
-- blendFuncSeparate $= ((Zero,Zero),(Zero, OneMinusSrcAlpha))
stencilTest $= Enabled
forM_ lightPoints $ \(x,y,r,lum) -> do
-- depthFunc $= Just Less
@@ -91,13 +93,13 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints
-- currentProgram does get called twice: here and inside drawShader below
currentProgram $= Just (_shaderProgram $ _wallShadowShader pdata)
uniform (head $ fromJust $ _shaderCustomUnis $ _wallShadowShader pdata)
$= Vector2 (x) (y)
$= Vector2 x y
-- blendFunc $= (Zero,One)
drawShader (_wallShadowShader pdata) nWalls
cullFace $= Just Front
stencilOp $= (OpKeep,OpKeep,OpDecr)
drawShader (_wallShadowShader pdata) nWalls
-- cullFace $= Just Front
-- stencilOp $= (OpKeep,OpKeep,OpDecr)
-- drawShader (_wallShadowShader pdata) nWalls
cullFace $= Nothing
@@ -107,9 +109,7 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints
zTran (a,b) = (a*2*zoom / winx, b*2*zoom / winy)
pokeFourOff lightPtr 0 (x',y',r,lum)
bindShaderBuffers [_lightSourceShader pdata] [1]
stencilFunc $= (Equal, 0, 255)
-- depthFunc $= Just Always
drawShader (_lightSourceShader pdata) 1
-- currentProgram $= Just (_shaderProgram $ _wallLightShader pdata)