Browse Source

Removed Terrain for now...

Mark Sibly 8 years ago
parent
commit
ca02d0fe32

+ 0 - 154
modules/mojo3d/graphics/shaders/terrain.glsl

@@ -1,154 +0,0 @@
-//@renderpasses 0,1
-
-//renderer uniforms...
-
-uniform mat4 r_ModelViewMatrix;
-uniform mat4 r_ModelViewProjectionMatrix;
-uniform mat3 r_ModelViewNormalMatrix;
-
-#if MX2_RENDERPASS==0
-
-uniform vec4 r_AmbientDiffuse;
-uniform samplerCube r_EnvTexture;
-uniform mat3 r_EnvMatrix;
-
-//pbr varyings...
-
-varying vec3 v_Position;
-varying vec2 v_TexCoord0;
-varying vec3 v_Normal;
-varying mat3 v_TanMatrix;
-
-#endif
-
-//@vertex
-
-//vertex attribs....
-
-attribute vec4 a_Position;
-
-#if MX2_RENDERPASS==0 
-
-attribute vec2 a_TexCoord0;
-attribute vec3 a_Normal;
-attribute vec4 a_Tangent;
-
-#endif
-
-void main(){
-
-#if MX2_RENDERPASS==0
-
-	// view space position
-	v_Position=( r_ModelViewMatrix * a_Position ).xyz;
-
-	// texture coord0
-	v_TexCoord0=a_TexCoord0;
-
-	// viewspace normal
-	v_Normal=r_ModelViewNormalMatrix * a_Normal;
-	
-	// viewspace tangent matrix
-	v_TanMatrix[2]=v_Normal;
-	v_TanMatrix[0]=r_ModelViewNormalMatrix * a_Tangent.xyz;
-	v_TanMatrix[1]=cross( v_TanMatrix[0],v_TanMatrix[2] ) * a_Tangent.a;
-	
-#endif
-	
-	gl_Position=r_ModelViewProjectionMatrix * a_Position;
-}
-
-//@fragment
-
-#if MX2_RENDERPASS==0
-
-void main0( vec3 color,vec3 emissive,float metalness,float roughness,float occlusion,vec3 normal ){
-
-	normal=normalize( v_TanMatrix * normal );
-
-	vec3 color0=vec3( 0.04,0.04,0.04 );
-	
-	vec3 diffuse=color * (1.0-metalness);
-	
-	vec3 specular=(color-color0) * metalness + color0;
-	
-	vec3 rvec=r_EnvMatrix * reflect( v_Position,normal );
-	
-	float lod=textureCube( r_EnvTexture,rvec,10.0 ).a * 255.0 - 10.0;
-	
-	if( lod>0.0 ) lod=textureCube( r_EnvTexture,rvec ).a * 255.0;
-	
-	vec3 env=pow( textureCube( r_EnvTexture,rvec,max( roughness*10.0-lod,0.0 ) ).rgb,vec3( 2.2 ) );
-
-	vec3 vvec=normalize( -v_Position );
-	
-	float ndotv=max( dot( normal,vvec ),0.0 );
-	
-	vec3 fschlick=specular + (1.0-specular) * pow( 1.0-ndotv,5.0 ) * (1.0-roughness);
-
-	vec3 ambdiff=diffuse * r_AmbientDiffuse.rgb;
-		
-	vec3 ambspec=env * fschlick;
-
-	gl_FragData[0]=vec4( min( (ambdiff+ambspec) * occlusion + emissive,8.0 ),1.0 );
-	
-	gl_FragData[1]=vec4( color,metalness );
-	
-	gl_FragData[2]=vec4( normal * 0.5 + 0.5,roughness );
-}
-
-#endif
-
-#if MX2_RENDERPASS==0
-
-uniform sampler2D m_BlendTexture;
-
-uniform sampler2D m_ColorTexture0;
-uniform sampler2D m_ColorTexture1;
-uniform sampler2D m_ColorTexture2;
-uniform sampler2D m_ColorTexture3;
-
-uniform sampler2D m_NormalTexture0;
-uniform sampler2D m_NormalTexture1;
-uniform sampler2D m_NormalTexture2;
-uniform sampler2D m_NormalTexture3;
-
-#endif
-
-void main(){
-
-#if MX2_RENDERPASS==0
-
-	vec4 blend=texture2D( m_BlendTexture,v_TexCoord0 ).rgb
-	
-	vec3 color0=pow( texture2D( m_ColorTexture0,v_TexCoord0 ).rgb,vec3( 2.2 ) ) * blend.r;
-	vec3 color1=pow( texture2D( m_ColorTexture1,v_TexCoord0 ).rgb,vec3( 2.2 ) ) * blend.g;
-	vec3 color2=pow( texture2D( m_ColorTexture2,v_TexCoord0 ).rgb,vec3( 2.2 ) ) * blend.b;
-	vec3 color3=pow( texture2D( m_ColorTexture3,v_TexCoord0 ).rgb,vec3( 2.2 ) ) * blend.a;
-	
-	vec3 normal0=( texture2D( m_NormalTexture0,v_TexCoord0 ).xyz * 2.0 - 1.0 ) * blend.r;
-	vec3 normal1=( texture2D( m_NormalTexture1,v_TexCoord0 ).xyz * 2.0 - 1.0 ) * blend.g;
-	vec3 normal2=( texture2D( m_NormalTexture2,v_TexCoord0 ).xyz * 2.0 - 1.0 ) * blend.b;
-	vec3 normal3=( texture2D( m_NormalTexture3,v_TexCoord0 ).xyz * 2.0 - 1.0 ) * blend.a;
-	
-	vec3 color=color0+color1+color2+color3;
-	
-	vec3 normal=normalize( normal0+normal1+normal2+normal3 );
-	
-	vec3 emissive=vec3( 0.0 );
-	
-	float metalness=0.0;
-	
-	float roughness=1.0;
-	
-	float occlusion=1.0;
-
-	main0( color,emissive,metalness,roughness,occlusion,normal );
-	
-#else
-
-	gl_FragColor=vec4( vec3( gl_FragCoord.z ),1.0 );
-
-#endif
-
-}

