tessellationgit status

This commit is contained in:
Nicole Dresselhaus 2014-01-21 16:18:48 +01:00
parent d37409a54e
commit 3b8d3f8f9e
5 changed files with 75 additions and 42 deletions

24
deps/getDeps.sh vendored
View File

@ -26,8 +26,27 @@ then
wget http://de.archive.ubuntu.com/ubuntu/pool/universe/libs/libsdl2/libsdl2-dbg_2.0.1+dfsg1-1ubuntu1_amd64.deb
sudo gdebi libsdl2-dbg_2.0.1+dfsg1-1ubuntu1_amd64.deb
fi
if [ ! -f "libsdl2-ttf-2.0-0_2.0.12+dfsg1-2_amd64.deb" ]
then
wget http://de.archive.ubuntu.com/ubuntu/pool/universe/libs/libsdl2-ttf/libsdl2-ttf-2.0-0_2.0.12+dfsg1-2_amd64.deb
sudo gdebi libsdl2-ttf-2.0-0_2.0.12+dfsg1-2_amd64.deb
fi
if [ ! -f "libsdl2-ttf-dev_2.0.12+dfsg1-2_amd64.deb" ]
then
wget http://de.archive.ubuntu.com/ubuntu/pool/universe/libs/libsdl2-ttf/libsdl2-ttf-dev_2.0.12+dfsg1-2_amd64.deb
sudo gdebi libsdl2-ttf-dev_2.0.12+dfsg1-2_amd64.deb
fi
if [ ! -f "libsdl2-image-2.0-0_2.0.0+dfsg-3_amd64.deb" ]
then
wget http://de.archive.ubuntu.com/ubuntu/pool/universe/libs/libsdl2-image/libsdl2-image-2.0-0_2.0.0+dfsg-3_amd64.deb
sudo gdebi libsdl2-image-2.0-0_2.0.0+dfsg-3_amd64.deb
fi
if [ ! -f "libsdl2-image-dev_2.0.0+dfsg-3_amd64.deb" ]
then
wget http://de.archive.ubuntu.com/ubuntu/pool/universe/libs/libsdl2-image/libsdl2-image-dev_2.0.0+dfsg-3_amd64.deb
sudo gdebi libsdl2-image-dev_2.0.0+dfsg-3_amd64.deb
fi
fi
## hack end
echo "cloning repositories"
@ -41,6 +60,9 @@ else
fi
echo "trying to build"
cabal install haddock
for d in `find . -maxdepth 1 -type d`
do
if [ "$d" == "." ]

View File

@ -1,12 +1,23 @@
#version 330
#version 400
//color from earlier stages
smooth in vec4 fg_SmoothColor;
smooth in vec3 teNormal;
in vec4 teColor;
out vec4 fg_FragColor;
out vec4 fgColor;
uniform mat4 ViewMatrix;
void main(void)
{
//copy-shader
fg_FragColor = fg_SmoothColor;
//heliospheric lighting
vec4 light = vec4(1.0,1.0,1.0,1.0);
vec4 dark = vec4(0.0,0.0,0.0,1.0);
//direction to sun from origin
vec3 lightDir = normalize(ViewMatrix * vec4(5.0,5.0,1.0,0.0)).xyz;
float costheta = dot(teNormal, lightDir);
float a = costheta * 0.5 + 0.5;
fgColor = teColor * mix(dark, light, a);
}

View File

@ -1,32 +1,18 @@
#version 330
//constant projection matrix
uniform mat4 fg_ProjectionMatrix;
uniform mat4 fg_ViewMatrix;
uniform mat3 fg_NormalMatrix;
#version 400
//vertex-data
in vec4 fg_Color;
in vec3 fg_VertexIn;
in vec3 fg_NormalIn;
in vec4 Color;
in vec3 Position;
in vec3 Normal;
//output-data for later stages
smooth out vec4 fg_SmoothColor;
out vec4 vColor;
out vec3 vPosition;
out vec3 vNormal;
void main()
{
vec3 fg_Normal = fg_NormalMatrix * fg_NormalIn; //vec3(0,1,0);
//transform vec3 into vec4, setting w to 1
vec4 fg_Vertex = vec4(fg_VertexIn, 1.0);
vec4 light = vec4(1.0,1.0,1.0,1.0);
vec4 dark = vec4(0.0,0.0,0.0,1.0);
//direction to sun from origin
vec3 lightDir = normalize(fg_ViewMatrix * vec4(5.0,5.0,1.0,0.0)).xyz;
float costheta = dot(normalize(fg_Normal), lightDir);
float a = costheta * 0.5 + 0.5;
fg_SmoothColor = fg_Color * mix(dark, light, a);// + 0.001* fg_Normal.xyzx;
gl_Position = fg_ProjectionMatrix * fg_ViewMatrix * fg_Vertex;
vPosition = Position;
vNormal = Normal;
vColor = Color;
}

