From 581cb142bb0a34a586f4d47de13fca0c3bffba10 Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Sun, 24 Aug 2014 23:47:17 +0200 Subject: [PATCH] added shading, reduced debug-output --- models/holzfaellerHaus1.iqm | Bin 0 -> 12824 bytes sample.iqm | Bin 3104 -> 0 bytes shaders/mapobjects/fragment.shader | 13 ++++++++++++- shaders/mapobjects/vertex.shader | 5 +++-- src/Importer/IQM/Parser.hs | 14 +++++++------- src/Render/Render.hs | 11 ++++++----- 6 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 models/holzfaellerHaus1.iqm delete mode 100644 sample.iqm diff --git a/models/holzfaellerHaus1.iqm b/models/holzfaellerHaus1.iqm new file mode 100644 index 0000000000000000000000000000000000000000..f24cc3cf40b76cab2892d07237b704738a7b53be GIT binary patch literal 12824 zcmeHN3v^9a8or4~sB}b-c$atu^{QNiXFFNj=t$s+qJBkG}NrFF;g8%pUZ2$@0`7po#VzmnXWaf*0^hZ`M>Y~|NZZO z?|WWJPV(@yL8C^d4;VUV*ofN)rMQA!E?1M=@B^Pv;7K3|$N_2tdx4F>SYSmbm#es| z6+hJzj_Q6AvnEb<4a}S|*{Y$2a}Ituhx&wo)Bu{G8TP{ueeCyOUCSyT^On`O@|CY9 zNZ%$d7cD=mLH>SQm#Y>X_$c4D4)l4&mW+-GpBzf@>`prFxmeU8VMEQ)g8t3$=brZp z-LH77iC(`s^e-KH+>=_jW5UV2$~hOWWE%x?F7lnS{<@^&CBenkygK)n!}=+6ZQe@{o$#r3bxNHn)Ve-TOch74-e1rIa$>H)+IyR{q@WkaGKW1gN8c;e18eGI z)&AK1%=x<&pOW5nMejDl6*Q?K~ z`}I2dym}p-rzbV?G#j!}+~>Pb=wsJzYF^S@`t`Z&e$^ZOjRuA%*z2%&Y2+MwZDGPUuxBN2bvVUSRUOWy?l1bh zthobowLTGI-oMnnF9i3ySEZjkSN5ad2VL;<{;BR4>RQblb$!iLWpB}$JitLp4j*Fw;fmOIF~WN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E9ti|uxu zN2O^gI1}4}&JJm(6x=1n?v@^t_Qd#jY||Tk&?mjn7lKWF_z-$#CUEJAd&HjyJ#$Y^ zX22aMHnGfz{N!X#%!hm4VIJJ$V^+js<0mgZ=0+XZ%#Awmk&FD;_}yH|#T^{t$wl5s z^6~3CJGRtgi{lT%so~Gd6X{lqP77E5Pw`tVS>l~U(TsgOI6ePz^3}P?pEF@!UH|zH J&ps{r{NI61n*#s< diff --git a/shaders/mapobjects/fragment.shader b/shaders/mapobjects/fragment.shader index 6c05c3a..b95f268 100644 --- a/shaders/mapobjects/fragment.shader +++ b/shaders/mapobjects/fragment.shader @@ -5,6 +5,17 @@ in vec3 vNormal; out vec4 fgColor; +uniform mat4 ViewMatrix; + void main () { - fgColor = vec4(1.0,0.0,1.0,0.5); + //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(vNormal, lightDir); + float a = costheta * 0.5 + 0.5; + + fgColor = vec4(0.5,0.5,0.5,1)*mix(dark,light,a); } diff --git a/shaders/mapobjects/vertex.shader b/shaders/mapobjects/vertex.shader index ff05a30..fb092dc 100644 --- a/shaders/mapobjects/vertex.shader +++ b/shaders/mapobjects/vertex.shader @@ -6,7 +6,7 @@ layout(location=2) in vec2 TexCoord; uniform mat4 ProjectionMatrix; uniform mat4 ViewMatrix; uniform mat3 NormalMatrix; -uniform vec3 PositionOffset = vec3(5,5,5); +uniform vec3 PositionOffset = vec3(5,2,5); uniform float TessLevelInner = 1.0; // controlled by keyboard buttons uniform float TessLevelOuter = 1.0; // controlled by keyboard buttons @@ -15,6 +15,7 @@ out vec3 vNormal; void main () { vPosition = Position; - gl_Position = vec4(Position,1);//ProjectionMatrix * ViewMatrix * vec4(PositionOffset + Position, 1); + //gl_Position = vec4(Position,1); + gl_Position = ProjectionMatrix * ViewMatrix * vec4(PositionOffset + Position, 1); vNormal = Normal; } diff --git a/src/Importer/IQM/Parser.hs b/src/Importer/IQM/Parser.hs index 8a98ab2..e000429 100644 --- a/src/Importer/IQM/Parser.hs +++ b/src/Importer/IQM/Parser.hs @@ -259,9 +259,9 @@ parseIQM a = bufferData ElementArrayBuffer $= (fromIntegral byteLen, p, StaticDraw) checkError "bufferData tris" return $ castPtr p - putStrLn "Triangles:" - printPtrAsWord32Array tris ((*3).fromIntegral.num_triangles.bareheader $ bare) 3 - print bare + --putStrLn "Triangles:" + --printPtrAsWord32Array tris ((*3).fromIntegral.num_triangles.bareheader $ bare) 3 + --print bare return $ IQM { header = bareheader bare , texts = baretexts bare @@ -275,14 +275,14 @@ parseIQM a = createVAO :: [(IQMVertexArray, BufferObject)] -> IO () createVAO bo = do - print bo + --print bo initVAO (AttribLocation 0) IQMPosition bo initVAO (AttribLocation 1) IQMNormal bo initVAO (AttribLocation 2) IQMTexCoord bo initVAO :: AttribLocation -> IQMVertexArrayType -> [(IQMVertexArray, BufferObject)] -> IO () initVAO l t bo = do - print $ concat ["adding ", show t, " to vertexBufferObject"] + --print $ concat ["adding ", show t, " to vertexBufferObject"] let (IQMVertexArray _ _ _ num _ _,buf) = case filter (\(IQMVertexArray ty _ _ _ _ _, _) -> ty == t) bo of [(a,b)] -> (a,b) _ -> error "IQM-Object not render-able with current shader-mechanics" @@ -325,11 +325,11 @@ readInVAO d vcount (IQMVertexArray type' a format num offset ptr) = putStrLn $ concat ["Allocating ", show vcount ,"x", show num,"x",show (vaSize format)," = ", show byteLen, " Bytes at ", show p, " for ", show type'] putStrLn $ concat ["Filling starting at ", show offset, " with: "] unsafeUseAsCString data' (\s -> copyBytes p s byteLen) - case type' of + {-case type' of IQMBlendIndexes -> printPtrAsUByteArray p numElems 4 IQMBlendWeights -> printPtrAsUByteArray p numElems 4 IQMTexCoord -> printPtrAsFloatArray p numElems 2 - _ -> printPtrAsFloatArray p numElems 3 + _ -> printPtrAsFloatArray p numElems 3-} return $ IQMVertexArray type' a format num offset $ castPtr p -- | Real internal Parser. diff --git a/src/Render/Render.hs b/src/Render/Render.hs index 17aff76..be4f216 100644 --- a/src/Render/Render.hs +++ b/src/Render/Render.hs @@ -180,7 +180,7 @@ initMapShader tessFac (buf, vertDes) = do putStrLn $ unlines $ "Model-Uniforms: ":map show uni' putStrLn $ unlines $ ["Model-Indices: ", show (texIndex', normalIndex', vertexIndex')] - testobj <- parseIQM "models/box.iqm" + testobj <- parseIQM "models/holzfaellerHaus1.iqm" let objs = [MapObject testobj (L.V3 0 10 0) (MapObjectState ())] currentProgram $= Nothing @@ -288,10 +288,11 @@ renderIQM :: IQM -> L.V3 CFloat -> L.V3 CFloat -> IO () renderIQM m p@(L.V3 x y z) s@(L.V3 sx sy sz) = do withVAO (vertexArrayObject m) $ do vertexAttribArray (AttribLocation 0) $= Enabled + vertexAttribArray (AttribLocation 1) $= Enabled checkError "setting array to enabled" bindBuffer ElementArrayBuffer $= Just (triangleBufferObject m) checkError "bindBuffer" - let n = fromIntegral.num_triangles.header $ m + let n = fromIntegral.(*3).num_triangles.header $ m --print $ concat ["drawing ", show n," triangles"] drawElements Triangles n UnsignedInt nullPtr checkError "drawing model" @@ -332,7 +333,7 @@ drawMap = do glPatchParameteri gl_PATCH_VERTICES 3 - cullFace $= Nothing --Just Front + cullFace $= Just Front polygonMode $= (Fill,Fill) glDrawArrays gl_PATCHES 0 (fromIntegral numVert) @@ -491,11 +492,11 @@ render = do currentProgram $= Just (state ^. gl.glMap.objectProgram) checkError "setting up shadowmap-program" --set up projection (= copy from state) - {-mat44ToGPU frust projmo "mapObjects-projection" + mat44ToGPU frust projmo "mapObjects-projection" --set up camera mat44ToGPU cam' vmatmo "mapObjects-cam" --set up normal - mat33ToGPU nmap nmatmo "mapObjects-nmat"-} + mat33ToGPU nmap nmatmo "mapObjects-nmat" mapM_ renderObject (state ^. gl.glMap.mapObjects) checkError "draw mapobjects"