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 *****
 
+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.
 
 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 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.
 

+ 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;
 	
 	specular=fschlick * pow( ndoth,spow ) * fnorm;
-
+	
 	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
 	light*=shadowColor( position );
 #endif

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

@@ -71,6 +71,9 @@ uniform vec2 r_BufferCoordScale;
 //***** LIGHTING *****
 //
 uniform mat4 r_LightViewMatrix;
+uniform mat4 r_InverseLightViewMatrix;
+uniform samplerCube r_LightCubeTexture;
+uniform sampler2D r_LightTexture;
 uniform vec4 r_LightColor;
 uniform float r_LightRange;
 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
 		
 		_runiforms.SetMat4f( "LightViewMatrix",lvmatrix )
+		_runiforms.SetMat4f( "InverseLightViewMatrix",-lvmatrix )
 		_runiforms.SetColor( "LightColor",light.Color )
 		_runiforms.SetFloat( "LightRange",light.Range )
 		_runiforms.SetFloat( "LightInnerAngle",light.InnerAngle*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.DepthMask=False
@@ -204,6 +205,8 @@ When a new renderer is created, the config setting `MOJO3D\_RENDERER` can be use
 		
 		_gdevice.RenderTarget=_renderTarget1
 		
+		_runiforms.SetMat4f( "InverseProjectionMatrix",_invProjMatrix )
+		
 		RenderQuad()
 		
 		_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 _ambientRendered:Bool
+	
+	Field _whiteCubeTexture:Texture
+	Field _whiteTexture:Texture
 
 	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
 			
+		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 ) )
 	End
 	

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

@@ -29,7 +29,7 @@ Class Light Extends Entity
 		
 		Name="Light"
 		Type=LightType.Directional
-		Color=Color.White
+		Texture=Null
 		Range=10
 		InnerAngle=15
 		OuterAngle=30
@@ -53,6 +53,7 @@ Class Light Extends Entity
 	
 	#rem monkeydoc The light type.
 	#end
+	[jsonify=1]
 	Property Type:LightType()
 		
 		Return _type
@@ -62,6 +63,16 @@ Class Light Extends Entity
 		_type=type
 	End
 	
+	[jsonify=1]
+	Property Texture:Texture()
+		
+		Return _texture
+	
+	Setter( texture:Texture )
+		
+		_texture=texture
+	End
+	
 	#rem monkeydoc Light shadows enabled flag.
 	#end
 	[jsonify=1]
@@ -91,6 +102,7 @@ Class Light Extends Entity
 	Defaults to 0 degrees.
 		
 	#end
+	[jsonify=1]
 	Property InnerAngle:Float()
 		
 		Return _innerAngle
@@ -105,6 +117,7 @@ Class Light Extends Entity
 	Defaults to 45 degrees.
 		
 	#end
+	[jsonify=1]
 	Property OuterAngle:Float()
 		
 		Return _outerAngle
@@ -121,11 +134,11 @@ Class Light Extends Entity
 		Super.New( light,parent )
 		
 		Type=light.Type
-		Color=light.Color
+		Texture=light.Texture
+		CastsShadow=light.CastsShadow
 		Range=light.Range
 		InnerAngle=light.InnerAngle
 		OuterAngle=light.OuterAngle
-		CastsShadow=light.CastsShadow
 		
 		AddInstance( light )
 	End
@@ -148,6 +161,7 @@ Class Light Extends Entity
 	Private
 	
 	Field _type:LightType
+	Field _texture:Texture
 	Field _color:Color
 	Field _range: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 "assets/fish.glb"
+#Import "assets/monkey2-logo.png"
 
 Using std..
 Using mojo..
@@ -85,14 +86,16 @@ Class MyWindow Extends Window
 		
 		'Create camera
 		Local camera:=New Camera( Self )
-		camera.Move( 0,0,-5 )
+		camera.Move( 0,1,-5 )
 		camera.AddComponent<FlyBehaviour>()
 		
 		'Create light
 		Local light:=New Light
 		light.Type=LightType.Point
+		light.Texture=Texture.Load( "asset::monkey2-logo.png",TextureFlags.Filter|TextureFlags.Cubemap )
 		light.CastsShadow=True
 		light.Range=15
+		light.AddComponent<RotateBehaviour>().Speed=New Vec3f( 0,-.05,0 )
 		
 		CreateRoom()
 		

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

@@ -4,11 +4,12 @@ Namespace myapp3d
 #Import "<mojo>"
 #Import "<mojo3d>"
 
+#Import "assets/monkey2-logo.png"
+
 Using std..
 Using mojo..
 Using mojo3d..
 
-
 Class MyWindow Extends Window
 	
 	Field _scene:Scene
@@ -39,6 +40,7 @@ Class MyWindow Extends Window
 		'create light
 		_light=New Light
 		_light.Type=LightType.Spot
+		_light.Texture=Texture.Load( "asset::monkey2-logo.png" )'ColorTexture( Color.Red )
 		_light.Range=25
 		_light.InnerAngle=15
 		_light.OuterAngle=45
@@ -48,14 +50,16 @@ Class MyWindow Extends Window
 		
 		'create ground
 		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.CastsShadow=False
 		
 		'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.AddComponent<RotateBehaviour>().Speed=New Vec3f( .2,.4,.6 )
+		
 	End
 	
 	Method OnRender( canvas:Canvas ) Override
@@ -73,9 +77,10 @@ Class MyWindow Extends Window
 			End
 		Endif
 		
-		_donut.Rotate( .2,.4,.6 )
 		_scene.Update()
-		_camera.Render( canvas )
+		
+		_scene.Render( canvas )
+		
 		canvas.DrawText( "FPS="+App.FPS,0,0 )
 	End