About Monkey 2 › Forums › Monkey 2 Development › Bug: Light sprite with Virtual Resolution
This topic contains 3 replies, has 3 voices, and was last updated by 
 Playniax
 1 year, 7 months ago.
- 
		AuthorPosts
 - 
		
			
				
September 9, 2017 at 11:53 pm #10378
I’ve altered the simple light example to implement a virtual resolution, but when I move the mouse around the light sprite doesnt move correctly with the mouse when I maximize the window:
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104[crayon-5cba8cf27e93b020364821 inline="true" ]Namespace myapp#Import "<std>"#Import "<mojo>"#Import "Slate Tiles II_D.png"#Import "Slate Tiles II_N.png"#Import "Slate Tiles II_S.png"#Import "cone_orange.png"#Import "Monkey2-logo-48.png"Using std..Using mojo..Global virtualResolution:=New Vec2i( 640,480 )Class MyWindow Extends WindowField _floor:ImageField _light:ImageField _logo:ImageMethod New()Super.New( "Test Window",640,480,WindowFlags.Resizable )Layout = "letterbox"ClearColor=Color.Black_floor=Image.LoadBump( "asset::Slate Tiles II_D.png","asset::Slate Tiles II_N.png","asset::Slate Tiles II_S.png",.75,True )_light=Image.LoadLight( "asset::cone_orange.png" )_light.Handle=New Vec2f( .5,0 )_light.Scale=New Vec2f( 3, 3 )_logo=Image.Load( "asset::Monkey2-logo-48.png" )_logo.Handle=New Vec2f( .5 )_logo.ShadowCaster=New ShadowCaster( _logo.Width/2,20 )EndMethod OnMeasure:Vec2i() OverrideReturn virtualResolutionEndMethod OnRender( canvas:Canvas ) OverrideGlobal viewRot:=0.0viewRot+=.001' canvas.Translate( Width/2,Height/2 )' canvas.Scale( Sin( viewRot*3 )*.25+1.25,Cos( viewRot*5 )*.25+1.25 )' canvas.Rotate( viewRot )' canvas.Translate( -Width/2,-Height/2 )Local rmouse:=-canvas.Matrix * Mouse.LocationGlobal lightRot:=0.0lightRot+=.02App.RequestRender()canvas.AmbientLight=New Color( .1,.1,.1,1 ) 'Color.DarkGreycanvas.BeginLighting()canvas.AddLight( _light,rmouse.X,rmouse.Y,lightRot )canvas.AddLight( _light,rmouse.X,rmouse.Y,lightRot+Pi )canvas.AddLight( _light,rmouse.X,rmouse.Y,lightRot+Pi/2 )canvas.AddLight( _light,rmouse.X,rmouse.Y,lightRot+Pi+Pi/2 )For Local x:=0 Until Width Step _floor.WidthFor Local y:=0 Until Height Step _floor.Heightcanvas.DrawImage( _floor,x,y )NextNextFor Local an:=0.0 Until TwoPi Step TwoPi/8.0canvas.DrawImage( _logo,Width/2+Cos( an ) * Width/4,Height/2 + Sin( an ) * Height/4 )Nextcanvas.EndLighting()canvas.DrawText( Floor( App.FPS+.5 ),Width/2,0,.5,0 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndSeptember 10, 2017 at 6:38 am #10385Woah, had to dig deep to find that one, but once I did the fix was surprisingly simple and halved the length of the light vertex shader in the process.
Fix push to develop branch, but you should really only need to update this file:
https://github.com/blitz-research/monkey2/blob/develop/modules/mojo/graphics/shaders/light.glsl
September 10, 2017 at 6:45 am #10386Thanks Mark! I’ll test in a bit
September 10, 2017 at 7:23 am #10387Great find therevills! Thanks Mark!
Btw, I found that Pyro’s own virtual stuff did not suffer the problem…
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.