From 446d8548a61edc3b7b8e9e9abbbf7b43d8a93d2e Mon Sep 17 00:00:00 2001 From: Astrofra Date: Wed, 15 Dec 2021 14:03:39 +0100 Subject: [PATCH] Tutorials update for HARFANG v3.1.0: - Updated the code according to the v3.1.0 of the HARFANG API. - Fixed an upscale shader bug in the AAA rendering pipeline. - File cleanup. --- .vscode/launch.json | 50 +++++++++---------- README.md | 4 +- ...o_pipeline.py => draw_model_no_pipeline.py | 0 filesystem_recursive_directory_listing.lua | 2 +- game_mouse_flight.py | 2 +- resources/core/shader/aaa_upsample_fs.sc | 2 +- scene_draw_to_texture.lua | 5 +- scene_draw_to_texture.py | 5 +- scene_instances.lua | 1 - scene_instances.py | 2 +- 10 files changed, 37 insertions(+), 36 deletions(-) rename draw_models_no_pipeline.py => draw_model_no_pipeline.py (100%) diff --git a/.vscode/launch.json b/.vscode/launch.json index 47e78e3..8aae0ce 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,25 +1,25 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Python: Current File", - "type": "python", - "request": "launch", - "program": "${file}", - "cwd": "${workspaceFolder}/", - "console": "integratedTerminal" - }, - { - "name": "Lua: Current File", - "type": "lua", - "request": "launch", - "stopOnEntry": false, - "program": "${file}", - "cwd": "${workspaceFolder}/", - "luaexe": "${workspaceFolder}/_bin/lua.exe", - } - ] -} +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "cwd": "${workspaceFolder}/", + "console": "integratedTerminal" + }, + { + "name": "Lua: Current File", + "type": "lua", + "request": "launch", + "stopOnEntry": false, + "program": "${file}", + "cwd": "${workspaceFolder}/", + "luaexe": "${workspaceFolder}/_bin/lua.exe", + } + ] +} diff --git a/README.md b/README.md index 2ea7d62..3fac490 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# HARFANG® 3.0 Tutorials +# HARFANG® 3.1.0 Tutorials -These **tutorials** demonstrate the usage of the HARFANG 3.0 API in **Python** and **Lua**. +These **tutorials** demonstrate the usage of the HARFANG 3.1.0 API in **Python** and **Lua**. To run the tutorials: diff --git a/draw_models_no_pipeline.py b/draw_model_no_pipeline.py similarity index 100% rename from draw_models_no_pipeline.py rename to draw_model_no_pipeline.py diff --git a/filesystem_recursive_directory_listing.lua b/filesystem_recursive_directory_listing.lua index 9631353..4a94124 100644 --- a/filesystem_recursive_directory_listing.lua +++ b/filesystem_recursive_directory_listing.lua @@ -10,7 +10,7 @@ end entries = hg.ListDirRecursive('resources', hg.DE_All) -for i=0, entries:size() do +for i=0, entries:size()-1 do entry = entries:at(i) print(string.format('- %s is a %s', entry.name, entry_type_to_string(entry.type))) end \ No newline at end of file diff --git a/game_mouse_flight.py b/game_mouse_flight.py index 50b036a..27dfe68 100644 --- a/game_mouse_flight.py +++ b/game_mouse_flight.py @@ -55,7 +55,7 @@ def draw_circle(view_id, center, radius, color): scene = hg.Scene() hg.LoadSceneFromAssets('playground/playground.scn', scene, res, hg.GetForwardPipelineInfo()) -plane_node = hg.CreateInstanceFromAssets(scene, hg.TranslationMat4(hg.Vec3(0, 4, 0)), 'paper_plane/paper_plane.scn', res, hg.GetForwardPipelineInfo()) +plane_node, _ = hg.CreateInstanceFromAssets(scene, hg.TranslationMat4(hg.Vec3(0, 4, 0)), 'paper_plane/paper_plane.scn', res, hg.GetForwardPipelineInfo()) camera_node = hg.CreateCamera(scene, hg.TranslationMat4(hg.Vec3(0, 4, -5)), 0.01, 1000) scene.SetCurrentCamera(camera_node) diff --git a/resources/core/shader/aaa_upsample_fs.sc b/resources/core/shader/aaa_upsample_fs.sc index 5dc60af..792d52c 100644 --- a/resources/core/shader/aaa_upsample_fs.sc +++ b/resources/core/shader/aaa_upsample_fs.sc @@ -9,7 +9,7 @@ float gaussian(float v, float sigma) { } void main() { - vec2 ratio = floor(textureSize(u_attr_hi, 0).xy / textureSize(u_attr_lo, 0).xy); + vec2 ratio = round(textureSize(u_attr_hi, 0).xy / textureSize(u_attr_lo, 0).xy); vec2 pixel = gl_FragCoord.xy / ratio; vec2 tmp = floor(pixel-vec2_splat(0.5)) + vec2_splat(0.5); ivec2 coord = ivec2(tmp); diff --git a/scene_draw_to_texture.lua b/scene_draw_to_texture.lua index dcf56d0..e58cdd3 100644 --- a/scene_draw_to_texture.lua +++ b/scene_draw_to_texture.lua @@ -19,7 +19,8 @@ scene = hg.Scene() hg.LoadSceneFromAssets("materials/materials.scn", scene, res, hg.GetForwardPipelineInfo()) -- create a 512x512 frame buffer to draw the scene to -frame_buffer = hg.CreateFrameBuffer(512, 512, hg.TF_RGBA32F, hg.TF_D24, 8, res, 'framebuffer') -- 8x MSAA +frame_buffer = hg.CreateFrameBuffer(512, 512, hg.TF_RGBA32F, hg.TF_D24, 8, 'framebuffer') -- 8x MSAA +color = hg.GetColorTexture(frame_buffer) -- create the cube model vtx_layout = hg.VertexLayoutPosFloatNormUInt8TexCoord0UInt8() @@ -49,7 +50,7 @@ while not hg.ReadKeyboard():Key(hg.K_Escape) do hg.SetViewPerspective(view_id, 0, 0, res_x, res_y, hg.TranslationMat4(hg.Vec3(0, 0, -1.8))) val_uniforms = {hg.MakeUniformSetValue('color', hg.Vec4(1, 1, 1, 1))} -- note: these could be moved out of the main loop but are kept here for readability - tex_uniforms = {hg.MakeUniformSetTexture('s_tex', res:GetTexture(frame_buffer.color), 0)} + tex_uniforms = {hg.MakeUniformSetTexture('s_tex', color, 0)} hg.DrawModel(view_id, cube_mdl, cube_prg, val_uniforms, tex_uniforms, hg.TransformationMat4(hg.Vec3(0, 0, 0), hg.Vec3(angle * 0.1, angle * 0.05, angle * 0.2))) diff --git a/scene_draw_to_texture.py b/scene_draw_to_texture.py index 4926f84..d108b8d 100644 --- a/scene_draw_to_texture.py +++ b/scene_draw_to_texture.py @@ -20,7 +20,8 @@ hg.LoadSceneFromAssets("materials/materials.scn", scene, res, hg.GetForwardPipelineInfo()) # create a 512x512 frame buffer to draw the scene to -frame_buffer = hg.CreateFrameBuffer(512, 512, hg.TF_RGBA32F, hg.TF_D24, 8, res, 'framebuffer') # 8x MSAA +frame_buffer = hg.CreateFrameBuffer(512, 512, hg.TF_RGBA32F, hg.TF_D24, 8, 'framebuffer') # 8x MSAA +color = hg.GetColorTexture(frame_buffer) # create the cube model vtx_layout = hg.VertexLayoutPosFloatNormUInt8TexCoord0UInt8() @@ -50,7 +51,7 @@ hg.SetViewPerspective(view_id, 0, 0, res_x, res_y, hg.TranslationMat4(hg.Vec3(0, 0, -1.8))) val_uniforms = [hg.MakeUniformSetValue('color', hg.Vec4(1, 1, 1, 1))] # note: these could be moved out of the main loop but are kept here for readability - tex_uniforms = [hg.MakeUniformSetTexture('s_tex', res.GetTexture(frame_buffer.color), 0)] + tex_uniforms = [hg.MakeUniformSetTexture('s_tex', color, 0)] hg.DrawModel(view_id, cube_mdl, cube_prg, val_uniforms, tex_uniforms, hg.TransformationMat4(hg.Vec3(0, 0, 0), hg.Vec3(angle * 0.1, angle * 0.05, angle * 0.2))) diff --git a/scene_instances.lua b/scene_instances.lua index 60164fd..ebfe8ef 100644 --- a/scene_instances.lua +++ b/scene_instances.lua @@ -114,7 +114,6 @@ while not keyboard:Pressed(hg.K_Escape) do dt = hg.TickClock() for i, actor in ipairs(actors) do - print(actor) actor:update(dt) end diff --git a/scene_instances.py b/scene_instances.py index c14f8d4..44905d9 100644 --- a/scene_instances.py +++ b/scene_instances.py @@ -22,7 +22,7 @@ # declare the biped actor class class BipedActor: def __init__(self, pos): - self.__node = hg.CreateInstanceFromAssets(scene, hg.Mat4.Identity, "biped/biped.scn", res, hg.GetForwardPipelineInfo()) + self.__node, _ = hg.CreateInstanceFromAssets(scene, hg.Mat4.Identity, "biped/biped.scn", res, hg.GetForwardPipelineInfo()) self.__node.GetTransform().SetPosRot(pos, hg.Deg3(0, hg.FRand(360), 0)) self.__delay = 0