Browse Source

Added experimental point/spot light texturing - see tests/spotlight and tests/room.

Mark Sibly 7 years ago
parent
commit
22b822c248

+ 7 - 1
VERSIONS.TXT

@@ -1,6 +1,12 @@
 
 
 ***** Monkey-v2018.05 Mx2cc-v1.1.12 Ted2go-2.10 *****
 ***** Monkey-v2018.05 Mx2cc-v1.1.12 Ted2go-2.10 *****
 
 
+Added experimental spot and point light texturing via new Light.Texture property. See tests/spotlight and tests/room for demos.
+
+Added RigidBody.LinearFactor and RigidBody.Angular factor properties - untested!
+
+Added support for multiple UVs to gltf2 and assimp loaders.
+
 Streamlined mojo3d tests dir.
 Streamlined mojo3d tests dir.
 
 
 Added LinearDamping and AngularDamping properties to RigidBody, but can't get them to do anything so far - please have a play James!
 Added LinearDamping and AngularDamping properties to RigidBody, but can't get them to do anything so far - please have a play James!
@@ -13,7 +19,7 @@ Major clean up of mojo3d material system. Minor cleanup of post effect system, m
 
 
 Added multidimensional array initializers, eg: New Int[2,2]( 1,2,3,4 ). Array length much match number of elements exactly or runtime error.
 Added multidimensional array initializers, eg: New Int[2,2]( 1,2,3,4 ). Array length much match number of elements exactly or runtime error.
 
 
-Added first physics constraint component to mojo3d - should probably be renamed joint IMO. Stay tuned...
+Added first physics constraint component to mojo3d, PointToPointConstraint - should probably be renamed joint IMO. Stay tuned...
 
 
 Added low budget OpenUrl for emscripten. It just replaces current page with the given URL so effectively ends app too.
 Added low budget OpenUrl for emscripten. It just replaces current page with the given URL so effectively ends app too.
 
 

+ 15 - 1
modules/mojo3d/assets/shaders/imports/pbr.glsl

