added shading, reduced debug-output
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								models/holzfaellerHaus1.iqm
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								models/holzfaellerHaus1.iqm
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								sample.iqm
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								sample.iqm
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -5,6 +5,17 @@ in vec3 vNormal; | |||||||
|  |  | ||||||
| out vec4 fgColor; | out vec4 fgColor; | ||||||
|  |  | ||||||
|  | uniform mat4 ViewMatrix; | ||||||
|  |  | ||||||
| void main () { | 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); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,7 +6,7 @@ layout(location=2) in vec2 TexCoord; | |||||||
| uniform mat4 ProjectionMatrix; | uniform mat4 ProjectionMatrix; | ||||||
| uniform mat4 ViewMatrix; | uniform mat4 ViewMatrix; | ||||||
| uniform mat3 NormalMatrix; | 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 TessLevelInner = 1.0; // controlled by keyboard buttons | ||||||
| uniform float TessLevelOuter = 1.0; // controlled by keyboard buttons | uniform float TessLevelOuter = 1.0; // controlled by keyboard buttons | ||||||
|  |  | ||||||
| @@ -15,6 +15,7 @@ out vec3 vNormal; | |||||||
|  |  | ||||||
| void main () { | void main () { | ||||||
|    vPosition = Position; |    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; |    vNormal = Normal; | ||||||
| } | } | ||||||
|   | |||||||
| @@ -259,9 +259,9 @@ parseIQM a = | |||||||
|             bufferData ElementArrayBuffer $= (fromIntegral byteLen, p, StaticDraw) |             bufferData ElementArrayBuffer $= (fromIntegral byteLen, p, StaticDraw) | ||||||
|         checkError "bufferData tris" |         checkError "bufferData tris" | ||||||
|         return $ castPtr p |         return $ castPtr p | ||||||
|     putStrLn "Triangles:" |     --putStrLn "Triangles:" | ||||||
|     printPtrAsWord32Array tris ((*3).fromIntegral.num_triangles.bareheader $ bare) 3 |     --printPtrAsWord32Array tris ((*3).fromIntegral.num_triangles.bareheader $ bare) 3 | ||||||
|     print bare |     --print bare | ||||||
|     return $ IQM |     return $ IQM | ||||||
|         { header               = bareheader bare |         { header               = bareheader bare | ||||||
|         , texts                = baretexts bare |         , texts                = baretexts bare | ||||||
| @@ -275,14 +275,14 @@ parseIQM a = | |||||||
|  |  | ||||||
| createVAO :: [(IQMVertexArray, BufferObject)] -> IO () | createVAO :: [(IQMVertexArray, BufferObject)] -> IO () | ||||||
| createVAO bo = do | createVAO bo = do | ||||||
|         print bo |         --print bo | ||||||
|         initVAO (AttribLocation 0) IQMPosition bo |         initVAO (AttribLocation 0) IQMPosition bo | ||||||
|         initVAO (AttribLocation 1) IQMNormal   bo |         initVAO (AttribLocation 1) IQMNormal   bo | ||||||
|         initVAO (AttribLocation 2) IQMTexCoord bo |         initVAO (AttribLocation 2) IQMTexCoord bo | ||||||
|  |  | ||||||
| initVAO :: AttribLocation -> IQMVertexArrayType -> [(IQMVertexArray, BufferObject)] -> IO () | initVAO :: AttribLocation -> IQMVertexArrayType -> [(IQMVertexArray, BufferObject)] -> IO () | ||||||
| initVAO l t bo = do | 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 | 	let (IQMVertexArray _ _ _ num _ _,buf) = case filter (\(IQMVertexArray ty _ _ _ _ _, _) -> ty == t) bo of | ||||||
| 							[(a,b)] -> (a,b) | 							[(a,b)] -> (a,b) | ||||||
| 							_ -> error "IQM-Object not render-able with current shader-mechanics" | 							_ -> 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 ["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: "] |         putStrLn $ concat ["Filling starting at ", show offset, " with: "] | ||||||
|         unsafeUseAsCString data' (\s -> copyBytes p s byteLen) |         unsafeUseAsCString data' (\s -> copyBytes p s byteLen) | ||||||
|         case type' of |         {-case type' of | ||||||
|             IQMBlendIndexes -> printPtrAsUByteArray p numElems 4 |             IQMBlendIndexes -> printPtrAsUByteArray p numElems 4 | ||||||
|             IQMBlendWeights -> printPtrAsUByteArray p numElems 4 |             IQMBlendWeights -> printPtrAsUByteArray p numElems 4 | ||||||
|             IQMTexCoord     -> printPtrAsFloatArray p numElems 2 |             IQMTexCoord     -> printPtrAsFloatArray p numElems 2 | ||||||
|             _ -> printPtrAsFloatArray p numElems 3 |             _ -> printPtrAsFloatArray p numElems 3-} | ||||||
|         return $ IQMVertexArray type' a format num offset $ castPtr p |         return $ IQMVertexArray type' a format num offset $ castPtr p | ||||||
|  |  | ||||||
| -- | Real internal Parser. | -- | Real internal Parser. | ||||||
|   | |||||||
| @@ -180,7 +180,7 @@ initMapShader tessFac (buf, vertDes) = do | |||||||
|    putStrLn $ unlines $ "Model-Uniforms: ":map show uni' |    putStrLn $ unlines $ "Model-Uniforms: ":map show uni' | ||||||
|    putStrLn $ unlines $ ["Model-Indices: ", show (texIndex', normalIndex', vertexIndex')] |    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 ())] |    let objs = [MapObject testobj (L.V3 0 10 0) (MapObjectState ())] | ||||||
|  |  | ||||||
|    currentProgram $= Nothing |    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 | renderIQM m p@(L.V3 x y z) s@(L.V3 sx sy sz) = do | ||||||
|     withVAO (vertexArrayObject m) $ do |     withVAO (vertexArrayObject m) $ do | ||||||
|         vertexAttribArray (AttribLocation 0) $= Enabled |         vertexAttribArray (AttribLocation 0) $= Enabled | ||||||
|  |         vertexAttribArray (AttribLocation 1) $= Enabled | ||||||
|         checkError "setting array to enabled" |         checkError "setting array to enabled" | ||||||
|         bindBuffer ElementArrayBuffer $= Just (triangleBufferObject m) |         bindBuffer ElementArrayBuffer $= Just (triangleBufferObject m) | ||||||
|         checkError "bindBuffer" |         checkError "bindBuffer" | ||||||
|         let n = fromIntegral.num_triangles.header $ m |         let n = fromIntegral.(*3).num_triangles.header $ m | ||||||
|         --print $ concat ["drawing ", show n," triangles"] |         --print $ concat ["drawing ", show n," triangles"] | ||||||
|         drawElements Triangles n UnsignedInt nullPtr |         drawElements Triangles n UnsignedInt nullPtr | ||||||
|         checkError "drawing model" |         checkError "drawing model" | ||||||
| @@ -332,7 +333,7 @@ drawMap = do | |||||||
|  |  | ||||||
|         glPatchParameteri gl_PATCH_VERTICES 3 |         glPatchParameteri gl_PATCH_VERTICES 3 | ||||||
|  |  | ||||||
|         cullFace $= Nothing --Just Front |         cullFace $= Just Front | ||||||
|         polygonMode $= (Fill,Fill) |         polygonMode $= (Fill,Fill) | ||||||
|  |  | ||||||
|         glDrawArrays gl_PATCHES 0 (fromIntegral numVert) |         glDrawArrays gl_PATCHES 0 (fromIntegral numVert) | ||||||
| @@ -491,11 +492,11 @@ render = do | |||||||
|         currentProgram $= Just (state ^. gl.glMap.objectProgram) |         currentProgram $= Just (state ^. gl.glMap.objectProgram) | ||||||
|         checkError "setting up shadowmap-program" |         checkError "setting up shadowmap-program" | ||||||
|         --set up projection (= copy from state) |         --set up projection (= copy from state) | ||||||
|         {-mat44ToGPU frust projmo "mapObjects-projection" |         mat44ToGPU frust projmo "mapObjects-projection" | ||||||
|         --set up camera |         --set up camera | ||||||
|         mat44ToGPU cam' vmatmo "mapObjects-cam" |         mat44ToGPU cam' vmatmo "mapObjects-cam" | ||||||
|         --set up normal |         --set up normal | ||||||
|         mat33ToGPU nmap nmatmo "mapObjects-nmat"-} |         mat33ToGPU nmap nmatmo "mapObjects-nmat" | ||||||
|  |  | ||||||
|         mapM_ renderObject (state ^. gl.glMap.mapObjects) |         mapM_ renderObject (state ^. gl.glMap.mapObjects) | ||||||
|         checkError "draw mapobjects" |         checkError "draw mapobjects" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user