Add MatrixHelper folder
This commit is contained in:
+31
-27
@@ -1,6 +1,6 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
layout (points) in;
|
layout (points) in;
|
||||||
layout (triangle_strip, max_vertices = 12) out;
|
layout (triangle_strip, max_vertices = 11) out;
|
||||||
|
|
||||||
uniform vec2 lightPos;
|
uniform vec2 lightPos;
|
||||||
uniform mat4 perpMat;
|
uniform mat4 perpMat;
|
||||||
@@ -15,20 +15,6 @@ float isLHS (vec2 startV, vec2 testV)
|
|||||||
{
|
{
|
||||||
return sign( -startV.x * testV.y + startV.y * testV.x);
|
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
|
// construct a box with opening on bottom face
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
@@ -43,18 +29,28 @@ vec4 p5 = shift(p1);
|
|||||||
vec4 p6 = shift(p2);
|
vec4 p6 = shift(p2);
|
||||||
vec4 p7 = vec4 (p6.xy,-0.5,1);
|
vec4 p7 = vec4 (p6.xy,-0.5,1);
|
||||||
vec4 p8 = vec4 (p5.xy,-0.5,1);
|
vec4 p8 = vec4 (p5.xy,-0.5,1);
|
||||||
gl_Position = perpMat * p4; EmitVertex();
|
|
||||||
gl_Position = perpMat * p3; EmitVertex();
|
vec4 a1 = perpMat * p1;
|
||||||
gl_Position = perpMat * p7; EmitVertex();
|
vec4 a2 = perpMat * p2;
|
||||||
gl_Position = perpMat * p8; EmitVertex();
|
vec4 a3 = perpMat * p3;
|
||||||
gl_Position = perpMat * p5; EmitVertex();
|
vec4 a4 = perpMat * p4;
|
||||||
gl_Position = perpMat * p3; EmitVertex();
|
vec4 a5 = perpMat * p5;
|
||||||
gl_Position = perpMat * p1; EmitVertex();
|
vec4 a6 = perpMat * p6;
|
||||||
gl_Position = perpMat * p4; EmitVertex();
|
vec4 a7 = perpMat * p7;
|
||||||
gl_Position = perpMat * p2; EmitVertex();
|
vec4 a8 = perpMat * p8;
|
||||||
gl_Position = perpMat * p7; EmitVertex();
|
|
||||||
gl_Position = perpMat * p6; EmitVertex();
|
gl_Position = a4; EmitVertex();
|
||||||
gl_Position = perpMat * p5; 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();
|
EndPrimitive();
|
||||||
} else {}
|
} else {}
|
||||||
}
|
}
|
||||||
@@ -82,3 +78,11 @@ vec4 p8 = vec4 (p5.xy,-0.5,1);
|
|||||||
// gl_Position = perspective * worldMat * p7; EmitVertex();
|
// gl_Position = perspective * worldMat * p7; EmitVertex();
|
||||||
// gl_Position = perspective * worldMat * p6; EmitVertex();
|
// gl_Position = perspective * worldMat * p6; EmitVertex();
|
||||||
// gl_Position = perspective * worldMat * p5; 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();
|
||||||
|
//}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -76,10 +76,12 @@ renderPicture' pdata rot zoom (tranx,trany) (winx,winy) wallPoints lightPoints
|
|||||||
) :: IO (GLmatrix GLfloat)
|
) :: IO (GLmatrix GLfloat)
|
||||||
uniform ( (fromJust $ _shaderCustomUnis $ _wallShadowShader pdata) !! 1)
|
uniform ( (fromJust $ _shaderCustomUnis $ _wallShadowShader pdata) !! 1)
|
||||||
$= pmat
|
$= pmat
|
||||||
|
cullFace $= Just Back
|
||||||
drawShader (_wallShadowShader pdata) nWalls
|
drawShader (_wallShadowShader pdata) nWalls
|
||||||
|
|
||||||
depthMask $= Disabled
|
depthMask $= Disabled
|
||||||
blendFuncSeparate $= ((Zero,Zero),(Zero, OneMinusSrcAlpha))
|
blendFunc $= (Zero, OneMinusSrcAlpha)
|
||||||
|
-- blendFuncSeparate $= ((Zero,Zero),(Zero, OneMinusSrcAlpha))
|
||||||
stencilTest $= Enabled
|
stencilTest $= Enabled
|
||||||
forM_ lightPoints $ \(x,y,r,lum) -> do
|
forM_ lightPoints $ \(x,y,r,lum) -> do
|
||||||
-- depthFunc $= Just Less
|
-- 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 does get called twice: here and inside drawShader below
|
||||||
currentProgram $= Just (_shaderProgram $ _wallShadowShader pdata)
|
currentProgram $= Just (_shaderProgram $ _wallShadowShader pdata)
|
||||||
uniform (head $ fromJust $ _shaderCustomUnis $ _wallShadowShader pdata)
|
uniform (head $ fromJust $ _shaderCustomUnis $ _wallShadowShader pdata)
|
||||||
$= Vector2 (x) (y)
|
$= Vector2 x y
|
||||||
-- blendFunc $= (Zero,One)
|
-- blendFunc $= (Zero,One)
|
||||||
drawShader (_wallShadowShader pdata) nWalls
|
drawShader (_wallShadowShader pdata) nWalls
|
||||||
|
|
||||||
cullFace $= Just Front
|
-- cullFace $= Just Front
|
||||||
stencilOp $= (OpKeep,OpKeep,OpDecr)
|
-- stencilOp $= (OpKeep,OpKeep,OpDecr)
|
||||||
drawShader (_wallShadowShader pdata) nWalls
|
-- drawShader (_wallShadowShader pdata) nWalls
|
||||||
|
|
||||||
cullFace $= Nothing
|
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)
|
zTran (a,b) = (a*2*zoom / winx, b*2*zoom / winy)
|
||||||
pokeFourOff lightPtr 0 (x',y',r,lum)
|
pokeFourOff lightPtr 0 (x',y',r,lum)
|
||||||
bindShaderBuffers [_lightSourceShader pdata] [1]
|
bindShaderBuffers [_lightSourceShader pdata] [1]
|
||||||
|
|
||||||
stencilFunc $= (Equal, 0, 255)
|
stencilFunc $= (Equal, 0, 255)
|
||||||
-- depthFunc $= Just Always
|
|
||||||
drawShader (_lightSourceShader pdata) 1
|
drawShader (_lightSourceShader pdata) 1
|
||||||
|
|
||||||
-- currentProgram $= Just (_shaderProgram $ _wallLightShader pdata)
|
-- currentProgram $= Just (_shaderProgram $ _wallLightShader pdata)
|
||||||
|
|||||||
Reference in New Issue
Block a user