@@ -57,9 +57,23 @@ void emitPbrFragment( vec3 color,float metalness,float roughness,vec3 position,v
 	vec3 fschlick=specular + (1.0-specular) * pow( 1.0-hdotl,5.0 ) * glosiness;
 	vec3 fschlick=specular + (1.0-specular) * pow( 1.0-hdotl,5.0 ) * glosiness;
 	
 	
 	specular=fschlick * pow( ndoth,spow ) * fnorm;
 	specular=fschlick * pow( ndoth,spow ) * fnorm;
-
+	
 	vec3 light=r_LightColor.rgb * ndotl * atten;
 	vec3 light=r_LightColor.rgb * ndotl * atten;
 	
 	
+#if MX2_POINTLIGHT
+
+	vec3 lpos=(r_InverseLightViewMatrix * vec4( position,1.0 )).xyz;
+	light*=pow( textureCube( r_LightCubeTexture,lpos ).rgb,vec3( 2.2 ) );
+
+#elif MX2_SPOTLIGHT
+
+	vec3 lpos=(r_InverseLightViewMatrix * vec4( position,1.0 )).xyz;
+	lpos.xy=lpos.xy/lpos.z * 0.5 + 0.5;
+	lpos.y=1.0-lpos.y;
+	light*=pow( texture2D( r_LightTexture,lpos.xy ).rgb,vec3( 2.2 ) ); 
+
+#endif
+	
 #if MX2_SHADOWTYPE
 #if MX2_SHADOWTYPE
 	light*=shadowColor( position );
 	light*=shadowColor( position );
 #endif
 #endif

+ 3 - 0
modules/mojo3d/assets/shaders/imports/std.glsl

@@ -71,6 +71,9 @@ uniform vec2 r_BufferCoordScale;
 //***** LIGHTING *****
 //***** LIGHTING *****
 //
 //
 uniform mat4 r_LightViewMatrix;
 uniform mat4 r_LightViewMatrix;
+uniform mat4 r_InverseLightViewMatrix;
+uniform samplerCube r_LightCubeTexture;
+uniform sampler2D r_LightTexture;
 uniform vec4 r_LightColor;
 uniform vec4 r_LightColor;
 uniform float r_LightRange;
 uniform float r_LightRange;
 uniform float r_LightInnerAngle;
 uniform float r_LightInnerAngle;

+ 14 - 2
modules/mojo3d/render/renderer.monkey2

@@ -186,12 +186,13 @@ When a new renderer is created, the config setting `MOJO3D\_RENDERER` can be use
 		Local lvmatrix:=_viewMatrix * light.Matrix
 		Local lvmatrix:=_viewMatrix * light.Matrix
 		
 		
 		_runiforms.SetMat4f( "LightViewMatrix",lvmatrix )
 		_runiforms.SetMat4f( "LightViewMatrix",lvmatrix )
+		_runiforms.SetMat4f( "InverseLightViewMatrix",-lvmatrix )
 		_runiforms.SetColor( "LightColor",light.Color )
 		_runiforms.SetColor( "LightColor",light.Color )
 		_runiforms.SetFloat( "LightRange",light.Range )
 		_runiforms.SetFloat( "LightRange",light.Range )
 		_runiforms.SetFloat( "LightInnerAngle",light.InnerAngle*Pi/180.0 )
 		_runiforms.SetFloat( "LightInnerAngle",light.InnerAngle*Pi/180.0 )
 		_runiforms.SetFloat( "LightOuterAngle",light.OuterAngle*Pi/180.0 )
 		_runiforms.SetFloat( "LightOuterAngle",light.OuterAngle*Pi/180.0 )
-		
-		_runiforms.SetMat4f( "InverseProjectionMatrix",_invProjMatrix )
+		_runiforms.SetTexture( "LightCubeTexture",light.Texture ?Else _whiteCubeTexture )
+		_runiforms.SetTexture( "LightTexture",light.Texture ?Else _whiteTexture )
 		
 		
 		_gdevice.ColorMask=ColorMask.All
 		_gdevice.ColorMask=ColorMask.All
 		_gdevice.DepthMask=False
 		_gdevice.DepthMask=False
@@ -204,6 +205,8 @@ When a new renderer is created, the config setting `MOJO3D\_RENDERER` can be use
 		
 		
 		_gdevice.RenderTarget=_renderTarget1
 		_gdevice.RenderTarget=_renderTarget1
 		
 		
+		_runiforms.SetMat4f( "InverseProjectionMatrix",_invProjMatrix )
+		
 		RenderQuad()
 		RenderQuad()
 		
 		
 		_gdevice.RenderTarget=_renderTarget0
 		_gdevice.RenderTarget=_renderTarget0
@@ -809,6 +812,9 @@ When a new renderer is created, the config setting `MOJO3D\_RENDERER` can be use
 	Field _invProjMatrix:Mat4f
 	Field _invProjMatrix:Mat4f
 	
 	
 	Field _ambientRendered:Bool
 	Field _ambientRendered:Bool
+	
+	Field _whiteCubeTexture:Texture
+	Field _whiteTexture:Texture
 
 
 	Global _current:Renderer
 	Global _current:Renderer
 	
 	
@@ -847,6 +853,12 @@ When a new renderer is created, the config setting `MOJO3D\_RENDERER` can be use
 			New Mat3f( +1,0, 0, 0,-1,0,  0,0,+1 ),	'+Z
 			New Mat3f( +1,0, 0, 0,-1,0,  0,0,+1 ),	'+Z
 			New Mat3f( -1,0, 0, 0,-1,0,  0,0,-1 ) )	'-Z
 			New Mat3f( -1,0, 0, 0,-1,0,  0,0,-1 ) )	'-Z
 			
 			
+		Local pixmap:=New Pixmap( 1,1,PixelFormat.I8 )
+		pixmap.Clear( Color.White )
+		_whiteCubeTexture=New Texture( pixmap,TextureFlags.Cubemap )
+		
+		_whiteTexture=Texture.ColorTexture( Color.White )
+			
 		ValidateSize( New Vec2i( 1920,1080 ) )
 		ValidateSize( New Vec2i( 1920,1080 ) )
 	End
 	End
 	
 	

