From 361d70bf1c0046a11acab7282362ffc3b2d521b0 Mon Sep 17 00:00:00 2001 From: Astrofra Date: Fri, 9 Dec 2022 16:21:43 +0100 Subject: [PATCH] v3.2.5 update. Added the Python/Lua/Go `XR` samples. Fixed the vertex layout of the `render to texture` sample. --- resources/playground/Plane.geo | Bin 179 -> 5045 bytes scene_draw_to_texture.go | 2 +- scene_draw_to_texture.lua | 2 +- scene_draw_to_texture.py | 2 +- scene_xr.go | 162 +++++++++++++++++++++++++++++++++ scene_xr.lua | 132 +++++++++++++++++++++++++++ scene_xr.py | 128 ++++++++++++++++++++++++++ 7 files changed, 425 insertions(+), 3 deletions(-) create mode 100644 scene_xr.go create mode 100644 scene_xr.lua create mode 100644 scene_xr.py diff --git a/resources/playground/Plane.geo b/resources/playground/Plane.geo index 239c5689ac883ebe0c1d1c16ebecfc6a66df9468..81a7f9d7a42bbc9969811c3d6d775630f14bfe94 100644 GIT binary patch literal 5045 zcmeI0y>3%M5JuNd0wDw({z(D3ugcJl zkfF7&mr=FWyjezSt$9m^M$MbnnzvX4soZ^!y%ddRtT=^?Ww`Nx;Xab5Dg)z$bpnI1B0 zlIbC{Ci(r~VO*E|{MmB+oJR%#GVcp} zzgw4|&rzp*+^6)T`Ji)o>(fhLW53fgE$39sH*I;_hn!3MRQySY`AJ(o>|;*)aPC<8 zvA!4YQd{2otjYS`4|}F_dFxaDej@!3rGDt!=9{*>?IZL*l>LUj^ZBrkdFkK#MqmEA yQ1-nhaVcucr#`j+M&EQUpZe7P8-3IDV*g2p{&aoYXH)JEb(sHq-uCG#Jih?+6p^j~ literal 179 zcmeZpcXLx<00I^e!SLZA1cTX*NNkWekPjCJvl)S07O+kxAd4A@K_VakF%80IU})G6 MV-d$jsK&+u0GM47*8l(j diff --git a/scene_draw_to_texture.go b/scene_draw_to_texture.go index b72fdb0..022178c 100644 --- a/scene_draw_to_texture.go +++ b/scene_draw_to_texture.go @@ -28,7 +28,7 @@ func main() { color := hg.GetColorTexture(frame_buffer) // create the cube model - vtx_layout := hg.VertexLayoutPosFloatNormUInt8TexCoord0UInt8() + vtx_layout := hg.VertexLayoutPosFloatTexCoord0UInt8() cube_mdl := hg.CreateCubeModel(vtx_layout, 1, 1, 1) res.AddModel("cube", cube_mdl) diff --git a/scene_draw_to_texture.lua b/scene_draw_to_texture.lua index d63e550..cc22599 100644 --- a/scene_draw_to_texture.lua +++ b/scene_draw_to_texture.lua @@ -23,7 +23,7 @@ frame_buffer = hg.CreateFrameBuffer(512, 512, hg.TF_RGBA32F, hg.TF_D24, 4, 'fram color = hg.GetColorTexture(frame_buffer) -- create the cube model -vtx_layout = hg.VertexLayoutPosFloatNormUInt8TexCoord0UInt8() +vtx_layout = hg.VertexLayoutPosFloatTexCoord0UInt8() cube_mdl = hg.CreateCubeModel(vtx_layout, 1, 1, 1) cube_ref = res:AddModel('cube', cube_mdl) diff --git a/scene_draw_to_texture.py b/scene_draw_to_texture.py index 05e1bf8..3330694 100644 --- a/scene_draw_to_texture.py +++ b/scene_draw_to_texture.py @@ -24,7 +24,7 @@ color = hg.GetColorTexture(frame_buffer) # create the cube model -vtx_layout = hg.VertexLayoutPosFloatNormUInt8TexCoord0UInt8() +vtx_layout = hg.VertexLayoutPosFloatTexCoord0UInt8() cube_mdl = hg.CreateCubeModel(vtx_layout, 1, 1, 1) cube_ref = res.AddModel('cube', cube_mdl) diff --git a/scene_xr.go b/scene_xr.go new file mode 100644 index 0000000..f6f54fd --- /dev/null +++ b/scene_xr.go @@ -0,0 +1,162 @@ +package main + +/* +#include +extern void update_controllersCallback(uintptr); +extern uint16_t draw_sceneCallback(uintptr, uintptr, uintptr, uintptr); +*/ +import "C" + +import ( + "unsafe" + + hg "github.com/harfang3d/harfang-go/v3" +) + +var ( + prg_ref *hg.PipelineProgramRef + scene *hg.Scene + render_data *hg.SceneForwardPipelineRenderData + + pipeline *hg.ForwardPipeline + res *hg.PipelineResources +) + +// Create materials +func create_material(ubc *hg.Vec4, orm *hg.Vec4) *hg.Material { + mat := hg.NewMaterial() + hg.SetMaterialProgram(mat, prg_ref) + hg.SetMaterialValueWithVec4V(mat, "uBaseOpacityColor", ubc) + hg.SetMaterialValueWithVec4V(mat, "uOcclusionRoughnessMetalnessColor", orm) + return mat +} + +//export update_controllersCallback +func update_controllersCallback(head uintptr) { +} + +//export draw_sceneCallback +func draw_sceneCallback(rect uintptr, viewState uintptr, view_id *uint16, fb uintptr) uint16 { + rect_ := hg.NewIntRectFromCPointer(unsafe.Pointer(rect)) + viewState_ := hg.NewViewStateFromCPointer(unsafe.Pointer(viewState)) + fb_ := hg.NewFrameBufferHandleFromCPointer(unsafe.Pointer(fb)) + passId := hg.NewSceneForwardPipelinePassViewId() + hg.PrepareSceneForwardPipelineViewDependentRenderData(view_id, viewState_, scene, render_data, pipeline, res, passId) + passId = hg.SubmitSceneToForwardPipelineWithFrameBuffer(view_id, scene, rect_, viewState_, pipeline, render_data, res, fb_) + + hg.Frame() + return *view_id +} + +func main() { + hg.InputInit() + hg.WindowSystemInit() + + hg.SetLogLevel(hg.LLAll) + hg.SetLogDetailed(true) + + res_x, res_y := int32(1280), int32(720) + win := hg.RenderInitWithWindowTitleWidthHeightTypeResetFlags("Harfang - OpenXR Scene", res_x, res_y, hg.RTDirect3D11, hg.RFNone) + + hg.AddAssetsFolder("resources_compiled") + + pipeline = hg.CreateForwardPipeline() + res = hg.NewPipelineResources() + + render_data = hg.NewSceneForwardPipelineRenderData() // this object is used by the low-level scene rendering API to share view-independent data with both eyes + + // OpenVR initialization + if !hg.OpenXRInit() { + panic("Can't initialize OpenXR") + } + + eye_framebuffer := hg.OpenXRCreateEyeFrameBufferWithAa(hg.OXRAAMSAA4x) + + // Create models + vtx_layout := hg.VertexLayoutPosFloatNormUInt8() + + cube_mdl := hg.CreateCubeModel(vtx_layout, 1, 1, 1) + cube_ref := res.AddModel("cube", cube_mdl) + ground_mdl := hg.CreateCubeModel(vtx_layout, 50, 0.01, 50) + ground_ref := res.AddModel("ground", ground_mdl) + + // Load shader + prg_ref = hg.LoadPipelineProgramRefFromAssets("core/shader/pbr.hps", res, hg.GetForwardPipelineInfo()) + + // Create scene + scene = hg.NewScene() + scene.GetCanvas().SetColor(hg.NewColorWithRGBA(255.0/255.0, 255.0/255.0, 217.0/255.0, 1.0)) + scene.GetEnvironment().SetAmbient(hg.NewColorWithRGBA(15.0/255.0, 12.0/255.0, 9.0/255.0, 1.0)) + + hg.CreateSpotLightWithDiffuseSpecularPriorityShadowTypeShadowBias(scene, hg.TransformationMat4(hg.NewVec3WithXYZ(-8, 4, -5), hg.NewVec3WithXYZ(hg.Deg(19), hg.Deg(59), 0)), 0, hg.Deg(5), hg.Deg(30), hg.ColorGetWhite(), hg.ColorGetWhite(), 10, hg.LSTMap, 0.0001) + hg.CreatePointLightWithDiffuseSpecularPriority(scene, hg.TranslationMat4(hg.NewVec3WithXYZ(2.4, 1, 0.5)), 10, hg.NewColorWithRGBA(94.0/255.0, 255.0/255.0, 228.0/255.0, 1.0), hg.NewColorWithRGBA(94.0/255.0, 1.0, 228.0/255.0, 1.0), 0) + + mat_cube := create_material(hg.NewVec4WithXYZW(255.0/255.0, 230.0/255.0, 255.0/255.0, 1), hg.NewVec4WithXYZW(1, 0.658, 0., 1)) + hg.CreateObjectWithSliceOfMaterials(scene, hg.TransformationMat4(hg.NewVec3WithXYZ(0, 0.5, 0), hg.NewVec3WithXYZ(0, hg.Deg(70), 0)), cube_ref, hg.GoSliceOfMaterial{mat_cube}) + + mat_ground := create_material(hg.NewVec4WithXYZW(255/255.0, 120/255.0, 147/255.0, 1), hg.NewVec4WithXYZW(1, 1, 0.1, 1)) + hg.CreateObjectWithSliceOfMaterials(scene, hg.TranslationMat4(hg.NewVec3WithXYZ(0, 0, 0)), ground_ref, hg.GoSliceOfMaterial{mat_ground}) + + // Setup 2D rendering to display eyes textures + quad_layout := hg.NewVertexLayout() + quad_layout.Begin().Add(hg.APosition, 3, hg.ATFloat).Add(hg.ATexCoord0, 3, hg.ATFloat).End() + + quad_model := hg.CreatePlaneModel(quad_layout, 1, 1, 1, 1) + quad_render_state := hg.ComputeRenderStateWithDepthTestCulling(hg.BMAlpha, hg.DTDisabled, hg.FCDisabled) + + eye_t_size := float32(res_x) / 2.5 + eye_t_x := (float32(res_x)-2*eye_t_size)/6 + eye_t_size/2 + quad_matrix := hg.TransformationMat4WithScale(hg.NewVec3WithXYZ(0, 0, 0), hg.NewVec3WithXYZ(hg.Deg(90), hg.Deg(0), hg.Deg(0)), hg.NewVec3WithXYZ(eye_t_size, 1, eye_t_size)) + + tex0_program := hg.LoadProgramFromAssets("shaders/sprite") + + quad_uniform_set_value_list := hg.NewUniformSetValueList() + quad_uniform_set_value_list.Clear() + quad_uniform_set_value_list.PushBack(hg.MakeUniformSetValueWithVec4V("color", hg.NewVec4WithXYZW(1, 1, 1, 1))) + + quad_uniform_set_texture_list := hg.NewUniformSetTextureList() + + //<-time.After(time.Second * 3) + + // Main loop + for !hg.ReadKeyboard().Key(hg.KEscape) && hg.IsWindowOpen(win) { + + dt := hg.TickClock() + + scene.Update(dt) + + vid := uint16(0) // keep track of the next free view id + passId := hg.NewSceneForwardPipelinePassViewId() + + // Prepare view-independent render data once + hg.PrepareSceneForwardPipelineCommonRenderData(&vid, scene, render_data, pipeline, res, passId) + + openxrFrameInfo := hg.OpenXRSubmitSceneToForwardPipeline(hg.TranslationMat4(hg.NewVec3WithXYZ(0, 0, 0)), C.update_controllersCallback, C.draw_sceneCallback, &vid, 0.1, 100) + + // Display the VR eyes texture to the backbuffer + hg.SetViewRect(vid, 0, 0, uint16(res_x), uint16(res_y)) + vs := hg.ComputeOrthographicViewState(hg.TranslationMat4(hg.NewVec3WithXYZ(0, 0, 0)), float32(res_y), 0.1, 100, hg.ComputeAspectRatioX(float32(res_x), float32(res_y))) + hg.SetViewTransform(vid, vs.GetView(), vs.GetProj()) + + if openxrFrameInfo.GetIdFbs().Len() > 0 { + quad_uniform_set_texture_list.Clear() + quad_uniform_set_texture_list.PushBack(hg.MakeUniformSetTexture("s_tex", hg.OpenXRGetColorTextureFromId(eye_framebuffer, openxrFrameInfo, 0), 0)) + hg.SetT(quad_matrix, hg.NewVec3WithXYZ(eye_t_x, 0, 1)) + hg.DrawModelWithRenderState(vid, quad_model, tex0_program, quad_uniform_set_value_list, quad_uniform_set_texture_list, quad_matrix, quad_render_state) + + quad_uniform_set_texture_list.Clear() + quad_uniform_set_texture_list.PushBack(hg.MakeUniformSetTexture("s_tex", hg.OpenXRGetColorTextureFromId(eye_framebuffer, openxrFrameInfo, 1), 0)) + hg.SetT(quad_matrix, hg.NewVec3WithXYZ(-eye_t_x, 0, 1)) + hg.DrawModelWithRenderState(vid, quad_model, tex0_program, quad_uniform_set_value_list, quad_uniform_set_texture_list, quad_matrix, quad_render_state) + } + hg.Frame() + + hg.OpenXRFinishSubmitFrameBuffer(openxrFrameInfo) + + hg.UpdateWindow(win) + } + + hg.DestroyForwardPipeline(pipeline) + hg.RenderShutdown() + hg.DestroyWindow(win) +} diff --git a/scene_xr.lua b/scene_xr.lua new file mode 100644 index 0000000..7be24fb --- /dev/null +++ b/scene_xr.lua @@ -0,0 +1,132 @@ +-- Display a scene in XR + +hg = require("harfang") + +hg.InputInit() +hg.WindowSystemInit() + +res_x, res_y = 1280, 720 +win = hg.RenderInit("Harfang - OpenXR Scene", res_x, res_y, hg.RF_None) + +hg.AddAssetsFolder("resources_compiled") + +pipeline = hg.CreateForwardPipeline() +res = hg.PipelineResources() + +render_data = hg.SceneForwardPipelineRenderData() -- this object is used by the low-level scene rendering API to share view-independent data with both eyes + +-- OpenXR initialization +if not hg.OpenXRInit() then + os.exit() +end + +eye_framebuffers = hg.OpenXRCreateEyeFrameBuffer(hg.OXRAA_MSAA4x) + +-- Create models +vtx_layout = hg.VertexLayoutPosFloatNormUInt8() + +cube_mdl = hg.CreateCubeModel(vtx_layout, 1, 1, 1) +cube_ref = res.AddModel('cube', cube_mdl) +ground_mdl = hg.CreateCubeModel(vtx_layout, 50, 0.01, 50) +ground_ref = res.AddModel('ground', ground_mdl) + +-- Load shader +prg_ref = hg.LoadPipelineProgramRefFromAssets('core/shader/pbr.hps', res, hg.GetForwardPipelineInfo()) + +-- Create materials +function create_material(ubc, orm) + mat = hg.Material() + hg.SetMaterialProgram(mat, prg_ref) + hg.SetMaterialValue(mat, "uBaseOpacityColor", ubc) + hg.SetMaterialValue(mat, "uOcclusionRoughnessMetalnessColor", orm) + return mat +end + +-- Create scene +scene = hg.Scene() +scene.canvas.color = hg.Color(255 / 255, 255 / 255, 217 / 255, 1) +scene.environment.ambient = hg.Color(15 / 255, 12 / 255, 9 / 255, 1) + +lgt = hg.CreateSpotLight(scene, hg.TransformationMat4(hg.Vec3(-8, 4, -5), hg.Vec3(hg.Deg(19), hg.Deg(59), 0)), 0, hg.Deg(5), hg.Deg(30), hg.Color.White, hg.Color.White, 10, hg.LST_Map, 0.0001) +back_lgt = hg.CreatePointLight(scene, hg.TranslationMat4(hg.Vec3(2.4, 1, 0.5)), 10, hg.Color(94 / 255, 255 / 255, 228 / 255, 1), hg.Color(94 / 255, 1, 228 / 255, 1), 0) + +mat_cube = create_material(hg.Vec4(255 / 255, 230 / 255, 20 / 255, 1), hg.Vec4(1, 0.658, 0., 1)) +hg.CreateObject(scene, hg.TransformationMat4(hg.Vec3(0, 0.5, 0), hg.Vec3(0, hg.Deg(70), 0)), cube_ref, {mat_cube}) + +mat_ground = create_material(hg.Vec4(255 / 255, 120 / 255, 147 / 255, 1), hg.Vec4(1, 1, 0.1, 1)) +hg.CreateObject(scene, hg.TranslationMat4(hg.Vec3(0, 0, 0)), ground_ref, {mat_ground}) + +-- Setup 2D rendering to display eyes textures +quad_layout = hg.VertexLayout() +quad_layout:Begin():Add(hg.A_Position, 3, hg.AT_Float):Add(hg.A_TexCoord0, 3, hg.AT_Float):End() + +quad_model = hg.CreatePlaneModel(quad_layout, 1, 1, 1, 1) +quad_render_state = hg.ComputeRenderState(hg.BM_Alpha, hg.DT_Disabled, hg.FC_Disabled) + +eye_t_size = res_x / 2.5 +eye_t_x = (res_x - 2 * eye_t_size) / 6 + eye_t_size / 2 +quad_matrix = hg.TransformationMat4(hg.Vec3(0, 0, 0), hg.Vec3(hg.Deg(90), hg.Deg(0), hg.Deg(0)), hg.Vec3(eye_t_size, 1, eye_t_size)) + +tex0_program = hg.LoadProgramFromAssets("shaders/sprite") + +quad_uniform_set_value_list = hg.UniformSetValueList() +quad_uniform_set_value_list:clear() +quad_uniform_set_value_list:push_back(hg.MakeUniformSetValue("color", hg.Vec4(1, 1, 1, 1))) + +quad_uniform_set_texture_list = hg.UniformSetTextureList() + +-- Main loop +while not hg.ReadKeyboard():Key(hg.K_Escape) and hg.IsWindowOpen(win) do + dt = hg.TickClock() + + scene:Update(dt) + + actor_body_mtx = hg.TransformationMat4(hg.Vec3(-1.3, .45, -2), hg.Vec3(0, 0, 0)) + + vid = 0 -- keep track of the next free view id + passId = hg.SceneForwardPipelinePassViewId() + + -- Prepare view-independent render data once + vid, passId = hg.PrepareSceneForwardPipelineCommonRenderData(vid, scene, render_data, pipeline, res, passId) + + function update_controllers(head) + -- pass + end + + function draw_scene(rect, view_state, view_id, fb) + passId = hg.SceneForwardPipelinePassViewId() + view_id, passId = hg.PrepareSceneForwardPipelineViewDependentRenderData(view_id, view_state, scene, render_data, pipeline, res, passId) + view_id, passId = hg.SubmitSceneToForwardPipeline(view_id, scene, rect, view_state, pipeline, render_data, res, fb) + + return view_id + end + + openxrFrameInfo, vid = hg.OpenXRSubmitSceneToForwardPipeline(hg.TranslationMat4(hg.Vec3(0, 0, 0)), update_controllers, draw_scene, vid, 0.1, 100) + + -- Display the VR eyes texture to the backbuffer + hg.SetViewRect(vid, 0, 0, res_x, res_y) + vs = hg.ComputeOrthographicViewState(hg.TranslationMat4(hg.Vec3(0, 0, 0)), res_y, 0.1, 100, hg.ComputeAspectRatioX(res_x, res_y)) + hg.SetViewTransform(vid, vs.view, vs.proj) + + if openxrFrameInfo.id_fbs.size() > 0 then + quad_uniform_set_texture_list:clear() + quad_uniform_set_texture_list:push_back(hg.MakeUniformSetTexture("s_tex", hg.OpenXRGetColorTextureFromId(eye_framebuffers, openxrFrameInfo, 0), 0)) + hg.SetT(quad_matrix, hg.Vec3(eye_t_x, 0, 1)) + hg.DrawModel(vid, quad_model, tex0_program, quad_uniform_set_value_list, quad_uniform_set_texture_list, quad_matrix, quad_render_state) + + quad_uniform_set_texture_list:clear() + quad_uniform_set_texture_list:push_back(hg.MakeUniformSetTexture("s_tex", hg.OpenXRGetColorTextureFromId(eye_framebuffers, openxrFrameInfo, 1), 0)) + hg.SetT(quad_matrix, hg.Vec3(-eye_t_x, 0, 1)) + hg.DrawModel(vid, quad_model, tex0_program, quad_uniform_set_value_list, quad_uniform_set_texture_list, quad_matrix, quad_render_state) + end + + hg.Frame() + + hg.OpenXRFinishSubmitFrameBuffer(openxrFrameInfo) + + hg.UpdateWindow(win) +end + +hg.DestroyForwardPipeline(pipeline) +hg.RenderShutdown() +hg.DestroyWindow(win) diff --git a/scene_xr.py b/scene_xr.py new file mode 100644 index 0000000..0d35e8d --- /dev/null +++ b/scene_xr.py @@ -0,0 +1,128 @@ +# Display a scene in XR + +import harfang as hg +import sys + +hg.InputInit() +hg.WindowSystemInit() + +res_x, res_y = 1280, 720 +win = hg.RenderInit("Harfang - OpenXR Scene", res_x, res_y, hg.RF_None) + +hg.AddAssetsFolder("resources_compiled") + +pipeline = hg.CreateForwardPipeline() +res = hg.PipelineResources() + +render_data = hg.SceneForwardPipelineRenderData() # this object is used by the low-level scene rendering API to share view-independent data with both eyes + +# OpenXR initialization +if not hg.OpenXRInit(): + sys.exit() + +eye_framebuffers = hg.OpenXRCreateEyeFrameBuffer(hg.OXRAA_MSAA4x) + +# Create models +vtx_layout = hg.VertexLayoutPosFloatNormUInt8() + +cube_mdl = hg.CreateCubeModel(vtx_layout, 1, 1, 1) +cube_ref = res.AddModel('cube', cube_mdl) +ground_mdl = hg.CreateCubeModel(vtx_layout, 50, 0.01, 50) +ground_ref = res.AddModel('ground', ground_mdl) + +# Load shader +prg_ref = hg.LoadPipelineProgramRefFromAssets('core/shader/pbr.hps', res, hg.GetForwardPipelineInfo()) + +# Create materials +def create_material(ubc, orm): + mat = hg.Material() + hg.SetMaterialProgram(mat, prg_ref) + hg.SetMaterialValue(mat, "uBaseOpacityColor", ubc) + hg.SetMaterialValue(mat, "uOcclusionRoughnessMetalnessColor", orm) + return mat + + +# Create scene +scene = hg.Scene() +scene.canvas.color = hg.Color(255 / 255, 255 / 255, 217 / 255, 1) +scene.environment.ambient = hg.Color(15 / 255, 12 / 255, 9 / 255, 1) + +lgt = hg.CreateSpotLight(scene, hg.TransformationMat4(hg.Vec3(-8, 4, -5), hg.Vec3(hg.Deg(19), hg.Deg(59), 0)), 0, hg.Deg(5), hg.Deg(30), hg.Color.White, hg.Color.White, 10, hg.LST_Map, 0.0001) +back_lgt = hg.CreatePointLight(scene, hg.TranslationMat4(hg.Vec3(2.4, 1, 0.5)), 10, hg.Color(94 / 255, 255 / 255, 228 / 255, 1), hg.Color(94 / 255, 1, 228 / 255, 1), 0) + +mat_cube = create_material(hg.Vec4(255 / 255, 230 / 255, 20 / 255, 1), hg.Vec4(1, 0.658, 0., 1)) +hg.CreateObject(scene, hg.TransformationMat4(hg.Vec3(0, 0.5, 0), hg.Vec3(0, hg.Deg(70), 0)), cube_ref, [mat_cube]) + +mat_ground = create_material(hg.Vec4(255 / 255, 120 / 255, 147 / 255, 1), hg.Vec4(1, 1, 0.1, 1)) +hg.CreateObject(scene, hg.TranslationMat4(hg.Vec3(0, 0, 0)), ground_ref, [mat_ground]) + +# Setup 2D rendering to display eyes textures +quad_layout = hg.VertexLayout() +quad_layout.Begin().Add(hg.A_Position, 3, hg.AT_Float).Add(hg.A_TexCoord0, 3, hg.AT_Float).End() + +quad_model = hg.CreatePlaneModel(quad_layout, 1, 1, 1, 1) +quad_render_state = hg.ComputeRenderState(hg.BM_Alpha, hg.DT_Disabled, hg.FC_Disabled) + +eye_t_size = res_x / 2.5 +eye_t_x = (res_x - 2 * eye_t_size) / 6 + eye_t_size / 2 +quad_matrix = hg.TransformationMat4(hg.Vec3(0, 0, 0), hg.Vec3(hg.Deg(90), hg.Deg(0), hg.Deg(0)), hg.Vec3(eye_t_size, 1, eye_t_size)) + +tex0_program = hg.LoadProgramFromAssets("shaders/sprite") + +quad_uniform_set_value_list = hg.UniformSetValueList() +quad_uniform_set_value_list.clear() +quad_uniform_set_value_list.push_back(hg.MakeUniformSetValue("color", hg.Vec4(1, 1, 1, 1))) + +quad_uniform_set_texture_list = hg.UniformSetTextureList() + +# Main loop +while not hg.ReadKeyboard().Key(hg.K_Escape) and hg.IsWindowOpen(win): + dt = hg.TickClock() + + scene.Update(dt) + + actor_body_mtx = hg.TransformationMat4(hg.Vec3(-1.3, .45, -2), hg.Vec3(0, 0, 0)) + + vid = 0 # keep track of the next free view id + passId = hg.SceneForwardPipelinePassViewId() + + # Prepare view-independent render data once + vid, passId = hg.PrepareSceneForwardPipelineCommonRenderData(vid, scene, render_data, pipeline, res, passId) + + def update_controllers(head): + pass + + def draw_scene(rect, view_state, view_id, fb): + passId = hg.SceneForwardPipelinePassViewId() + view_id, passId = hg.PrepareSceneForwardPipelineViewDependentRenderData(view_id, view_state, scene, render_data, pipeline, res, passId) + view_id, passId = hg.SubmitSceneToForwardPipeline(view_id, scene, rect, view_state, pipeline, render_data, res, fb) + + return view_id + + openxrFrameInfo, vid = hg.OpenXRSubmitSceneToForwardPipeline(hg.TranslationMat4(hg.Vec3(0, 0, 0)), update_controllers, draw_scene, vid, 0.1, 100) + + # Display the VR eyes texture to the backbuffer + hg.SetViewRect(vid, 0, 0, res_x, res_y) + vs = hg.ComputeOrthographicViewState(hg.TranslationMat4(hg.Vec3(0, 0, 0)), res_y, 0.1, 100, hg.ComputeAspectRatioX(res_x, res_y)) + hg.SetViewTransform(vid, vs.view, vs.proj) + + if openxrFrameInfo.id_fbs.size() > 0 : + quad_uniform_set_texture_list.clear() + quad_uniform_set_texture_list.push_back(hg.MakeUniformSetTexture("s_tex", hg.OpenXRGetColorTextureFromId(eye_framebuffers, openxrFrameInfo, 0), 0)) + hg.SetT(quad_matrix, hg.Vec3(eye_t_x, 0, 1)) + hg.DrawModel(vid, quad_model, tex0_program, quad_uniform_set_value_list, quad_uniform_set_texture_list, quad_matrix, quad_render_state) + + quad_uniform_set_texture_list.clear() + quad_uniform_set_texture_list.push_back(hg.MakeUniformSetTexture("s_tex", hg.OpenXRGetColorTextureFromId(eye_framebuffers, openxrFrameInfo, 1), 0)) + hg.SetT(quad_matrix, hg.Vec3(-eye_t_x, 0, 1)) + hg.DrawModel(vid, quad_model, tex0_program, quad_uniform_set_value_list, quad_uniform_set_texture_list, quad_matrix, quad_render_state) + + hg.Frame() + + hg.OpenXRFinishSubmitFrameBuffer(openxrFrameInfo) + + hg.UpdateWindow(win) + +hg.DestroyForwardPipeline(pipeline) +hg.RenderShutdown() +hg.DestroyWindow(win)