If I enable shadows, >60% of the display is clipped and other distortions in the HMD
Uncomment the shadow bit and it works again.
The shadows are rendered in the HMD view as well as the monitor.
Example code:
// Project: _VR_Environment
// Created: 2017-08-18
#import_plugin AGKVR
// show all errors
SetErrorMode(2)
SetWindowTitle( "_VR_Environment" )
SetWindowSize( 1024, 768, 0 )
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetSyncRate(0,0)
UseNewDefaultFonts(1) // since version 2.0.22 we can use nicer default fonts
Global CamXRot#,CamYRot#,CamZRot#,CamXPos#,CamYPos#,CamZPos# as Float
global MouseX#,MouseY# as Float
global SunVx#,SunVy#,SunVz# as Float
global testPlane as Integer
global lefthandID as Integer
global box as Integer
SetGenerateMipmaps(1)
SetSkyBoxHorizonColor(200,200,255)
SetSkyBoxHorizonSize(3,25)
SetSkyBoxSkyColor(50,50,255)
SetSkyBoxSunColor(255,255,255)
SetSkyBoxVisible(1)
SetSkyBoxSunSize(12,63.0)
SetSkyBoxSunVisible(1)
#constant VR 1
CamXPos#=0.0
CamYPos#=50.0
CamZPos#=0.0
SunVx#=0.2
SunVy#=-0.2
SunVz#=-1
//SetSunDirection(SunVx#,SunVy#,SunVz#)
testplane=CreateObjectPlane(1500,1500)
SetObjectLookAt(testPlane,0,0,0,0)
SetObjectPosition(testPlane,0,0,500)
RotateObjectLocalX(testPlane,90)
SetObjectColor(testPlane,255,0,0,255)
box=CreateObjectBox(40,40,40)
SetObjectPosition(box,0,50,500)
//lefthandID=LoadObject("/media/left_controller_body.lwo")
if VR
AGKVR.SetCameraRange(0.01,1000.0)
AGKVR.ErrorMessagesOn(1)
InitError As Integer
RightEyeImg As Integer = 500
LeftEyeImg As Integer = 501
InitError = AGKVR.Init( RightEyeImg, LeftEyeImg )
// InitError = 0: SUCCESS!
// InitError = 1: Unable to init VR runtime
// InitError = 2: Compositor initialization failed.
AGKVR.UpdatePlayer( )
AGKVR.ResetSeatedZeroPose()
AGKVR.SetPlayerPosition(0,50,0)
AGKVR.SetPlayerRotation(0,0,0)
else
SetVSync(1)
endif
SetShadowMappingMode(3)
SetShadowSmoothing(1)
SetShadowBias(0.0012)
SetShadowMapSize(2048,2048)
SetObjectCastShadow(box,1)
Repeat
if VR
AGKVR.UpdatePlayer( )
//SetObjectPosition( lefthandID, AGKVR.GetLeftHandX(), AGKVR.GetLeftHandY(), AGKVR.GetLeftHandZ())
//SetObjectRotation( lefthandID, AGKVR.GetLeftHandAngleX(), AGKVR.GetLeftHandAngleY(), AGKVR.GetLeftHandAngleZ())
endif
if VR
AGKVR.Render()
//The camera's position and rotation will determine what is displayed on the monitor, not the HMD
SetCameraPosition( 1, AGKVR.GetHMDX(), AGKVR.GetHMDY(), AGKVR.GetHMDZ())
SetCameraRotation( 1, AGKVR.GetHMDAngleX(), AGKVR.GetHMDAngleY(), AGKVR.GetHMDAngleZ())
else
FreeView()
endif
//Print(ScreenFPS())
//Print(CamYRot#)
Sync()
Until GetRawKeyPressed(27)
function FreeView()
Local NewMouseX# as Float
Local NewMouseY# as Float
NewMouseX#=MouseX#-GetRawMouseX()
NewMouseY#=MouseY#-GetRawMouseY()
MouseX#=GetRawMouseX()
MouseY#=GetRawMouseY()
CamXRot#=CamXRot#-(NewMouseY#/8.0)
CamYRot#=CamYRot#-(NewMouseX#/8.0)
if MouseX#<100.0 then MouseX#=MouseX#+100.0
if MouseX#>900.0 then MouseX#=MouseX#-100.0
if MouseY#<100.0 then MouseY#=MouseY#+100.0
if MouseY#>600.0 then MouseY#=MouseY#-100.0
SetRawMousePosition(MouseX#,MouseY#)
SetCameraPosition(1,CamXPos#,CamYPos#,CamZPos#)
SetCameraLookAt(1,CamXPos#,CamYPos#,CamZPos#,0)
SetCameraRotation(1,CamXRot#,CamYRot#,CamZRot#)
endfunction