+ 0 - 198
modules/mojo3d/graphics/terrain.monkey2

@@ -1,198 +0,0 @@
-
-Namespace mojo3d.graphics
-
-#rem monkeydoc The Terrain class.
-#end
-Class Terrain Extends Entity
-
-	#rem monkeydoc Creates a new terrain.
-	#end	
-	Method New( heightMap:Pixmap,bounds:Boxf,material:Material,parent:Entity=null )
-		Super.New( parent )
-		
-		Local cellSize:=128
-		
-		Assert( heightMap.Width=heightMap.Height,"Terrain heightmap must be square" )
-		
-		Assert( Log2( heightMap.Width )=Floor( Log2( heightMap.Width ) ),"Terrain heightmap size must be power of 2" )
-
-		Assert( Log2( cellSize )=Floor( Log2( cellSize ) ),"Terrain cell size must be power of 2" )
-		
-		Assert( heightMap.Width>=cellSize,"Terrain heightmap size must be greater than cell size" )
-		
-		_heightMap=heightMap
-		_size=heightMap.Width
-		_bounds=bounds
-		_material=material
-		_cellSize=cellSize
-		
-		Init()
-		
-		Show()
-	End
-	
-	Method OnRender( rq:RenderQueue )
-		
-		Local count:=_ibuffer.Length/3
-		
-		For Local vbuffer:=Eachin _vbuffers
-
-			rq.AddRenderOp( _material,vbuffer,_ibuffer,Self,3,count,0 )
-			
-		Next
-	End
-	
-	Protected
-	
-	Method OnShow() Override
-		
-		Scene.Terrains.Add( Self )
-	End
-	
-	Method OnHide() Override
-		
-		Scene.Terrains.Remove( Self )
-	End
-	
-	Private
-	
-	Field _heightMap:Pixmap
-	Field _bounds:Boxf
-	Field _material:Material
-	
-	Field _cellSize:Int
-	Field _size:Int
-	
-	Field _ibuffer:IndexBuffer
-	Field _vbuffers:VertexBuffer[]
-	
-	Method GetPosition:Vec3f( i:Int,j:Int )
-		
-		i=Clamp( i,0,_size-1 )
-		j=Clamp( j,0,_size-1 )
-		
-		Local x:=Float(i)/Float(_size-1)
-		Local z:=Float(j)/Float(_size-1)
-		
-		Local y:=_heightMap.PixelPtr( i,j )[0]/255.0
-		
-		Return New Vec3f( x,y,z ) * _bounds.Size+_bounds.min
-	End
-
-	Method GetTexCoord0:Vec2f( i:Int,j:Int )
-	
-		Local x:=Float(i)/Float(_size-1)
-		Local z:=Float(j)/Float(_size-1)
-
-		Return New Vec2f( x,z )
-	End
-	
-	Method GetNormal:Vec3f( i:Int,j:Int )
-
-		Local v0:=GetPosition( i,j )
-		Local v1:=GetPosition( i,Min( j+1,_size-1 ) )
-		Local v2:=GetPosition( Min( i+1,_size-1 ),j )
-		Local v3:=GetPosition( i,Max( j-1,0 ) )
-		Local v4:=GetPosition( Max( i-1,0 ),j )
-				
-		Local n0:=(v1-v0).Cross(v2-v0).Normalize()
-		Local n1:=(v2-v0).Cross(v3-v0).Normalize()
-		Local n2:=(v3-v0).Cross(v4-v0).Normalize()
-		Local n3:=(v4-v0).Cross(v1-v0).Normalize()
-			
-		Local n:=(n0+n1+n2+n3).Normalize()
-			
-'		If (i&15)=0 And (j&15)=0 print "n="+v
-			
-'		DebugAssert( n.y>0 )
-		
-		Return n
-	End
-	
-	Function GetIndexBuffer:IndexBuffer( cellSize:Int )
-		
-		Global _ibuffers:=New IntMap<IndexBuffer>
-				
-		If _ibuffers.Contains( cellSize ) Return _ibuffers[cellSize]
-	
-		Local indices:=New Uint[ cellSize*cellSize*6 ],ip:=indices.Data
-				
-		For Local j:=0 Until cellSize
-		
-			Local k:=j*(cellSize+1)
-		
-			For Local i:=k Until k+cellSize
-			
-				Local v0:=i,v1:=i+cellSize+1,v2:=i+cellSize+2,v3:=i+1
-			
-				If (j~(i-k)) & 1
-	 				ip[0]=v1 ; ip[1]=v2 ; ip[2]=v3
-	 				ip[3]=v1 ; ip[4]=v3 ; ip[5]=v0
-				Else
-					ip[0]=v2 ; ip[1]=v3 ; ip[2]=v0
-					ip[3]=v2 ; ip[4]=v0 ; ip[5]=v1
-				Endif
-				
-				ip+=6
-			Next
-		Next
-		
-		Local ibuffer:=New IndexBuffer( indices )
-		
-		_ibuffers[cellSize]=ibuffer
-		
-		Return ibuffer
-	End
-	
-	Method Init()
-		
-		_ibuffer=GetIndexBuffer( _cellSize )
-		
-		Local vbuffers:=New Stack<VertexBuffer>
-		
-		Local vertices:=New Stack<Vertex3f>
-		
-		For Local j0:=0 Until _size Step _cellSize
-		
-			Local j1:=j0+_cellSize
-
-			For Local i0:=0 Until _size Step _cellSize
-			
-				Local i1:=i0+_cellSize
-				
-				Local v0:=vertices.Length
-				
-				For Local j:=j0 To j1
-				
-					For Local i:=i0 To i1
-					
-						Local p:=GetPosition( i,j )
-						
-						Local t0:=GetTexCoord0( i,j )
-						
-						Local n:=GetNormal( i,j )
-						
-						Local v:=New Vertex3f( p,t0,n )
-						
-						vertices.Push( v )
-					
-					Next
-					
-				Next
-				
-				UpdateTangents( vertices.Data.Data,vertices.Length,Cast<UInt Ptr>( _ibuffer.Data ),_ibuffer.Length )
-				
-				Local vbuffer:=New VertexBuffer( vertices.ToArray() )
-
-				vbuffers.Push( vbuffer )
-				
-				vertices.Clear()
-			Next
-			
-		Next
-		
-		_vbuffers=vbuffers.ToArray()
-
-	End
-	
-End