+ 17 - 3
modules/mojo3d/scene/entities/light.monkey2

@@ -29,7 +29,7 @@ Class Light Extends Entity
 		
 		
 		Name="Light"
 		Name="Light"
 		Type=LightType.Directional
 		Type=LightType.Directional
-		Color=Color.White
+		Texture=Null
 		Range=10
 		Range=10
 		InnerAngle=15
 		InnerAngle=15
 		OuterAngle=30
 		OuterAngle=30
@@ -53,6 +53,7 @@ Class Light Extends Entity
 	
 	
 	#rem monkeydoc The light type.
 	#rem monkeydoc The light type.
 	#end
 	#end
+	[jsonify=1]
 	Property Type:LightType()
 	Property Type:LightType()
 		
 		
 		Return _type
 		Return _type
@@ -62,6 +63,16 @@ Class Light Extends Entity
 		_type=type
 		_type=type
 	End
 	End
 	
 	
+	[jsonify=1]
+	Property Texture:Texture()
+		
+		Return _texture
+	
+	Setter( texture:Texture )
+		
+		_texture=texture
+	End
+	
 	#rem monkeydoc Light shadows enabled flag.
 	#rem monkeydoc Light shadows enabled flag.
 	#end
 	#end
 	[jsonify=1]
 	[jsonify=1]
@@ -91,6 +102,7 @@ Class Light Extends Entity
 	Defaults to 0 degrees.
 	Defaults to 0 degrees.
 		
 		
 	#end
 	#end
+	[jsonify=1]
 	Property InnerAngle:Float()
 	Property InnerAngle:Float()
 		
 		
 		Return _innerAngle
 		Return _innerAngle
@@ -105,6 +117,7 @@ Class Light Extends Entity
 	Defaults to 45 degrees.
 	Defaults to 45 degrees.
 		
 		
 	#end
 	#end
+	[jsonify=1]
 	Property OuterAngle:Float()
 	Property OuterAngle:Float()
 		
 		
 		Return _outerAngle
 		Return _outerAngle
@@ -121,11 +134,11 @@ Class Light Extends Entity
 		Super.New( light,parent )
 		Super.New( light,parent )
 		
 		
 		Type=light.Type
 		Type=light.Type
-		Color=light.Color
+		Texture=light.Texture
+		CastsShadow=light.CastsShadow
 		Range=light.Range
 		Range=light.Range
 		InnerAngle=light.InnerAngle
 		InnerAngle=light.InnerAngle
 		OuterAngle=light.OuterAngle
 		OuterAngle=light.OuterAngle
-		CastsShadow=light.CastsShadow
 		
 		
 		AddInstance( light )
 		AddInstance( light )
 	End
 	End
@@ -148,6 +161,7 @@ Class Light Extends Entity
 	Private
 	Private
 	
 	
 	Field _type:LightType
 	Field _type:LightType
+	Field _texture:Texture
 	Field _color:Color
 	Field _color:Color
 	Field _range:Float
 	Field _range:Float
 	Field _innerAngle:Float
 	Field _innerAngle:Float

BIN
modules/mojo3d/tests/assets/monkey2-logo.png


+ 4 - 1
modules/mojo3d/tests/room.monkey2

@@ -5,6 +5,7 @@ Namespace myapp
 #Import "<mojo3d>"
 #Import "<mojo3d>"
 
 
 #Import "assets/fish.glb"
 #Import "assets/fish.glb"
+#Import "assets/monkey2-logo.png"
 
 
 Using std..
 Using std..
 Using mojo..
 Using mojo..
@@ -85,14 +86,16 @@ Class MyWindow Extends Window
 		
 		
 		'Create camera
 		'Create camera
 		Local camera:=New Camera( Self )
 		Local camera:=New Camera( Self )