View File

@ -35,6 +35,7 @@ import qualified Graphics.Rendering.OpenGL.GL as GL
import Graphics.Rendering.OpenGL.Raw.Core31
import Data.Time (getCurrentTime, UTCTime, diffUTCTime)
import Graphics.Rendering.OpenGL.Raw.ARB.TessellationShader
-- Our modules
import Map.Map
import Render.Misc (checkError,
@ -122,8 +123,8 @@ main = do
now <- getCurrentTime
putStrLn "foo"
let zDistClosest = 10
zDistFarthest = zDistClosest + 20
let zDistClosest = 1
zDistFarthest = zDistClosest + 30
fov = 90 --field of view
near = 1 --near plane
far = 100 --far plane
@ -232,7 +233,10 @@ draw = do
GL.vertexAttribArray vi GL.$= GL.Enabled
checkError "beforeDraw"
GL.drawArrays GL.Triangles 0 numVert
glPatchParameteri gl_PATCH_VERTICES 3
glPolygonMode gl_FRONT gl_LINE
glDrawArrays gl_PATCHES 0 (fromIntegral numVert)
checkError "draw"

View File

@ -18,6 +18,10 @@ import Render.Misc
vertexShaderFile :: String
vertexShaderFile = "shaders/vertex.shader"
tessControlShaderFile :: String
tessControlShaderFile = "shaders/tessControl.shader"
tessEvalShaderFile :: String
tessEvalShaderFile = "shaders/tessEval.shader"
fragmentShaderFile :: String
fragmentShaderFile = "shaders/fragment.shader"
@ -45,37 +49,43 @@ initShader :: IO (
)
initShader = do
! vertexSource <- B.readFile vertexShaderFile
! tessControlSource <- B.readFile tessControlShaderFile
! tessEvalSource <- B.readFile tessEvalShaderFile
! fragmentSource <- B.readFile fragmentShaderFile
vertexShader <- compileShaderSource VertexShader vertexSource
checkError "compile Vertex"
tessControlShader <- compileShaderSource TessControlShader tessControlSource
checkError "compile Vertex"
tessEvalShader <- compileShaderSource TessEvaluationShader tessEvalSource
checkError "compile Vertex"
fragmentShader <- compileShaderSource FragmentShader fragmentSource
checkError "compile Frag"
program <- createProgramUsing [vertexShader, fragmentShader]
program <- createProgramUsing [vertexShader, tessControlShader, tessEvalShader, fragmentShader]
checkError "compile Program"
currentProgram $= Just program
projectionMatrixIndex <- get (uniformLocation program "fg_ProjectionMatrix")
projectionMatrixIndex <- get (uniformLocation program "ProjectionMatrix")
checkError "projMat"
viewMatrixIndex <- get (uniformLocation program "fg_ViewMatrix")
viewMatrixIndex <- get (uniformLocation program "ViewMatrix")
checkError "viewMat"
modelMatrixIndex <- get (uniformLocation program "fg_ModelMatrix")
modelMatrixIndex <- get (uniformLocation program "ModelMatrix")
checkError "modelMat"
normalMatrixIndex <- get (uniformLocation program "fg_NormalMatrix")
normalMatrixIndex <- get (uniformLocation program "NormalMatrix")
checkError "normalMat"
vertexIndex <- get (attribLocation program "fg_VertexIn")
vertexIndex <- get (attribLocation program "Position")
vertexAttribArray vertexIndex $= Enabled
checkError "vertexInd"
normalIndex <- get (attribLocation program "fg_NormalIn")
normalIndex <- get (attribLocation program "Normal")
vertexAttribArray normalIndex $= Enabled
checkError "normalInd"
colorIndex <- get (attribLocation program "fg_Color")
colorIndex <- get (attribLocation program "Color")
vertexAttribArray colorIndex $= Enabled
checkError "colorInd"