+ 0 - 71
modules/mojo3d/graphics/terrainmaterial.monkey2

@@ -1,71 +0,0 @@
-
-Namespace mojo3d.graphics
-
-#rem monkeydoc The TerrainMaterial class.
-#end
-Class TerrainMaterial Extends Material
-
-	#rem monkeydoc Creates a new terrain material.
-	#end
-	Method New()
-		Super.New( Shader.Open( "terrain" ) )
-		
-		BlendTexture=Texture.ColorTexture( Color.Black )
-		
-		ColorTextures=New Texture[](
-			Texture.ColorTexture( Color.White ),
-			Texture.ColorTexture( Color.White ),
-			Texture.ColorTexture( Color.White ),
-			Texture.ColorTexture( Color.White ) )
-			
-		NormalTextures=New Texture[]( 
-			Texture.FlatNormal(),
-			Texture.FlatNormal(),
-			Texture.FlatNormal(),
-			Texture.FlatNormal() )
-	End
-	
-	Property BlendTexture:Texture()
-		
-		Return Uniforms.GetTexture( "BlendTexture" )
-		
-	Setter( texture:Texture )
-		
-		Uniforms.SetTexture( "BlendTexture",texture )
-	End
-	
-	Property ColorTextures:Texture[]()
-		
-		Return New Texture[](
-			Uniforms.GetTexture( "ColorTexture0" ),
-			Uniforms.GetTexture( "ColorTexture1" ),
-			Uniforms.GetTexture( "ColorTexture2" ),
-			Uniforms.GetTexture( "ColorTexture3" ) )
-	
-	Setter( textures:Texture[] )
-		Assert( textures.Length=4,"ColorTextures length must be 4" )
-		
-		Uniforms.SetTexture( "ColorTexture0",textures[0] )
-		Uniforms.SetTexture( "ColorTexture1",textures[1] )
-		Uniforms.SetTexture( "ColorTexture2",textures[2] )
-		Uniforms.SetTexture( "ColorTexture3",textures[3] )
-	End
-	
-	Property NormalTextures:Texture[]()
-		
-		Return New Texture[](
-			Uniforms.GetTexture( "NormalTexture0" ),
-			Uniforms.GetTexture( "NormalTexture1" ),
-			Uniforms.GetTexture( "NormalTexture2" ),
-			Uniforms.GetTexture( "NormalTexture3" ) )
-	
-	Setter( textures:Texture[] )
-		Assert( textures.Length=4,"NormalTextures length must be 4" )
-		
-		Uniforms.SetTexture( "NormalTexture0",textures[0] )
-		Uniforms.SetTexture( "NormalTexture1",textures[1] )
-		Uniforms.SetTexture( "NormalTexture2",textures[2] )
-		Uniforms.SetTexture( "NormalTexture3",textures[3] )
-	End
-	
-End