-		camera.Move( 0,0,-5 )
+		camera.Move( 0,1,-5 )
 		camera.AddComponent<FlyBehaviour>()
 		camera.AddComponent<FlyBehaviour>()
 		
 		
 		'Create light
 		'Create light
 		Local light:=New Light
 		Local light:=New Light
 		light.Type=LightType.Point
 		light.Type=LightType.Point
+		light.Texture=Texture.Load( "asset::monkey2-logo.png",TextureFlags.Filter|TextureFlags.Cubemap )
 		light.CastsShadow=True
 		light.CastsShadow=True
 		light.Range=15
 		light.Range=15
+		light.AddComponent<RotateBehaviour>().Speed=New Vec3f( 0,-.05,0 )
 		
 		
 		CreateRoom()
 		CreateRoom()
 		
 		

+ 11 - 6
modules/mojo3d/tests/spotlight.monkey2

@@ -4,11 +4,12 @@ Namespace myapp3d
 #Import "<mojo>"
 #Import "<mojo>"
 #Import "<mojo3d>"
 #Import "<mojo3d>"
 
 
+#Import "assets/monkey2-logo.png"
+
 Using std..
 Using std..
 Using mojo..
 Using mojo..
 Using mojo3d..
 Using mojo3d..
 
 
-
 Class MyWindow Extends Window
 Class MyWindow Extends Window
 	
 	
 	Field _scene:Scene
 	Field _scene:Scene
@@ -39,6 +40,7 @@ Class MyWindow Extends Window
 		'create light
 		'create light
 		_light=New Light
 		_light=New Light
 		_light.Type=LightType.Spot
 		_light.Type=LightType.Spot
+		_light.Texture=Texture.Load( "asset::monkey2-logo.png" )'ColorTexture( Color.Red )
 		_light.Range=25
 		_light.Range=25
 		_light.InnerAngle=15
 		_light.InnerAngle=15
 		_light.OuterAngle=45
 		_light.OuterAngle=45
@@ -48,14 +50,16 @@ Class MyWindow Extends Window
 		
 		
 		'create ground
 		'create ground
 		Local groundBox:=New Boxf( -100,-1,-100,100,0,100 )
 		Local groundBox:=New Boxf( -100,-1,-100,100,0,100 )
-		Local groundMaterial:=New PbrMaterial( Color.White,0,1 )
+		Local groundMaterial:=New PbrMaterial( Color.Brown,0,1 )
 		_ground=Model.CreateBox( groundBox,1,1,1,groundMaterial )
 		_ground=Model.CreateBox( groundBox,1,1,1,groundMaterial )
 		_ground.CastsShadow=False
 		_ground.CastsShadow=False
 		
 		
 		'create donut
 		'create donut
-		Local donutMaterial:=New PbrMaterial( Color.Red, 0.05, 0.2 )
-		_donut=Model.CreateBox( New Boxf( -1,1 ),1,1,1,donutMaterial )'Model.CreateTorus( 2,.5,48,24,donutMaterial )
+		Local donutMaterial:=New PbrMaterial( Color.White,0,1 )
+		_donut=Model.CreateTorus( 2,.5,48,24,donutMaterial )
 		_donut.Move( 0,2.5,0 )
 		_donut.Move( 0,2.5,0 )
+		_donut.AddComponent<RotateBehaviour>().Speed=New Vec3f( .2,.4,.6 )
+		
 	End
 	End
 	
 	
 	Method OnRender( canvas:Canvas ) Override
 	Method OnRender( canvas:Canvas ) Override
@@ -73,9 +77,10 @@ Class MyWindow Extends Window
 			End
 			End
 		Endif
 		Endif
 		
 		
-		_donut.Rotate( .2,.4,.6 )
 		_scene.Update()
 		_scene.Update()
-		_camera.Render( canvas )
+		
+		_scene.Render( canvas )
+		
 		canvas.DrawText( "FPS="+App.FPS,0,0 )
 		canvas.DrawText( "FPS="+App.FPS,0,0 )
 	End
 	End