+ 4 - 1
modules/mojo3d/mojo3d.monkey2

@@ -17,11 +17,14 @@ Using gles20..
 #Import "graphics/util3d"
 #Import "graphics/mesh"
 #Import "graphics/meshprims"
+
 #Import "graphics/entity"
+
 #Import "graphics/camera"
+
 #Import "graphics/light"
+
 #Import "graphics/model"
-#Import "graphics/terrain"
 
 #Import "graphics/sprite"
 #Import "graphics/spritebuffer"

+ 0 - 78
modules/mojo3d/tests/terraintest.monkey2

@@ -1,78 +0,0 @@
-
-Namespace myapp
-
-#Import "<std>"
-#Import "<mojo>"
-#Import "<mojo3d>"
-
-#Import "assets/"
-
-#Import "util"
-
-Using std..
-Using mojo..
-Using mojo3d..
-
-Class MyWindow Extends Window
-	
-	Field _scene:Scene
-	
-	Field _fog:FogEffect
-	
-	Field _camera:Camera
-	
-	Field _light:Light
-	
-	Field _material:Material
-	
-	Field _terrain:Terrain
-	
-	Method New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
-
-		Super.New( title,width,height,flags )
-		
-		_scene=Scene.GetCurrent()
-		
-		_fog=New FogEffect( Color.Sky,480,512 )
-		
-		'create camera
-		'
-		_camera=New Camera
-		_camera.Near=1
-		_camera.Far=512
-		_camera.Move( 0,66,0 )
-		
-		'create light
-		'
-		_light=New Light
-		_light.RotateX( Pi/2 )	'aim directional light 'down' - Pi/2=90 degrees.
-		
-		_material=PbrMaterial.Load( "asset::mossy-ground1.pbr" )
-		_material.ScaleTextureMatrix( 32,32 )
-		
-		Local heightMap:=Pixmap.Load( "asset::heightmap_256.BMP" )
-		
-		_terrain=New Terrain( heightMap,New Boxf( -512,0,-512,512,64,512 ),_material )
-	End
-	
-	Method OnRender( canvas:Canvas ) Override
-	
-		RequestRender()
-		
-		util.Fly( _camera,Self )
-		
-		_scene.Render( canvas,_camera )
-		
-		canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )
-	End
-	
-End
-
-Function Main()
-
-	New AppInstance
-	
-	New MyWindow
-	
-	App.Run()
-End