diff --git a/app/main.py b/app/main.py index 00dfd6b..bc28f41 100644 --- a/app/main.py +++ b/app/main.py @@ -9,6 +9,8 @@ str_error = "The robot is not connected" # helpers + + def clamp(v, v_min, v_max): return max(v_min, min(v, v_max)) @@ -24,6 +26,7 @@ def rangeadjust(k, a, b, u, v): def lerp(k, a, b): return a + (b - a) * k + # look for the poppy on the network url = "" try: @@ -40,15 +43,18 @@ def lerp(k, a, b): res_x, res_y = 1920, 1080 -#initialize lists and variables for toggle button (swipe style) +# initialize lists and variables for toggle button (swipe style) mousexlist = [] mouseylist = [] has_switched = False compliance_mode = False +compliance_lerp = True -win = hg.NewWindow("Harfang - Poppy", res_x, res_y, 32)#, hg.WV_Fullscreen) + +win = hg.NewWindow("Harfang - Poppy", res_x, res_y, 32) # , hg.WV_Fullscreen) hg.RenderInit(win) -hg.RenderReset(res_x, res_y, hg.RF_MSAA8X | hg.RF_FlipAfterRender | hg.RF_FlushAfterRender | hg.RF_MaxAnisotropy) +hg.RenderReset(res_x, res_y, hg.RF_MSAA8X | hg.RF_FlipAfterRender | + hg.RF_FlushAfterRender | hg.RF_MaxAnisotropy) hg.AddAssetsFolder("resources_compiled") @@ -85,9 +91,12 @@ def lerp(k, a, b): # load shaders -render_state_quad = hg.ComputeRenderState(hg.BM_Alpha, hg.DT_Less, hg.FC_Disabled) -render_state_quad_occluded = hg.ComputeRenderState(hg.BM_Alpha, hg.DT_Less, hg.FC_Disabled) -render_state_line = hg.ComputeRenderState(hg.BM_Opaque, hg.DT_Less, hg.FC_Disabled) +render_state_quad = hg.ComputeRenderState( + hg.BM_Alpha, hg.DT_Less, hg.FC_Disabled) +render_state_quad_occluded = hg.ComputeRenderState( + hg.BM_Alpha, hg.DT_Less, hg.FC_Disabled) +render_state_line = hg.ComputeRenderState( + hg.BM_Opaque, hg.DT_Less, hg.FC_Disabled) shader_rotator = hg.LoadProgramFromAssets("shaders/rotator") shader_for_plane = hg.LoadProgramFromAssets("shaders/texture") shader_for_line = hg.LoadProgramFromAssets("shaders/pos_rgb") @@ -96,22 +105,33 @@ def lerp(k, a, b): vtx_line_layout = hg.VertexLayoutPosFloatColorUInt8() # load font -font = hg.LoadFontFromAssets("Roboto-Regular.ttf", 36, 1024, 1, "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ") -text_render_state = hg.ComputeRenderState(hg.BM_Alpha, hg.DT_Always, hg.FC_Disabled, False) +font = hg.LoadFontFromAssets("Roboto-Regular.ttf", 36, 1024, 1, + "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ") +text_render_state = hg.ComputeRenderState( + hg.BM_Alpha, hg.DT_Always, hg.FC_Disabled, False) font_color = hg.MakeUniformSetValue("u_color", hg.Vec4(1.0, 0.75, 0.2, 1.0)) -font_color_white = hg.MakeUniformSetValue("u_color", hg.Vec4(1.0, 1.0, 1.0, 1.0)) +font_color_white = hg.MakeUniformSetValue( + "u_color", hg.Vec4(1.0, 1.0, 1.0, 1.0)) font_shadow = hg.MakeUniformSetValue("u_color", hg.Vec4(0.0, 0.0, 0.0, 1.0)) # array for each motor node and rotation axis choice hg_motors = [ - {"n": scene.GetNode("bras_1"), "acc": 0, "v": 0, "axis": "Y", "lower_limit": -150, "upper_limit": 150, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel(vtx_layout, 0.12, 0.12, 1, 1), "offset_slider": hg.Vec3(0, 0, 1), "offset_rotation": hg.Vec3(0, 0, 0), "axis_tex_big": True}, - {"n": scene.GetNode("bras_2"), "acc": 0, "v": 0, "axis": "X", "lower_limit": 90, "upper_limit": -125, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel(vtx_layout, 0.03, 0.03, 1, 1), "offset_slider": hg.Vec3(1, 0, 0), "offset_rotation": hg.Vec3(-1.57, 1.57, 0), "axis_tex_big": False}, - {"n": scene.GetNode("bras_3"), "acc": 0, "v": 0, "axis": "X", "lower_limit": 90, "upper_limit": -90, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel(vtx_layout, 0.03, 0.03, 1, 1), "offset_slider": hg.Vec3(1, 0, 0), "offset_rotation": hg.Vec3(-1.57, 1.57, 0), "axis_tex_big": False}, - {"n": scene.GetNode("bras_4"), "acc": 0, "v": 0, "axis": "Z", "lower_limit": -150, "upper_limit": 150, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel(vtx_layout, 0.06, 0.06, 1, 1), "offset_slider": hg.Vec3(0, 1, 0), "offset_rotation": hg.Vec3(0, 0, 0), "axis_tex_big": True}, - {"n": scene.GetNode("bras_5"), "acc": 0, "v": 0, "axis": "X", "lower_limit": 90, "upper_limit": -90, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel(vtx_layout, 0.03, 0.03, 1, 1), "offset_slider": hg.Vec3(1, 0, 0), "offset_rotation": hg.Vec3(-1.57, 0, 1.57), "axis_tex_big": False}, - {"n": scene.GetNode("bras_6"), "acc": 0, "v": 0, "axis": "X", "lower_limit": 110, "upper_limit": -90, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel(vtx_layout, 0.03, 0.03, 1, 1), "offset_slider": hg.Vec3(1, 0, 0), "offset_rotation": hg.Vec3(-1.57, 0, 1.57), "axis_tex_big": False}, + {"n": scene.GetNode("bras_1"), "acc": 0, "v": 0, "axis": "Y", "lower_limit": -150, "upper_limit": 150, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel( + vtx_layout, 0.12, 0.12, 1, 1), "offset_slider": hg.Vec3(0, 0, 1), "offset_rotation": hg.Vec3(0, 0, 0), "axis_tex_big": True}, + {"n": scene.GetNode("bras_2"), "acc": 0, "v": 0, "axis": "X", "lower_limit": 90, "upper_limit": -125, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel( + vtx_layout, 0.03, 0.03, 1, 1), "offset_slider": hg.Vec3(1, 0, 0), "offset_rotation": hg.Vec3(-1.57, 1.57, 0), "axis_tex_big": False}, + {"n": scene.GetNode("bras_3"), "acc": 0, "v": 0, "axis": "X", "lower_limit": 90, "upper_limit": -90, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel( + vtx_layout, 0.03, 0.03, 1, 1), "offset_slider": hg.Vec3(1, 0, 0), "offset_rotation": hg.Vec3(-1.57, 1.57, 0), "axis_tex_big": False}, + {"n": scene.GetNode("bras_4"), "acc": 0, "v": 0, "axis": "Z", "lower_limit": -150, "upper_limit": 150, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel( + vtx_layout, 0.06, 0.06, 1, 1), "offset_slider": hg.Vec3(0, 1, 0), "offset_rotation": hg.Vec3(0, 0, 0), "axis_tex_big": True}, + {"n": scene.GetNode("bras_5"), "acc": 0, "v": 0, "axis": "X", "lower_limit": 90, "upper_limit": -90, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel( + vtx_layout, 0.03, 0.03, 1, 1), "offset_slider": hg.Vec3(1, 0, 0), "offset_rotation": hg.Vec3(-1.57, 0, 1.57), "axis_tex_big": False}, + {"n": scene.GetNode("bras_6"), "acc": 0, "v": 0, "axis": "X", "lower_limit": 110, "upper_limit": -90, "new_position": 0.0, "quad_jauge_axis": hg.CreatePlaneModel( + vtx_layout, 0.03, 0.03, 1, 1), "offset_slider": hg.Vec3(1, 0, 0), "offset_rotation": hg.Vec3(-1.57, 0, 1.57), "axis_tex_big": False}, ] +hg_motors_previous = [[0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]] + led_colors = [ "off", "red", @@ -140,7 +160,8 @@ def lerp(k, a, b): cam = scene.CreateNode() cam.SetName("Camera") cam.SetTransform(scene.CreateTransform()) - cam.GetTransform().SetWorld(hg.TransformationMat4(hg.Vec3(0, 1000, 0), hg.Vec3(0, 0, 0))) + cam.GetTransform().SetWorld(hg.TransformationMat4( + hg.Vec3(0, 1000, 0), hg.Vec3(0, 0, 0))) cam.SetCamera(scene.CreateCamera(0.1, 10000)) scene.SetCurrentCamera(cam) @@ -157,22 +178,28 @@ def lerp(k, a, b): app_clock = 0 app_status = "dancing" + def toggle_button(label, value, x, y): global has_switched - mat = hg.TransformationMat4(hg.Vec3(x, y, 1), hg.Vec3(0, 0, 0), hg.Vec3(1, 1, 1)) + mat = hg.TransformationMat4( + hg.Vec3(x, y, 1), hg.Vec3(0, 0, 0), hg.Vec3(1, 1, 1)) pos = hg.GetT(mat) axis_x = hg.GetX(mat) * 56 axis_y = hg.GetY(mat) * 24 toggle_vtx = hg.Vertices(vtx_layout, 4) - toggle_vtx.Begin(0).SetPos(pos - axis_x - axis_y).SetTexCoord0(hg.Vec2(0, 1)).End() - toggle_vtx.Begin(1).SetPos(pos - axis_x + axis_y).SetTexCoord0(hg.Vec2(0, 0)).End() - toggle_vtx.Begin(2).SetPos(pos + axis_x + axis_y).SetTexCoord0(hg.Vec2(1, 0)).End() - toggle_vtx.Begin(3).SetPos(pos + axis_x - axis_y).SetTexCoord0(hg.Vec2(1, 1)).End() + toggle_vtx.Begin(0).SetPos( + pos - axis_x - axis_y).SetTexCoord0(hg.Vec2(0, 1)).End() + toggle_vtx.Begin(1).SetPos( + pos - axis_x + axis_y).SetTexCoord0(hg.Vec2(0, 0)).End() + toggle_vtx.Begin(2).SetPos( + pos + axis_x + axis_y).SetTexCoord0(hg.Vec2(1, 0)).End() + toggle_vtx.Begin(3).SetPos( + pos + axis_x - axis_y).SetTexCoord0(hg.Vec2(1, 1)).End() toggle_idx = [0, 3, 2, 0, 2, 1] - - hg.DrawTriangles(view_id, toggle_idx, toggle_vtx, shader_for_plane, [], [texture_on if value else texture_off], render_state_quad) + hg.DrawTriangles(view_id, toggle_idx, toggle_vtx, shader_for_plane, [], [ + texture_on if value else texture_off], render_state_quad) if mouse.Down(hg.MB_0): mousexlist.append(mouse.X()) @@ -205,20 +232,25 @@ def toggle_button(label, value, x, y): [font_color_white], [], text_render_state) return value + buttonlist = [[100, res_y - 80]] + def is_switching(): for i in buttonlist: - mat = hg.TransformationMat4(hg.Vec3(i[0], i[1], 1), hg.Vec3(0, 0, 0), hg.Vec3(1, 1, 1)) + mat = hg.TransformationMat4( + hg.Vec3(i[0], i[1], 1), hg.Vec3(0, 0, 0), hg.Vec3(1, 1, 1)) pos = hg.GetT(mat) axis_x = hg.GetX(mat) * 56 axis_y = hg.GetY(mat) * 24 - if (mouse.X() > pos.x - axis_x.x - 10 and mouse.X() < pos.x + axis_x.x + 10 and mouse.Y() > pos.y - axis_y.y - 10 and mouse.Y() < pos.y + axis_y.y + 10 and mouse.Down(hg.MB_0)): # check if mouse is clicked and is within the button area + 10px on every side - return True + # check if mouse is clicked and is within the button area + 10px on every side + if (mouse.X() > pos.x - axis_x.x - 10 and mouse.X() < pos.x + axis_x.x + 10 and mouse.Y() > pos.y - axis_y.y - 10 and mouse.Y() < pos.y + axis_y.y + 10 and mouse.Down(hg.MB_0)): + return True return False + def get_v_from_dancing(id_robot): - elapsed_time = app_clock *0.5 + elapsed_time = app_clock * 0.5 _amp = 1 _freq = 0.5 _offset = 0 @@ -245,6 +277,7 @@ def get_v_from_dancing(id_robot): """ Compute the sin(t) where t is the elapsed time since the primitive has been started. """ return _amp * math.sin(_freq * 2.0 * math.pi * elapsed_time + _phase * math.pi / 180.0) + _offset + # send value if url != "": try: @@ -261,24 +294,28 @@ def get_v_from_dancing(id_robot): app_clock += hg.time_to_sec_f(dt) - render_was_reset, res_x, res_y = hg.RenderResetToWindow(win, res_x, res_y, hg.RF_VSync | hg.RF_MSAA4X | hg.RF_MaxAnisotropy) + render_was_reset, res_x, res_y = hg.RenderResetToWindow( + win, res_x, res_y, hg.RF_VSync | hg.RF_MSAA4X | hg.RF_MaxAnisotropy) res_y = max(res_y, 16) - + if not is_switching(): - world, cam_rot, cam_tgt, cam_pos = OrbitalController(keyboard, mouse, cam_pos, cam_rot, cam_tgt, dt, res_x, res_y) + world, cam_rot, cam_tgt, cam_pos = OrbitalController( + keyboard, mouse, cam_pos, cam_rot, cam_tgt, dt, res_x, res_y) cam.GetTransform().SetWorld(world) scene.Update(dt) new_pass_views = hg.SceneForwardPipelinePassViewId() view_id = 0 - view_id, pass_ids = hg.SubmitSceneToPipeline(view_id, scene, hg.IntRect(0, 0, res_x, res_y), True, pipeline, res, pipeline_aaa, aaa_config, current_frame) + view_id, pass_ids = hg.SubmitSceneToPipeline(view_id, scene, hg.IntRect( + 0, 0, res_x, res_y), True, pipeline, res, pipeline_aaa, aaa_config, current_frame) - view_state = scene.ComputeCurrentCameraViewState(hg.ComputeAspectRatioX(res_x, res_y)) + view_state = scene.ComputeCurrentCameraViewState( + hg.ComputeAspectRatioX(res_x, res_y)) # api poppy url_set_motor_pos_registers = url + "/motors/set/registers/" url_set_motor_pos = url + "/motors/set/goto/" - send_dt = 1/10 # send information to the poppy every send_dt + send_dt = 1/10 # send information to the poppy every send_dt # get values from the real robot if compliance_mode: @@ -291,8 +328,12 @@ def get_v_from_dancing(id_robot): r = requests.get(url + "/motors/get/positions").text for id, m in enumerate(hg_motors): hg_m = hg_motors[id] + hg_motors_previous[id][0] = hg_m["v"] + hg_motors_previous[id][1] = hg.GetClock() hg_m["v"] = float(r.split(';')[id]) - if id==5: hg_m["v"] = -float(r.split(';')[id]) # send negative value for claw motor angle () + if id == 5: + # send negative value for claw motor angle () + hg_m["v"] = -float(r.split(';')[id]) except: print("Robot not connected " + url) @@ -321,19 +362,37 @@ def get_v_from_dancing(id_robot): url_set_motor_pos_registers += f"m{id + 1}:compliant:{'True' if compliance_mode else 'False'};m{id + 1}:led:{led_actual_color};" url_set_motor_pos += f"m{id + 1}:{v}:{send_dt};" - - hg_m["acc"] = lerp(0.1, hg_m["acc"], clamp((hg_m["v"] - v) / (hg.time_to_sec_f(dt)**2), -9999, 9999)) + hg_m["acc"] = lerp(0.1, hg_m["acc"], clamp( + (hg_m["v"] - v) / (hg.time_to_sec_f(dt)**2), -9999, 9999)) hg_m["v"] = v - # set the position to the virtual robot - rot = hg.Vec3(0, 0, 0) - if hg_m["axis"] == "X": - rot = hg.Vec3(-v*pi/180.0, 0, 0) - elif hg_m["axis"] == "Y": - rot = hg.Vec3(0, -v*pi/180.0, 0) - elif hg_m["axis"] == "Z": - rot = hg.Vec3(-1.57, 0, -v*pi/180.0) - hg_m["n"].GetTransform().SetRot(rot) + if compliance_mode and compliance_lerp: + adjusted_time = rangeadjust(hg.GetClock( + ), hg_motors_previous[id][1], hg_motors_previous[id][1] + hg.time_from_sec_f(send_dt), 0, 1) + if adjusted_time < 1.0: + # interpolate previous rotation with current one based on elapsed time between both + new_v = lerp(adjusted_time, hg_motors_previous[id][0], v) + # set the position to the virtual robot + rot = hg.Vec3(0, 0, 0) + if hg_m["axis"] == "X": + rot = hg.Vec3(-new_v*pi/180.0, 0, 0) + elif hg_m["axis"] == "Y": + rot = hg.Vec3(0, -new_v*pi/180.0, 0) + elif hg_m["axis"] == "Z": + rot = hg.Vec3(-1.57, 0, -new_v*pi/180.0) + + hg_m["n"].GetTransform().SetRot(rot) + + else: + rot = hg.Vec3(0, 0, 0) + if hg_m["axis"] == "X": + rot = hg.Vec3(-v*pi/180.0, 0, 0) + elif hg_m["axis"] == "Y": + rot = hg.Vec3(0, -v*pi/180.0, 0) + elif hg_m["axis"] == "Z": + rot = hg.Vec3(-1.57, 0, -v*pi/180.0) + + hg_m["n"].GetTransform().SetRot(rot) # check if we are getting value from the real root if not compliance_mode: @@ -369,8 +428,10 @@ def get_v_from_dancing(id_robot): print("Robot not connected "+url) # draw ui - view_id_scene_opaque = hg.GetSceneForwardPipelinePassViewId(pass_ids, hg.SFPP_Opaque) - view_id_scene_alpha = hg.GetSceneForwardPipelinePassViewId(pass_ids, hg.SFPP_Transparent) + view_id_scene_opaque = hg.GetSceneForwardPipelinePassViewId( + pass_ids, hg.SFPP_Opaque) + view_id_scene_alpha = hg.GetSceneForwardPipelinePassViewId( + pass_ids, hg.SFPP_Transparent) cam_world = cam.GetTransform().GetWorld() @@ -382,7 +443,8 @@ def get_v_from_dancing(id_robot): # set the position to the virtual robot m_world = hg_m["n"].GetTransform().GetWorld() m_pos = hg.GetT(m_world) - m_world_rot = hg.GetR(hg_m["n"].GetTransform().GetParent().GetTransform().GetWorld()) + m_world_rot = hg.GetR( + hg_m["n"].GetTransform().GetParent().GetTransform().GetWorld()) m_world_scale = hg.GetS(m_world) if hg_m["offset_slider"].x == 1: @@ -393,12 +455,15 @@ def get_v_from_dancing(id_robot): m_pos += hg.GetY(m_world) * 0.003 # draw jauge in axis - m_world = hg.TransformationMat4(m_pos, m_world_rot, m_world_scale) * hg.RotationMat4(hg_m["offset_rotation"]) + m_world = hg.TransformationMat4( + m_pos, m_world_rot, m_world_scale) * hg.RotationMat4(hg_m["offset_rotation"]) hg_m["centroid_jauge_world"] = m_world - progress = hg.MakeUniformSetValue("uProgress", hg.Vec4(rangeadjust_clamp(v, -180, 180, 0, 100)/100, 0, 0, 0)) + progress = hg.MakeUniformSetValue("uProgress", hg.Vec4( + rangeadjust_clamp(v, -180, 180, 0, 100)/100, 0, 0, 0)) - hg.DrawModel(view_id_scene_alpha, hg_m["quad_jauge_axis"], shader_rotator, [progress], [texture_asset1], m_world, render_state_quad_occluded) + hg.DrawModel(view_id_scene_alpha, hg_m["quad_jauge_axis"], shader_rotator, [ + progress], [texture_asset1], m_world, render_state_quad_occluded) # draw 2D jauge # set 2D view @@ -407,7 +472,8 @@ def get_v_from_dancing(id_robot): hg.SetViewRect(view_id, 0, 0, res_x, res_y) hg.SetViewClear(view_id, 0, 0, 1.0, 0) - vs = hg.ComputeOrthographicViewState(hg.TranslationMat4(hg.Vec3(res_x / 2, res_y / 2, 0)), res_y, 0.1, 100, hg.Vec2(res_x / res_y, 1)) + vs = hg.ComputeOrthographicViewState(hg.TranslationMat4( + hg.Vec3(res_x / 2, res_y / 2, 0)), res_y, 0.1, 100, hg.Vec2(res_x / res_y, 1)) hg.SetViewTransform(view_id, vs.view, vs.proj) for id, m in enumerate(hg_motors): @@ -419,35 +485,45 @@ def get_v_from_dancing(id_robot): # texture quad quad_width = quad_height = res_y * 0.12 - pos_in_pixel = hg.iVec2(int(res_x - quad_width * 1.1), int((res_y * 0.05) + (res_y * 0.9)/len(hg_motors) * id + (quad_height * 1.2) / 2)) + pos_in_pixel = hg.iVec2(int(res_x - quad_width * 1.1), int( + (res_y * 0.05) + (res_y * 0.9)/len(hg_motors) * id + (quad_height * 1.2) / 2)) - #setup quad vertices - mat = hg.TransformationMat4(hg.Vec3(pos_in_pixel.x, pos_in_pixel.y, 1), hg.Vec3(0, 0, 0), hg.Vec3(1, 1, 1)) + # setup quad vertices + mat = hg.TransformationMat4( + hg.Vec3(pos_in_pixel.x, pos_in_pixel.y, 1), hg.Vec3(0, 0, 0), hg.Vec3(1, 1, 1)) pos = hg.GetT(mat) axis_x = hg.GetX(mat) * quad_width / 2 axis_y = hg.GetY(mat) * quad_height / 2 quad_vtx = hg.Vertices(vtx_layout, 4) - quad_vtx.Begin(0).SetPos(pos - axis_x - axis_y).SetTexCoord0(hg.Vec2(0, 1)).End() - quad_vtx.Begin(1).SetPos(pos - axis_x + axis_y).SetTexCoord0(hg.Vec2(0, 0)).End() - quad_vtx.Begin(2).SetPos(pos + axis_x + axis_y).SetTexCoord0(hg.Vec2(1, 0)).End() - quad_vtx.Begin(3).SetPos(pos + axis_x - axis_y).SetTexCoord0(hg.Vec2(1, 1)).End() + quad_vtx.Begin(0).SetPos( + pos - axis_x - axis_y).SetTexCoord0(hg.Vec2(0, 1)).End() + quad_vtx.Begin(1).SetPos( + pos - axis_x + axis_y).SetTexCoord0(hg.Vec2(0, 0)).End() + quad_vtx.Begin(2).SetPos( + pos + axis_x + axis_y).SetTexCoord0(hg.Vec2(1, 0)).End() + quad_vtx.Begin(3).SetPos( + pos + axis_x - axis_y).SetTexCoord0(hg.Vec2(1, 1)).End() quad_idx = [0, 3, 2, 0, 2, 1] # draw quad - progress = hg.MakeUniformSetValue("uProgress", hg.Vec4(rangeadjust_clamp(v, -180, 180, 0, 100)/100, 0, 0, 0)) + progress = hg.MakeUniformSetValue("uProgress", hg.Vec4( + rangeadjust_clamp(v, -180, 180, 0, 100)/100, 0, 0, 0)) - hg.DrawTriangles(view_id, quad_idx, quad_vtx, shader_rotator, [progress], [texture_asset2], render_state_quad) + hg.DrawTriangles(view_id, quad_idx, quad_vtx, shader_rotator, [ + progress], [texture_asset2], render_state_quad) # # draw line in 2D vtx = hg.Vertices(vtx_line_layout, 2) pos_view = view_state.view * hg.GetT(hg_m["centroid_jauge_world"]) - projection = hg.ProjectToScreenSpace(view_state.proj, pos_view, hg.Vec2(res_x, res_y)) + projection = hg.ProjectToScreenSpace( + view_state.proj, pos_view, hg.Vec2(res_x, res_y)) motor_pos_2D = projection[1] vtx.Begin(0).SetPos(motor_pos_2D).SetColor0(hg.Color.White).End() - vtx.Begin(1).SetPos(hg.Vec3(pos_in_pixel.x - quad_width / 2, pos_in_pixel.y, 1)).SetColor0(hg.Color.White).End() + vtx.Begin(1).SetPos(hg.Vec3(pos_in_pixel.x - quad_width / 2, + pos_in_pixel.y, 1)).SetColor0(hg.Color.White).End() hg.DrawLines(view_id, vtx, shader_for_line) # draw percent @@ -458,18 +534,22 @@ def get_v_from_dancing(id_robot): hg.DrawText(view_id, font, - '{n} °'.format(n = int(rangeadjust_clamp(v, -180, 180, 0, 360))), shader_font, "u_tex", 0, - mat, hg.Vec3(0, 0, 0), hg.DTHA_Left, hg.DTVA_Top, - [font_color_white], [], text_render_state) + '{n} °'.format(n=int(rangeadjust_clamp( + v, -180, 180, 0, 360))), shader_font, "u_tex", 0, + mat, hg.Vec3( + 0, 0, 0), hg.DTHA_Left, hg.DTVA_Top, + [font_color_white], [], text_render_state) # draw central point on motor quad_width = 8 quad_height = 8 pos_in_pixel = motor_pos_2D - color = hg.MakeUniformSetValue("uTextureColor", hg.Vec4(-1.0, 0, 0, 1.0)) + color = hg.MakeUniformSetValue( + "uTextureColor", hg.Vec4(-1.0, 0, 0, 1.0)) - hg.DrawTriangles(view_id, quad_idx, quad_vtx, shader_for_plane, [], [texture_point], render_state_quad) + hg.DrawTriangles(view_id, quad_idx, quad_vtx, shader_for_plane, [], [ + texture_point], render_state_quad) # if roboto was not found, add a red text to tell everybody if url == "": @@ -479,7 +559,7 @@ def get_v_from_dancing(id_robot): font, str_error, shader_font, "u_tex", 0, mat, hg.Vec3(0, 0, 0), hg.DTHA_Left, hg.DTVA_Top, - [font_shadow], [], text_render_state) + [font_shadow], [], text_render_state) mat = hg.TranslationMat4(hg.Vec3(15, 50, 1)) hg.SetS(mat, hg.Vec3(1, -1, 1)) hg.DrawText(view_id, @@ -488,13 +568,16 @@ def get_v_from_dancing(id_robot): mat, hg.Vec3(0, 0, 0), hg.DTHA_Left, hg.DTVA_Top, [font_color], [], text_render_state) - compliance_mode = toggle_button("Compliance Mode ON" if compliance_mode else "Compliance Mode OFF", compliance_mode, 100, res_y - 80) + compliance_mode = toggle_button( + "Compliance Mode ON" if compliance_mode else "Compliance Mode OFF", compliance_mode, 100, res_y - 80) + if compliance_mode: + compliance_lerp = toggle_button( + "Motion Interpolation ON" if compliance_lerp else "Motion Interpolation OFF", compliance_lerp, 100, res_y - 180) view_id += 1 - current_frame = hg.Frame() hg.UpdateWindow(win) hg.RenderShutdown() -hg.DestroyWindow(win) \ No newline at end of file +hg.DestroyWindow(win) diff --git a/resources/core/shader/a_trous_fs.sc b/resources/core/shader/a_trous_fs.sc index 1f5a1d2..ed154ad 100644 --- a/resources/core/shader/a_trous_fs.sc +++ b/resources/core/shader/a_trous_fs.sc @@ -1,3 +1,4 @@ +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_color, 0); diff --git a/resources/core/shader/a_trous_vs.sc b/resources/core/shader/a_trous_vs.sc index 1b87b56..ef6ecd0 100644 --- a/resources/core/shader/a_trous_vs.sc +++ b/resources/core/shader/a_trous_vs.sc @@ -1,5 +1,6 @@ $input a_position +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/aaa_downsample_fs.sc b/resources/core/shader/aaa_downsample_fs.sc index 735bc27..72b4144 100644 --- a/resources/core/shader/aaa_downsample_fs.sc +++ b/resources/core/shader/aaa_downsample_fs.sc @@ -1,3 +1,4 @@ +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_color, 0); diff --git a/resources/core/shader/aaa_downsample_vs.sc b/resources/core/shader/aaa_downsample_vs.sc index 1b87b56..ef6ecd0 100644 --- a/resources/core/shader/aaa_downsample_vs.sc +++ b/resources/core/shader/aaa_downsample_vs.sc @@ -1,5 +1,6 @@ $input a_position +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/aaa_upsample_fs.sc b/resources/core/shader/aaa_upsample_fs.sc index 792d52c..2567d83 100644 --- a/resources/core/shader/aaa_upsample_fs.sc +++ b/resources/core/shader/aaa_upsample_fs.sc @@ -1,3 +1,4 @@ +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_input, 0); diff --git a/resources/core/shader/aaa_upsample_vs.sc b/resources/core/shader/aaa_upsample_vs.sc index 1b87b56..ef6ecd0 100644 --- a/resources/core/shader/aaa_upsample_vs.sc +++ b/resources/core/shader/aaa_upsample_vs.sc @@ -1,5 +1,6 @@ $input a_position +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/aaa_utils.sh b/resources/core/shader/aaa_utils.sh index 973ed52..d0585d4 100644 --- a/resources/core/shader/aaa_utils.sh +++ b/resources/core/shader/aaa_utils.sh @@ -1,3 +1,4 @@ +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #ifndef AAA_UTILS_SH_HEADER_GUARD #define AAA_UTILS_SH_HEADER_GUARD diff --git a/resources/core/shader/bloom_combine_fs.sc b/resources/core/shader/bloom_combine_fs.sc index 9c1b80d..d6abacb 100644 --- a/resources/core/shader/bloom_combine_fs.sc +++ b/resources/core/shader/bloom_combine_fs.sc @@ -1,5 +1,6 @@ $input v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_source, 0); diff --git a/resources/core/shader/bloom_combine_vs.sc b/resources/core/shader/bloom_combine_vs.sc index 0aa174c..a8521fe 100644 --- a/resources/core/shader/bloom_combine_vs.sc +++ b/resources/core/shader/bloom_combine_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/bloom_downsample_fs.sc b/resources/core/shader/bloom_downsample_fs.sc index e142d0f..f418d95 100644 --- a/resources/core/shader/bloom_downsample_fs.sc +++ b/resources/core/shader/bloom_downsample_fs.sc @@ -1,5 +1,6 @@ $input v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_source, 0); diff --git a/resources/core/shader/bloom_downsample_vs.sc b/resources/core/shader/bloom_downsample_vs.sc index e70a81b..47acae3 100644 --- a/resources/core/shader/bloom_downsample_vs.sc +++ b/resources/core/shader/bloom_downsample_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include uniform vec4 u_source_rect; diff --git a/resources/core/shader/bloom_threshold_fs.sc b/resources/core/shader/bloom_threshold_fs.sc index 7ef6e64..88731d7 100644 --- a/resources/core/shader/bloom_threshold_fs.sc +++ b/resources/core/shader/bloom_threshold_fs.sc @@ -1,5 +1,6 @@ $input v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include uniform vec4 u_params; diff --git a/resources/core/shader/bloom_threshold_vs.sc b/resources/core/shader/bloom_threshold_vs.sc index 8a1f333..7519a3d 100644 --- a/resources/core/shader/bloom_threshold_vs.sc +++ b/resources/core/shader/bloom_threshold_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/bloom_upsample_fs.sc b/resources/core/shader/bloom_upsample_fs.sc index 313f708..d121004 100644 --- a/resources/core/shader/bloom_upsample_fs.sc +++ b/resources/core/shader/bloom_upsample_fs.sc @@ -1,5 +1,6 @@ $input v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_source, 0); diff --git a/resources/core/shader/bloom_upsample_vs.sc b/resources/core/shader/bloom_upsample_vs.sc index 6f3cd94..df637d9 100644 --- a/resources/core/shader/bloom_upsample_vs.sc +++ b/resources/core/shader/bloom_upsample_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include uniform vec4 u_source_rect; diff --git a/resources/core/shader/compositing_fs.sc b/resources/core/shader/compositing_fs.sc index d7b63fa..c22ffcf 100644 --- a/resources/core/shader/compositing_fs.sc +++ b/resources/core/shader/compositing_fs.sc @@ -1,5 +1,6 @@ $input v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_copyColor, 0); diff --git a/resources/core/shader/compositing_vs.sc b/resources/core/shader/compositing_vs.sc index 7a95b22..38cbd27 100644 --- a/resources/core/shader/compositing_vs.sc +++ b/resources/core/shader/compositing_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/copy_fs.sc b/resources/core/shader/copy_fs.sc index 493ea49..3f7b43f 100644 --- a/resources/core/shader/copy_fs.sc +++ b/resources/core/shader/copy_fs.sc @@ -1,5 +1,6 @@ $input v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_copyColor, 0); diff --git a/resources/core/shader/copy_vs.sc b/resources/core/shader/copy_vs.sc index 7a95b22..38cbd27 100644 --- a/resources/core/shader/copy_vs.sc +++ b/resources/core/shader/copy_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/default_fs.sc b/resources/core/shader/default_fs.sc index 1bc97ac..5a50f59 100644 --- a/resources/core/shader/default_fs.sc +++ b/resources/core/shader/default_fs.sc @@ -1,5 +1,6 @@ $input vWorldPos, vNormal, vTangent, vBinormal, vTexCoord0, vTexCoord1, vLinearShadowCoord0, vLinearShadowCoord1, vLinearShadowCoord2, vLinearShadowCoord3, vSpotShadowCoord, vProjPos, vPrevProjPos +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include // Surface attributes @@ -223,9 +224,7 @@ void main() { float opacity = 1.0; #endif // USE_OPACITY_MAP -#if DEPTH_ONLY - ; -#else // DEPTH_ONLY +#if DEPTH_ONLY != 1 #if FORWARD_PIPELINE_AAA_PREPASS vec3 N_view = mul(u_view, vec4(N, 0)).xyz; vec2 velocity = vec2(vProjPos.xy / vProjPos.w - vPrevProjPos.xy / vPrevProjPos.w); @@ -240,5 +239,7 @@ void main() { gl_FragColor = vec4(color, opacity); #endif // FORWARD_PIPELINE_AAA_PREPASS +#else + gl_FragColor = vec4_splat(0.0); // note: fix required to stop glsl-optimizer from removing the whole function body #endif // DEPTH_ONLY } diff --git a/resources/core/shader/default_vs.sc b/resources/core/shader/default_vs.sc index b509d2b..c54388c 100644 --- a/resources/core/shader/default_vs.sc +++ b/resources/core/shader/default_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_normal, a_texcoord0, a_texcoord1, a_tangent, a_bitangent, a_indices, a_weight $output vWorldPos, vNormal, vTexCoord0, vTexCoord1, vTangent, vBinormal, vLinearShadowCoord0, vLinearShadowCoord1, vLinearShadowCoord2, vLinearShadowCoord3, vSpotShadowCoord, vProjPos, vPrevProjPos +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include mat3 normal_mat(mat4 m) { diff --git a/resources/core/shader/denoise_vs.sc b/resources/core/shader/denoise_vs.sc index aff3c54..8a5a43d 100644 --- a/resources/core/shader/denoise_vs.sc +++ b/resources/core/shader/denoise_vs.sc @@ -1,5 +1,6 @@ $input a_position +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/font_fs.sc b/resources/core/shader/font_fs.sc index e6289c2..7bfc6fa 100644 --- a/resources/core/shader/font_fs.sc +++ b/resources/core/shader/font_fs.sc @@ -1,5 +1,6 @@ $input v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include uniform vec4 u_color; diff --git a/resources/core/shader/font_vs.sc b/resources/core/shader/font_vs.sc index 0cfa264..569636a 100644 --- a/resources/core/shader/font_vs.sc +++ b/resources/core/shader/font_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/forward_pipeline.sh b/resources/core/shader/forward_pipeline.sh index e4bda47..a7fd130 100644 --- a/resources/core/shader/forward_pipeline.sh +++ b/resources/core/shader/forward_pipeline.sh @@ -1,3 +1,7 @@ +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. + +// DO NOT MODIFY THIS FILE! + #include #define PI 3.14159265359 @@ -38,13 +42,19 @@ uniform mat4 uProbeMatrix; uniform mat4 uInvProbeMatrix; uniform vec4 uProbeData; -SAMPLERCUBE(uIrradianceMap, 7); -SAMPLERCUBE(uRadianceMap, 8); -SAMPLER2D(uSSIrradianceMap, 9); -SAMPLER2D(uSSRadianceMap, 10); -SAMPLER2D(uBrdfMap, 11); -SAMPLER2D(uNoiseMap, 12); -SAMPLER2D(uAmbientOcclusion, 13); +/* + Reserved texture units for the AAA forward pipeline. + Do not modify these slots, they are hardcoded on the C++ side. + + If reserving new slots for the pipeline please keep in mind WebGL limitations: https://webglreport.com/?v=2 + At the moment it is not advisable to use texture units beyond 16 for embedded platforms. +*/ +SAMPLERCUBE(uIrradianceMap, 8); +SAMPLERCUBE(uRadianceMap, 9); +SAMPLER2D(uSSIrradianceMap, 10); +SAMPLER2D(uSSRadianceMap, 11); +SAMPLER2D(uBrdfMap, 12); +SAMPLER2D(uNoiseMap, 13); SAMPLER2DSHADOW(uLinearShadowMap, 14); SAMPLER2DSHADOW(uSpotShadowMap, 15); diff --git a/resources/core/shader/hiz_trace.sh b/resources/core/shader/hiz_trace.sh index c96f915..cf8aeb6 100644 --- a/resources/core/shader/hiz_trace.sh +++ b/resources/core/shader/hiz_trace.sh @@ -1,3 +1,4 @@ +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #ifndef HIZ_TRACE_SH_HEADER_GUARD #define HIZ_TRACE_SH_HEADER_GUARD diff --git a/resources/core/shader/imgui_fs.sc b/resources/core/shader/imgui_fs.sc index 90483c5..9f14940 100644 --- a/resources/core/shader/imgui_fs.sc +++ b/resources/core/shader/imgui_fs.sc @@ -1,5 +1,6 @@ $input v_color0, v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(s_tex, 0); diff --git a/resources/core/shader/imgui_vs.sc b/resources/core/shader/imgui_vs.sc index 9cc137a..f50f0d6 100644 --- a/resources/core/shader/imgui_vs.sc +++ b/resources/core/shader/imgui_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0, a_color0 $output v_color0, v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() diff --git a/resources/core/shader/missing_fs.sc b/resources/core/shader/missing_fs.sc index d740a92..0c09174 100644 --- a/resources/core/shader/missing_fs.sc +++ b/resources/core/shader/missing_fs.sc @@ -1,5 +1,6 @@ $input vWorldPos +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/missing_vs.sc b/resources/core/shader/missing_vs.sc index e2b8bb5..fd9b4fc 100644 --- a/resources/core/shader/missing_vs.sc +++ b/resources/core/shader/missing_vs.sc @@ -1,6 +1,7 @@ $input a_position $output vWorldPos +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/motion_blur_fs.sc b/resources/core/shader/motion_blur_fs.sc index d95f847..fea5d93 100644 --- a/resources/core/shader/motion_blur_fs.sc +++ b/resources/core/shader/motion_blur_fs.sc @@ -1,3 +1,4 @@ +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_color, 0); diff --git a/resources/core/shader/motion_blur_vs.sc b/resources/core/shader/motion_blur_vs.sc index 634540d..968f4f2 100644 --- a/resources/core/shader/motion_blur_vs.sc +++ b/resources/core/shader/motion_blur_vs.sc @@ -1,5 +1,6 @@ $input a_position, a_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/pbr_fs.sc b/resources/core/shader/pbr_fs.sc index 50c0549..69ba38b 100644 --- a/resources/core/shader/pbr_fs.sc +++ b/resources/core/shader/pbr_fs.sc @@ -1,5 +1,6 @@ $input vWorldPos, vNormal, vTangent, vBinormal, vTexCoord0, vTexCoord1, vLinearShadowCoord0, vLinearShadowCoord1, vLinearShadowCoord2, vLinearShadowCoord3, vSpotShadowCoord, vProjPos, vPrevProjPos +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include // Surface attributes @@ -292,5 +293,7 @@ void main() { gl_FragColor = vec4(color, opacity); #endif // FORWARD_PIPELINE_AAA_PREPASS +#else + gl_FragColor = vec4_splat(0.0); // note: fix required to stop glsl-optimizer from removing the whole function body #endif // DEPTH_ONLY } diff --git a/resources/core/shader/pbr_vs.sc b/resources/core/shader/pbr_vs.sc index f1b2ab9..2582a33 100644 --- a/resources/core/shader/pbr_vs.sc +++ b/resources/core/shader/pbr_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_normal, a_texcoord0, a_texcoord1, a_tangent, a_bitangent, a_indices, a_weight $output vWorldPos, vNormal, vTexCoord0, vTexCoord1, vTangent, vBinormal, vLinearShadowCoord0, vLinearShadowCoord1, vLinearShadowCoord2, vLinearShadowCoord3, vSpotShadowCoord, vProjPos, vPrevProjPos +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include mat3 normal_mat(mat4 m) { diff --git a/resources/core/shader/sao_blur_fs.sc b/resources/core/shader/sao_blur_fs.sc index 76d6f51..f16bde6 100644 --- a/resources/core/shader/sao_blur_fs.sc +++ b/resources/core/shader/sao_blur_fs.sc @@ -1,5 +1,6 @@ $input v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_attr0, 0); diff --git a/resources/core/shader/sao_blur_vs.sc b/resources/core/shader/sao_blur_vs.sc index 8a1f333..7519a3d 100644 --- a/resources/core/shader/sao_blur_vs.sc +++ b/resources/core/shader/sao_blur_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/sao_compute_fs.sc b/resources/core/shader/sao_compute_fs.sc index 1ca9cf0..d17d46e 100644 --- a/resources/core/shader/sao_compute_fs.sc +++ b/resources/core/shader/sao_compute_fs.sc @@ -1,5 +1,6 @@ $input v_viewRay +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_attr0, 0); diff --git a/resources/core/shader/sao_compute_vs.sc b/resources/core/shader/sao_compute_vs.sc index 3076def..d02de49 100644 --- a/resources/core/shader/sao_compute_vs.sc +++ b/resources/core/shader/sao_compute_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output v_viewRay +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/sao_upsample_fs.sc b/resources/core/shader/sao_upsample_fs.sc index 1d0c13e..4b16028 100644 --- a/resources/core/shader/sao_upsample_fs.sc +++ b/resources/core/shader/sao_upsample_fs.sc @@ -1,5 +1,6 @@ $input v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_attr0, 0); diff --git a/resources/core/shader/sao_upsample_vs.sc b/resources/core/shader/sao_upsample_vs.sc index 8a1f333..7519a3d 100644 --- a/resources/core/shader/sao_upsample_vs.sc +++ b/resources/core/shader/sao_upsample_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output v_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/ssgi_fs.sc b/resources/core/shader/ssgi_fs.sc index f8294fb..efd98fa 100644 --- a/resources/core/shader/ssgi_fs.sc +++ b/resources/core/shader/ssgi_fs.sc @@ -1,5 +1,6 @@ $input vTexCoord0, v_viewRay +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_color, 0); diff --git a/resources/core/shader/ssgi_vs.sc b/resources/core/shader/ssgi_vs.sc index af73283..6b7fbcf 100644 --- a/resources/core/shader/ssgi_vs.sc +++ b/resources/core/shader/ssgi_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output vTexCoord0, v_viewRay +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include #define uv_ratio vec2_splat(uAAAParams[0].x) diff --git a/resources/core/shader/ssr_fs.sc b/resources/core/shader/ssr_fs.sc index 6c693e7..9207050 100644 --- a/resources/core/shader/ssr_fs.sc +++ b/resources/core/shader/ssr_fs.sc @@ -1,5 +1,6 @@ $input vTexCoord0, v_viewRay +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_color, 0); diff --git a/resources/core/shader/ssr_vs.sc b/resources/core/shader/ssr_vs.sc index 1636a1d..6b33b32 100644 --- a/resources/core/shader/ssr_vs.sc +++ b/resources/core/shader/ssr_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output vTexCoord0, v_viewRay +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/taa_fs.sc b/resources/core/shader/taa_fs.sc index 8237b94..bcf820c 100644 --- a/resources/core/shader/taa_fs.sc +++ b/resources/core/shader/taa_fs.sc @@ -1,3 +1,4 @@ +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_color, 0); diff --git a/resources/core/shader/taa_vs.sc b/resources/core/shader/taa_vs.sc index 810238b..4747f03 100644 --- a/resources/core/shader/taa_vs.sc +++ b/resources/core/shader/taa_vs.sc @@ -1,5 +1,6 @@ $input a_position, a_texcoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/core/shader/temporal_accumulation_fs.sc b/resources/core/shader/temporal_accumulation_fs.sc index e850fd0..d8a3eb1 100644 --- a/resources/core/shader/temporal_accumulation_fs.sc +++ b/resources/core/shader/temporal_accumulation_fs.sc @@ -1,5 +1,6 @@ $input vTexCoord0 +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include SAMPLER2D(u_current, 0); diff --git a/resources/core/shader/temporal_accumulation_vs.sc b/resources/core/shader/temporal_accumulation_vs.sc index 9e87523..a85563e 100644 --- a/resources/core/shader/temporal_accumulation_vs.sc +++ b/resources/core/shader/temporal_accumulation_vs.sc @@ -1,6 +1,7 @@ $input a_position, a_texcoord0 $output vTexCoord0, +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. #include void main() { diff --git a/resources/shaders/bgfx_shader.sh b/resources/shaders/bgfx_shader.sh index 4340913..f11bcd2 100644 --- a/resources/shaders/bgfx_shader.sh +++ b/resources/shaders/bgfx_shader.sh @@ -1,645 +1,645 @@ -/* - * Copyright 2011-2021 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause - */ - -#ifndef BGFX_SHADER_H_HEADER_GUARD -#define BGFX_SHADER_H_HEADER_GUARD - -#if !defined(BGFX_CONFIG_MAX_BONES) -# define BGFX_CONFIG_MAX_BONES 32 -#endif // !defined(BGFX_CONFIG_MAX_BONES) - -#ifndef __cplusplus - -#if BGFX_SHADER_LANGUAGE_HLSL > 300 -# define BRANCH [branch] -# define LOOP [loop] -# define UNROLL [unroll] -#else -# define BRANCH -# define LOOP -# define UNROLL -#endif // BGFX_SHADER_LANGUAGE_HLSL > 300 - -#if BGFX_SHADER_LANGUAGE_HLSL > 300 && BGFX_SHADER_TYPE_FRAGMENT -# define EARLY_DEPTH_STENCIL [earlydepthstencil] -#else -# define EARLY_DEPTH_STENCIL -#endif // BGFX_SHADER_LANGUAGE_HLSL > 300 && BGFX_SHADER_TYPE_FRAGMENT - -#if BGFX_SHADER_LANGUAGE_GLSL -# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = _type[]( -# define ARRAY_END() ) -#else -# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = { -# define ARRAY_END() } -#endif // BGFX_SHADER_LANGUAGE_GLSL - -#if BGFX_SHADER_LANGUAGE_HLSL \ - || BGFX_SHADER_LANGUAGE_PSSL \ - || BGFX_SHADER_LANGUAGE_SPIRV \ - || BGFX_SHADER_LANGUAGE_METAL -# define CONST(_x) static const _x -# define dFdx(_x) ddx(_x) -# define dFdy(_y) ddy(-_y) -# define inversesqrt(_x) rsqrt(_x) -# define fract(_x) frac(_x) - -# define bvec2 bool2 -# define bvec3 bool3 -# define bvec4 bool4 - -// To be able to patch the uav registers on the DXBC SPDB Chunk (D3D11 renderer) the whitespaces around -// '_type[_reg]' are necessary. This only affects shaders with debug info (i.e., those that have the SPDB Chunk). -# if BGFX_SHADER_LANGUAGE_HLSL > 400 -# define REGISTER(_type, _reg) register( _type[_reg] ) -# else -# define REGISTER(_type, _reg) register(_type ## _reg) -# endif // BGFX_SHADER_LANGUAGE_HLSL - -# if BGFX_SHADER_LANGUAGE_HLSL > 300 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL -# if BGFX_SHADER_LANGUAGE_HLSL > 400 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL -# define dFdxCoarse(_x) ddx_coarse(_x) -# define dFdxFine(_x) ddx_fine(_x) -# define dFdyCoarse(_y) ddy_coarse(-_y) -# define dFdyFine(_y) ddy_fine(-_y) -# endif // BGFX_SHADER_LANGUAGE_HLSL > 400 - -# if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL -float intBitsToFloat(int _x) { return asfloat(_x); } -vec2 intBitsToFloat(uint2 _x) { return asfloat(_x); } -vec3 intBitsToFloat(uint3 _x) { return asfloat(_x); } -vec4 intBitsToFloat(uint4 _x) { return asfloat(_x); } -# endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL - -float uintBitsToFloat(uint _x) { return asfloat(_x); } -vec2 uintBitsToFloat(uint2 _x) { return asfloat(_x); } -vec3 uintBitsToFloat(uint3 _x) { return asfloat(_x); } -vec4 uintBitsToFloat(uint4 _x) { return asfloat(_x); } - -uint floatBitsToUint(float _x) { return asuint(_x); } -uvec2 floatBitsToUint(vec2 _x) { return asuint(_x); } -uvec3 floatBitsToUint(vec3 _x) { return asuint(_x); } -uvec4 floatBitsToUint(vec4 _x) { return asuint(_x); } - -int floatBitsToInt(float _x) { return asint(_x); } -ivec2 floatBitsToInt(vec2 _x) { return asint(_x); } -ivec3 floatBitsToInt(vec3 _x) { return asint(_x); } -ivec4 floatBitsToInt(vec4 _x) { return asint(_x); } - -uint bitfieldReverse(uint _x) { return reversebits(_x); } -uint2 bitfieldReverse(uint2 _x) { return reversebits(_x); } -uint3 bitfieldReverse(uint3 _x) { return reversebits(_x); } -uint4 bitfieldReverse(uint4 _x) { return reversebits(_x); } - -# if !BGFX_SHADER_LANGUAGE_SPIRV -uint packHalf2x16(vec2 _x) -{ - return (f32tof16(_x.y)<<16) | f32tof16(_x.x); -} - -vec2 unpackHalf2x16(uint _x) -{ - return vec2(f16tof32(_x & 0xffff), f16tof32(_x >> 16) ); -} -# endif // !BGFX_SHADER_LANGUAGE_SPIRV - -struct BgfxSampler2D -{ - SamplerState m_sampler; - Texture2D m_texture; -}; - -struct BgfxISampler2D -{ - Texture2D m_texture; -}; - -struct BgfxUSampler2D -{ - Texture2D m_texture; -}; - -struct BgfxSampler2DArray -{ - SamplerState m_sampler; - Texture2DArray m_texture; -}; - -struct BgfxSampler2DShadow -{ - SamplerComparisonState m_sampler; - Texture2D m_texture; -}; - -struct BgfxSampler2DArrayShadow -{ - SamplerComparisonState m_sampler; - Texture2DArray m_texture; -}; - -struct BgfxSampler3D -{ - SamplerState m_sampler; - Texture3D m_texture; -}; - -struct BgfxISampler3D -{ - Texture3D m_texture; -}; - -struct BgfxUSampler3D -{ - Texture3D m_texture; -}; - -struct BgfxSamplerCube -{ - SamplerState m_sampler; - TextureCube m_texture; -}; - -struct BgfxSamplerCubeShadow -{ - SamplerComparisonState m_sampler; - TextureCube m_texture; -}; - -struct BgfxSampler2DMS -{ - Texture2DMS m_texture; -}; - -vec4 bgfxTexture2D(BgfxSampler2D _sampler, vec2 _coord) -{ - return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); -} - -vec4 bgfxTexture2DBias(BgfxSampler2D _sampler, vec2 _coord, float _bias) -{ - return _sampler.m_texture.SampleBias(_sampler.m_sampler, _coord, _bias); -} - -vec4 bgfxTexture2DLod(BgfxSampler2D _sampler, vec2 _coord, float _level) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); -} - -vec4 bgfxTexture2DLodOffset(BgfxSampler2D _sampler, vec2 _coord, float _level, ivec2 _offset) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level, _offset); -} - -vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec3 _coord) -{ - vec2 coord = _coord.xy * rcp(_coord.z); - return _sampler.m_texture.Sample(_sampler.m_sampler, coord); -} - -vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec4 _coord) -{ - vec2 coord = _coord.xy * rcp(_coord.w); - return _sampler.m_texture.Sample(_sampler.m_sampler, coord); -} - -vec4 bgfxTexture2DGrad(BgfxSampler2D _sampler, vec2 _coord, vec2 _dPdx, vec2 _dPdy) -{ - return _sampler.m_texture.SampleGrad(_sampler.m_sampler, _coord, _dPdx, _dPdy); -} - -vec4 bgfxTexture2DArray(BgfxSampler2DArray _sampler, vec3 _coord) -{ - return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); -} - -vec4 bgfxTexture2DArrayLod(BgfxSampler2DArray _sampler, vec3 _coord, float _lod) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _lod); -} - -vec4 bgfxTexture2DArrayLodOffset(BgfxSampler2DArray _sampler, vec3 _coord, float _level, ivec2 _offset) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level, _offset); -} - -float bgfxShadow2D(BgfxSampler2DShadow _sampler, vec3 _coord) -{ - return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xy, _coord.z); -} - -float bgfxShadow2DProj(BgfxSampler2DShadow _sampler, vec4 _coord) -{ - vec3 coord = _coord.xyz * rcp(_coord.w); - return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, coord.xy, coord.z); -} - -vec4 bgfxShadow2DArray(BgfxSampler2DArrayShadow _sampler, vec4 _coord) -{ - return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w); -} - -vec4 bgfxTexture3D(BgfxSampler3D _sampler, vec3 _coord) -{ - return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); -} - -vec4 bgfxTexture3DLod(BgfxSampler3D _sampler, vec3 _coord, float _level) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); -} - -ivec4 bgfxTexture3D(BgfxISampler3D _sampler, vec3 _coord) -{ - uvec3 size; - _sampler.m_texture.GetDimensions(size.x, size.y, size.z); - return _sampler.m_texture.Load(ivec4(_coord * size, 0) ); -} - -uvec4 bgfxTexture3D(BgfxUSampler3D _sampler, vec3 _coord) -{ - uvec3 size; - _sampler.m_texture.GetDimensions(size.x, size.y, size.z); - return _sampler.m_texture.Load(ivec4(_coord * size, 0) ); -} - -vec4 bgfxTextureCube(BgfxSamplerCube _sampler, vec3 _coord) -{ - return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); -} - -vec4 bgfxTextureCubeBias(BgfxSamplerCube _sampler, vec3 _coord, float _bias) -{ - return _sampler.m_texture.SampleBias(_sampler.m_sampler, _coord, _bias); -} - -vec4 bgfxTextureCubeLod(BgfxSamplerCube _sampler, vec3 _coord, float _level) -{ - return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); -} - -float bgfxShadowCube(BgfxSamplerCubeShadow _sampler, vec4 _coord) -{ - return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w); -} - -vec4 bgfxTexelFetch(BgfxSampler2D _sampler, ivec2 _coord, int _lod) -{ - return _sampler.m_texture.Load(ivec3(_coord, _lod) ); -} - -vec4 bgfxTexelFetchOffset(BgfxSampler2D _sampler, ivec2 _coord, int _lod, ivec2 _offset) -{ - return _sampler.m_texture.Load(ivec3(_coord, _lod), _offset ); -} - -vec2 bgfxTextureSize(BgfxSampler2D _sampler, int _lod) -{ - vec2 result; - _sampler.m_texture.GetDimensions(result.x, result.y); - return result; -} - -vec4 bgfxTextureGather(BgfxSampler2D _sampler, vec2 _coord) -{ - return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord ); -} -vec4 bgfxTextureGatherOffset(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset) -{ - return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord, _offset ); -} -vec4 bgfxTextureGather(BgfxSampler2DArray _sampler, vec3 _coord) -{ - return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord ); -} - -ivec4 bgfxTexelFetch(BgfxISampler2D _sampler, ivec2 _coord, int _lod) -{ - return _sampler.m_texture.Load(ivec3(_coord, _lod) ); -} - -uvec4 bgfxTexelFetch(BgfxUSampler2D _sampler, ivec2 _coord, int _lod) -{ - return _sampler.m_texture.Load(ivec3(_coord, _lod) ); -} - -vec4 bgfxTexelFetch(BgfxSampler2DMS _sampler, ivec2 _coord, int _sampleIdx) -{ - return _sampler.m_texture.Load(_coord, _sampleIdx); -} - -vec4 bgfxTexelFetch(BgfxSampler2DArray _sampler, ivec3 _coord, int _lod) -{ - return _sampler.m_texture.Load(ivec4(_coord, _lod) ); -} - -vec4 bgfxTexelFetch(BgfxSampler3D _sampler, ivec3 _coord, int _lod) -{ - return _sampler.m_texture.Load(ivec4(_coord, _lod) ); -} - -vec3 bgfxTextureSize(BgfxSampler3D _sampler, int _lod) -{ - vec3 result; - _sampler.m_texture.GetDimensions(result.x, result.y, result.z); - return result; -} - -# define SAMPLER2D(_name, _reg) \ - uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ - uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler2D _name = { _name ## Sampler, _name ## Texture } -# define ISAMPLER2D(_name, _reg) \ - uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ - static BgfxISampler2D _name = { _name ## Texture } -# define USAMPLER2D(_name, _reg) \ - uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ - static BgfxUSampler2D _name = { _name ## Texture } -# define sampler2D BgfxSampler2D -# define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord) -# define texture2DBias(_sampler, _coord, _bias) bgfxTexture2DBias(_sampler, _coord, _bias) -# define texture2DLod(_sampler, _coord, _level) bgfxTexture2DLod(_sampler, _coord, _level) -# define texture2DLodOffset(_sampler, _coord, _level, _offset) bgfxTexture2DLodOffset(_sampler, _coord, _level, _offset) -# define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) -# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) bgfxTexture2DGrad(_sampler, _coord, _dPdx, _dPdy) - -# define SAMPLER2DARRAY(_name, _reg) \ - uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ - uniform Texture2DArray _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler2DArray _name = { _name ## Sampler, _name ## Texture } -# define sampler2DArray BgfxSampler2DArray -# define texture2DArray(_sampler, _coord) bgfxTexture2DArray(_sampler, _coord) -# define texture2DArrayLod(_sampler, _coord, _lod) bgfxTexture2DArrayLod(_sampler, _coord, _lod) -# define texture2DArrayLodOffset(_sampler, _coord, _level, _offset) bgfxTexture2DArrayLodOffset(_sampler, _coord, _level, _offset) - -# define SAMPLER2DMS(_name, _reg) \ - uniform Texture2DMS _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler2DMS _name = { _name ## Texture } -# define sampler2DMS BgfxSampler2DMS - -# define SAMPLER2DSHADOW(_name, _reg) \ - uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ - uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler2DShadow _name = { _name ## SamplerComparison, _name ## Texture } -# define sampler2DShadow BgfxSampler2DShadow -# define shadow2D(_sampler, _coord) bgfxShadow2D(_sampler, _coord) -# define shadow2DProj(_sampler, _coord) bgfxShadow2DProj(_sampler, _coord) - -# define SAMPLER2DARRAYSHADOW(_name, _reg) \ - uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ - uniform Texture2DArray _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler2DArrayShadow _name = { _name ## SamplerComparison, _name ## Texture } -# define sampler2DArrayShadow BgfxSampler2DArrayShadow -# define shadow2DArray(_sampler, _coord) bgfxShadow2DArray(_sampler, _coord) - -# define SAMPLER3D(_name, _reg) \ - uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ - uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ - static BgfxSampler3D _name = { _name ## Sampler, _name ## Texture } -# define ISAMPLER3D(_name, _reg) \ - uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ - static BgfxISampler3D _name = { _name ## Texture } -# define USAMPLER3D(_name, _reg) \ - uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ - static BgfxUSampler3D _name = { _name ## Texture } -# define sampler3D BgfxSampler3D -# define texture3D(_sampler, _coord) bgfxTexture3D(_sampler, _coord) -# define texture3DLod(_sampler, _coord, _level) bgfxTexture3DLod(_sampler, _coord, _level) - -# define SAMPLERCUBE(_name, _reg) \ - uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ - uniform TextureCube _name ## Texture : REGISTER(t, _reg); \ - static BgfxSamplerCube _name = { _name ## Sampler, _name ## Texture } -# define samplerCube BgfxSamplerCube -# define textureCube(_sampler, _coord) bgfxTextureCube(_sampler, _coord) -# define textureCubeBias(_sampler, _coord, _bias) bgfxTextureCubeBias(_sampler, _coord, _bias) -# define textureCubeLod(_sampler, _coord, _level) bgfxTextureCubeLod(_sampler, _coord, _level) - -# define SAMPLERCUBESHADOW(_name, _reg) \ - uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ - uniform TextureCube _name ## Texture : REGISTER(t, _reg); \ - static BgfxSamplerCubeShadow _name = { _name ## SamplerComparison, _name ## Texture } -# define samplerCubeShadow BgfxSamplerCubeShadow -# define shadowCube(_sampler, _coord) bgfxShadowCube(_sampler, _coord) - -# define texelFetch(_sampler, _coord, _lod) bgfxTexelFetch(_sampler, _coord, _lod) -# define texelFetchOffset(_sampler, _coord, _lod, _offset) bgfxTexelFetchOffset(_sampler, _coord, _lod, _offset) -# define textureSize(_sampler, _lod) bgfxTextureSize(_sampler, _lod) -# define textureGather(_sampler, _coord) bgfxTextureGather(_sampler, _coord) -# define textureGatherOffset(_sampler, _coord, _offset) bgfxTextureGatherOffset(_sampler, _coord, _offset) -# else - -# define sampler2DShadow sampler2D - -vec4 bgfxTexture2DProj(sampler2D _sampler, vec3 _coord) -{ - return tex2Dproj(_sampler, vec4(_coord.xy, 0.0, _coord.z) ); -} - -vec4 bgfxTexture2DProj(sampler2D _sampler, vec4 _coord) -{ - return tex2Dproj(_sampler, _coord); -} - -float bgfxShadow2D(sampler2DShadow _sampler, vec3 _coord) -{ -#if 0 - float occluder = tex2D(_sampler, _coord.xy).x; - return step(_coord.z, occluder); -#else - return tex2Dproj(_sampler, vec4(_coord.xy, _coord.z, 1.0) ).x; -#endif // 0 -} - -float bgfxShadow2DProj(sampler2DShadow _sampler, vec4 _coord) -{ -#if 0 - vec3 coord = _coord.xyz * rcp(_coord.w); - float occluder = tex2D(_sampler, coord.xy).x; - return step(coord.z, occluder); -#else - return tex2Dproj(_sampler, _coord).x; -#endif // 0 -} - -# define SAMPLER2D(_name, _reg) uniform sampler2D _name : REGISTER(s, _reg) -# define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name : REGISTER(s, _reg) -# define texture2D(_sampler, _coord) tex2D(_sampler, _coord) -# define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) - -# define SAMPLER2DARRAY(_name, _reg) SAMPLER2D(_name, _reg) -# define texture2DArray(_sampler, _coord) texture2D(_sampler, (_coord).xy) -# define texture2DArrayLod(_sampler, _coord, _lod) texture2DLod(_sampler, _coord, _lod) - -# define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name : REGISTER(s, _reg) -# define shadow2D(_sampler, _coord) bgfxShadow2D(_sampler, _coord) -# define shadow2DProj(_sampler, _coord) bgfxShadow2DProj(_sampler, _coord) - -# define SAMPLER3D(_name, _reg) uniform sampler3D _name : REGISTER(s, _reg) -# define texture3D(_sampler, _coord) tex3D(_sampler, _coord) - -# define SAMPLERCUBE(_name, _reg) uniform samplerCUBE _name : REGISTER(s, _reg) -# define textureCube(_sampler, _coord) texCUBE(_sampler, _coord) - -# define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec4( (_coord).xy, 0.0, _level) ) -# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) tex2Dgrad(_sampler, _coord, _dPdx, _dPdy) -# define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) ) -# define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) ) - -# endif // BGFX_SHADER_LANGUAGE_HLSL > 300 - -vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_mtx, _vec); } -vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_vec, _mtx); } -vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_mtx, _vec); } -vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_vec, _mtx); } - -bvec2 lessThan(vec2 _a, vec2 _b) { return _a < _b; } -bvec3 lessThan(vec3 _a, vec3 _b) { return _a < _b; } -bvec4 lessThan(vec4 _a, vec4 _b) { return _a < _b; } - -bvec2 lessThanEqual(vec2 _a, vec2 _b) { return _a <= _b; } -bvec3 lessThanEqual(vec3 _a, vec3 _b) { return _a <= _b; } -bvec4 lessThanEqual(vec4 _a, vec4 _b) { return _a <= _b; } - -bvec2 greaterThan(vec2 _a, vec2 _b) { return _a > _b; } -bvec3 greaterThan(vec3 _a, vec3 _b) { return _a > _b; } -bvec4 greaterThan(vec4 _a, vec4 _b) { return _a > _b; } - -bvec2 greaterThanEqual(vec2 _a, vec2 _b) { return _a >= _b; } -bvec3 greaterThanEqual(vec3 _a, vec3 _b) { return _a >= _b; } -bvec4 greaterThanEqual(vec4 _a, vec4 _b) { return _a >= _b; } - -bvec2 notEqual(vec2 _a, vec2 _b) { return _a != _b; } -bvec3 notEqual(vec3 _a, vec3 _b) { return _a != _b; } -bvec4 notEqual(vec4 _a, vec4 _b) { return _a != _b; } - -bvec2 equal(vec2 _a, vec2 _b) { return _a == _b; } -bvec3 equal(vec3 _a, vec3 _b) { return _a == _b; } -bvec4 equal(vec4 _a, vec4 _b) { return _a == _b; } - -float mix(float _a, float _b, float _t) { return lerp(_a, _b, _t); } -vec2 mix(vec2 _a, vec2 _b, vec2 _t) { return lerp(_a, _b, _t); } -vec3 mix(vec3 _a, vec3 _b, vec3 _t) { return lerp(_a, _b, _t); } -vec4 mix(vec4 _a, vec4 _b, vec4 _t) { return lerp(_a, _b, _t); } - -float mod(float _a, float _b) { return _a - _b * floor(_a / _b); } -vec2 mod(vec2 _a, vec2 _b) { return _a - _b * floor(_a / _b); } -vec3 mod(vec3 _a, vec3 _b) { return _a - _b * floor(_a / _b); } -vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); } - -#else -# define CONST(_x) const _x -# define atan2(_x, _y) atan(_x, _y) -# define mul(_a, _b) ( (_a) * (_b) ) -# define saturate(_x) clamp(_x, 0.0, 1.0) -# define SAMPLER2D(_name, _reg) uniform sampler2D _name -# define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name -# define SAMPLER3D(_name, _reg) uniform sampler3D _name -# define SAMPLERCUBE(_name, _reg) uniform samplerCube _name -# define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name - -# define SAMPLER2DARRAY(_name, _reg) uniform sampler2DArray _name -# define SAMPLER2DMSARRAY(_name, _reg) uniform sampler2DMSArray _name -# define SAMPLERCUBEARRAY(_name, _reg) uniform samplerCubeArray _name -# define SAMPLER2DARRAYSHADOW(_name, _reg) uniform sampler2DArrayShadow _name - -# define ISAMPLER2D(_name, _reg) uniform isampler2D _name -# define USAMPLER2D(_name, _reg) uniform usampler2D _name -# define ISAMPLER3D(_name, _reg) uniform isampler3D _name -# define USAMPLER3D(_name, _reg) uniform usampler3D _name - -# define texture2DBias(_sampler, _coord, _bias) texture2D(_sampler, _coord, _bias) -# define textureCubeBias(_sampler, _coord, _bias) textureCube(_sampler, _coord, _bias) - -# if BGFX_SHADER_LANGUAGE_GLSL >= 130 -# define texture2D(_sampler, _coord) texture(_sampler, _coord) -# define texture2DArray(_sampler, _coord) texture(_sampler, _coord) -# define texture3D(_sampler, _coord) texture(_sampler, _coord) -# define texture2DLod(_sampler, _coord, _lod) textureLod(_sampler, _coord, _lod) -# define texture2DLodOffset(_sampler, _coord, _lod, _offset) textureLodOffset(_sampler, _coord, _lod, _offset) -# endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 - -vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); } -vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_mtx, _vec); } -vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_vec, _mtx); } -vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_mtx, _vec); } - -float rcp(float _a) { return 1.0/_a; } -vec2 rcp(vec2 _a) { return vec2(1.0)/_a; } -vec3 rcp(vec3 _a) { return vec3(1.0)/_a; } -vec4 rcp(vec4 _a) { return vec4(1.0)/_a; } -#endif // BGFX_SHADER_LANGUAGE_* - -vec2 vec2_splat(float _x) { return vec2(_x, _x); } -vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); } -vec4 vec4_splat(float _x) { return vec4(_x, _x, _x, _x); } - -#if BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL -uvec2 uvec2_splat(uint _x) { return uvec2(_x, _x); } -uvec3 uvec3_splat(uint _x) { return uvec3(_x, _x, _x); } -uvec4 uvec4_splat(uint _x) { return uvec4(_x, _x, _x, _x); } -#endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL - -mat4 mtxFromRows(vec4 _0, vec4 _1, vec4 _2, vec4 _3) -{ -#if BGFX_SHADER_LANGUAGE_GLSL - return transpose(mat4(_0, _1, _2, _3) ); -#else - return mat4(_0, _1, _2, _3); -#endif // BGFX_SHADER_LANGUAGE_GLSL -} -mat4 mtxFromCols(vec4 _0, vec4 _1, vec4 _2, vec4 _3) -{ -#if BGFX_SHADER_LANGUAGE_GLSL - return mat4(_0, _1, _2, _3); -#else - return transpose(mat4(_0, _1, _2, _3) ); -#endif // BGFX_SHADER_LANGUAGE_GLSL -} -mat3 mtxFromRows(vec3 _0, vec3 _1, vec3 _2) -{ -#if BGFX_SHADER_LANGUAGE_GLSL - return transpose(mat3(_0, _1, _2) ); -#else - return mat3(_0, _1, _2); -#endif // BGFX_SHADER_LANGUAGE_GLSL -} -mat3 mtxFromCols(vec3 _0, vec3 _1, vec3 _2) -{ -#if BGFX_SHADER_LANGUAGE_GLSL - return mat3(_0, _1, _2); -#else - return transpose(mat3(_0, _1, _2) ); -#endif // BGFX_SHADER_LANGUAGE_GLSL -} - -#if BGFX_SHADER_LANGUAGE_GLSL -#define mtxFromRows3(_0, _1, _2) transpose(mat3(_0, _1, _2) ) -#define mtxFromRows4(_0, _1, _2, _3) transpose(mat4(_0, _1, _2, _3) ) -#define mtxFromCols3(_0, _1, _2) mat3(_0, _1, _2) -#define mtxFromCols4(_0, _1, _2, _3) mat4(_0, _1, _2, _3) -#else -#define mtxFromRows3(_0, _1, _2) mat3(_0, _1, _2) -#define mtxFromRows4(_0, _1, _2, _3) mat4(_0, _1, _2, _3) -#define mtxFromCols3(_0, _1, _2) transpose(mat3(_0, _1, _2) ) -#define mtxFromCols4(_0, _1, _2, _3) transpose(mat4(_0, _1, _2, _3) ) -#endif // BGFX_SHADER_LANGUAGE_GLSL - -uniform vec4 u_viewRect; -uniform vec4 u_viewTexel; -uniform mat4 u_view; -uniform mat4 u_invView; -uniform mat4 u_proj; -uniform mat4 u_invProj; -uniform mat4 u_viewProj; -uniform mat4 u_invViewProj; -uniform mat4 u_model[BGFX_CONFIG_MAX_BONES]; -uniform mat4 u_modelView; -uniform mat4 u_modelViewProj; -uniform vec4 u_alphaRef4; -#define u_alphaRef u_alphaRef4.x - -#endif // __cplusplus - -#endif // BGFX_SHADER_H_HEADER_GUARD +/* + * Copyright 2011-2021 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + */ + +#ifndef BGFX_SHADER_H_HEADER_GUARD +#define BGFX_SHADER_H_HEADER_GUARD + +#if !defined(BGFX_CONFIG_MAX_BONES) +# define BGFX_CONFIG_MAX_BONES 32 +#endif // !defined(BGFX_CONFIG_MAX_BONES) + +#ifndef __cplusplus + +#if BGFX_SHADER_LANGUAGE_HLSL > 300 +# define BRANCH [branch] +# define LOOP [loop] +# define UNROLL [unroll] +#else +# define BRANCH +# define LOOP +# define UNROLL +#endif // BGFX_SHADER_LANGUAGE_HLSL > 300 + +#if BGFX_SHADER_LANGUAGE_HLSL > 300 && BGFX_SHADER_TYPE_FRAGMENT +# define EARLY_DEPTH_STENCIL [earlydepthstencil] +#else +# define EARLY_DEPTH_STENCIL +#endif // BGFX_SHADER_LANGUAGE_HLSL > 300 && BGFX_SHADER_TYPE_FRAGMENT + +#if BGFX_SHADER_LANGUAGE_GLSL +# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = _type[]( +# define ARRAY_END() ) +#else +# define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = { +# define ARRAY_END() } +#endif // BGFX_SHADER_LANGUAGE_GLSL + +#if BGFX_SHADER_LANGUAGE_HLSL \ + || BGFX_SHADER_LANGUAGE_PSSL \ + || BGFX_SHADER_LANGUAGE_SPIRV \ + || BGFX_SHADER_LANGUAGE_METAL +# define CONST(_x) static const _x +# define dFdx(_x) ddx(_x) +# define dFdy(_y) ddy(-_y) +# define inversesqrt(_x) rsqrt(_x) +# define fract(_x) frac(_x) + +# define bvec2 bool2 +# define bvec3 bool3 +# define bvec4 bool4 + +// To be able to patch the uav registers on the DXBC SPDB Chunk (D3D11 renderer) the whitespaces around +// '_type[_reg]' are necessary. This only affects shaders with debug info (i.e., those that have the SPDB Chunk). +# if BGFX_SHADER_LANGUAGE_HLSL > 400 +# define REGISTER(_type, _reg) register( _type[_reg] ) +# else +# define REGISTER(_type, _reg) register(_type ## _reg) +# endif // BGFX_SHADER_LANGUAGE_HLSL + +# if BGFX_SHADER_LANGUAGE_HLSL > 300 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL +# if BGFX_SHADER_LANGUAGE_HLSL > 400 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL +# define dFdxCoarse(_x) ddx_coarse(_x) +# define dFdxFine(_x) ddx_fine(_x) +# define dFdyCoarse(_y) ddy_coarse(-_y) +# define dFdyFine(_y) ddy_fine(-_y) +# endif // BGFX_SHADER_LANGUAGE_HLSL > 400 + +# if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL +float intBitsToFloat(int _x) { return asfloat(_x); } +vec2 intBitsToFloat(uint2 _x) { return asfloat(_x); } +vec3 intBitsToFloat(uint3 _x) { return asfloat(_x); } +vec4 intBitsToFloat(uint4 _x) { return asfloat(_x); } +# endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL + +float uintBitsToFloat(uint _x) { return asfloat(_x); } +vec2 uintBitsToFloat(uint2 _x) { return asfloat(_x); } +vec3 uintBitsToFloat(uint3 _x) { return asfloat(_x); } +vec4 uintBitsToFloat(uint4 _x) { return asfloat(_x); } + +uint floatBitsToUint(float _x) { return asuint(_x); } +uvec2 floatBitsToUint(vec2 _x) { return asuint(_x); } +uvec3 floatBitsToUint(vec3 _x) { return asuint(_x); } +uvec4 floatBitsToUint(vec4 _x) { return asuint(_x); } + +int floatBitsToInt(float _x) { return asint(_x); } +ivec2 floatBitsToInt(vec2 _x) { return asint(_x); } +ivec3 floatBitsToInt(vec3 _x) { return asint(_x); } +ivec4 floatBitsToInt(vec4 _x) { return asint(_x); } + +uint bitfieldReverse(uint _x) { return reversebits(_x); } +uint2 bitfieldReverse(uint2 _x) { return reversebits(_x); } +uint3 bitfieldReverse(uint3 _x) { return reversebits(_x); } +uint4 bitfieldReverse(uint4 _x) { return reversebits(_x); } + +# if !BGFX_SHADER_LANGUAGE_SPIRV +uint packHalf2x16(vec2 _x) +{ + return (f32tof16(_x.y)<<16) | f32tof16(_x.x); +} + +vec2 unpackHalf2x16(uint _x) +{ + return vec2(f16tof32(_x & 0xffff), f16tof32(_x >> 16) ); +} +# endif // !BGFX_SHADER_LANGUAGE_SPIRV + +struct BgfxSampler2D +{ + SamplerState m_sampler; + Texture2D m_texture; +}; + +struct BgfxISampler2D +{ + Texture2D m_texture; +}; + +struct BgfxUSampler2D +{ + Texture2D m_texture; +}; + +struct BgfxSampler2DArray +{ + SamplerState m_sampler; + Texture2DArray m_texture; +}; + +struct BgfxSampler2DShadow +{ + SamplerComparisonState m_sampler; + Texture2D m_texture; +}; + +struct BgfxSampler2DArrayShadow +{ + SamplerComparisonState m_sampler; + Texture2DArray m_texture; +}; + +struct BgfxSampler3D +{ + SamplerState m_sampler; + Texture3D m_texture; +}; + +struct BgfxISampler3D +{ + Texture3D m_texture; +}; + +struct BgfxUSampler3D +{ + Texture3D m_texture; +}; + +struct BgfxSamplerCube +{ + SamplerState m_sampler; + TextureCube m_texture; +}; + +struct BgfxSamplerCubeShadow +{ + SamplerComparisonState m_sampler; + TextureCube m_texture; +}; + +struct BgfxSampler2DMS +{ + Texture2DMS m_texture; +}; + +vec4 bgfxTexture2D(BgfxSampler2D _sampler, vec2 _coord) +{ + return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); +} + +vec4 bgfxTexture2DBias(BgfxSampler2D _sampler, vec2 _coord, float _bias) +{ + return _sampler.m_texture.SampleBias(_sampler.m_sampler, _coord, _bias); +} + +vec4 bgfxTexture2DLod(BgfxSampler2D _sampler, vec2 _coord, float _level) +{ + return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); +} + +vec4 bgfxTexture2DLodOffset(BgfxSampler2D _sampler, vec2 _coord, float _level, ivec2 _offset) +{ + return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level, _offset); +} + +vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec3 _coord) +{ + vec2 coord = _coord.xy * rcp(_coord.z); + return _sampler.m_texture.Sample(_sampler.m_sampler, coord); +} + +vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec4 _coord) +{ + vec2 coord = _coord.xy * rcp(_coord.w); + return _sampler.m_texture.Sample(_sampler.m_sampler, coord); +} + +vec4 bgfxTexture2DGrad(BgfxSampler2D _sampler, vec2 _coord, vec2 _dPdx, vec2 _dPdy) +{ + return _sampler.m_texture.SampleGrad(_sampler.m_sampler, _coord, _dPdx, _dPdy); +} + +vec4 bgfxTexture2DArray(BgfxSampler2DArray _sampler, vec3 _coord) +{ + return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); +} + +vec4 bgfxTexture2DArrayLod(BgfxSampler2DArray _sampler, vec3 _coord, float _lod) +{ + return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _lod); +} + +vec4 bgfxTexture2DArrayLodOffset(BgfxSampler2DArray _sampler, vec3 _coord, float _level, ivec2 _offset) +{ + return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level, _offset); +} + +float bgfxShadow2D(BgfxSampler2DShadow _sampler, vec3 _coord) +{ + return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xy, _coord.z); +} + +float bgfxShadow2DProj(BgfxSampler2DShadow _sampler, vec4 _coord) +{ + vec3 coord = _coord.xyz * rcp(_coord.w); + return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, coord.xy, coord.z); +} + +vec4 bgfxShadow2DArray(BgfxSampler2DArrayShadow _sampler, vec4 _coord) +{ + return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w); +} + +vec4 bgfxTexture3D(BgfxSampler3D _sampler, vec3 _coord) +{ + return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); +} + +vec4 bgfxTexture3DLod(BgfxSampler3D _sampler, vec3 _coord, float _level) +{ + return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); +} + +ivec4 bgfxTexture3D(BgfxISampler3D _sampler, vec3 _coord) +{ + uvec3 size; + _sampler.m_texture.GetDimensions(size.x, size.y, size.z); + return _sampler.m_texture.Load(ivec4(_coord * size, 0) ); +} + +uvec4 bgfxTexture3D(BgfxUSampler3D _sampler, vec3 _coord) +{ + uvec3 size; + _sampler.m_texture.GetDimensions(size.x, size.y, size.z); + return _sampler.m_texture.Load(ivec4(_coord * size, 0) ); +} + +vec4 bgfxTextureCube(BgfxSamplerCube _sampler, vec3 _coord) +{ + return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); +} + +vec4 bgfxTextureCubeBias(BgfxSamplerCube _sampler, vec3 _coord, float _bias) +{ + return _sampler.m_texture.SampleBias(_sampler.m_sampler, _coord, _bias); +} + +vec4 bgfxTextureCubeLod(BgfxSamplerCube _sampler, vec3 _coord, float _level) +{ + return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); +} + +float bgfxShadowCube(BgfxSamplerCubeShadow _sampler, vec4 _coord) +{ + return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w); +} + +vec4 bgfxTexelFetch(BgfxSampler2D _sampler, ivec2 _coord, int _lod) +{ + return _sampler.m_texture.Load(ivec3(_coord, _lod) ); +} + +vec4 bgfxTexelFetchOffset(BgfxSampler2D _sampler, ivec2 _coord, int _lod, ivec2 _offset) +{ + return _sampler.m_texture.Load(ivec3(_coord, _lod), _offset ); +} + +vec2 bgfxTextureSize(BgfxSampler2D _sampler, int _lod) +{ + vec2 result; + _sampler.m_texture.GetDimensions(result.x, result.y); + return result; +} + +vec4 bgfxTextureGather(BgfxSampler2D _sampler, vec2 _coord) +{ + return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord ); +} +vec4 bgfxTextureGatherOffset(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset) +{ + return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord, _offset ); +} +vec4 bgfxTextureGather(BgfxSampler2DArray _sampler, vec3 _coord) +{ + return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord ); +} + +ivec4 bgfxTexelFetch(BgfxISampler2D _sampler, ivec2 _coord, int _lod) +{ + return _sampler.m_texture.Load(ivec3(_coord, _lod) ); +} + +uvec4 bgfxTexelFetch(BgfxUSampler2D _sampler, ivec2 _coord, int _lod) +{ + return _sampler.m_texture.Load(ivec3(_coord, _lod) ); +} + +vec4 bgfxTexelFetch(BgfxSampler2DMS _sampler, ivec2 _coord, int _sampleIdx) +{ + return _sampler.m_texture.Load(_coord, _sampleIdx); +} + +vec4 bgfxTexelFetch(BgfxSampler2DArray _sampler, ivec3 _coord, int _lod) +{ + return _sampler.m_texture.Load(ivec4(_coord, _lod) ); +} + +vec4 bgfxTexelFetch(BgfxSampler3D _sampler, ivec3 _coord, int _lod) +{ + return _sampler.m_texture.Load(ivec4(_coord, _lod) ); +} + +vec3 bgfxTextureSize(BgfxSampler3D _sampler, int _lod) +{ + vec3 result; + _sampler.m_texture.GetDimensions(result.x, result.y, result.z); + return result; +} + +# define SAMPLER2D(_name, _reg) \ + uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ + uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ + static BgfxSampler2D _name = { _name ## Sampler, _name ## Texture } +# define ISAMPLER2D(_name, _reg) \ + uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ + static BgfxISampler2D _name = { _name ## Texture } +# define USAMPLER2D(_name, _reg) \ + uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ + static BgfxUSampler2D _name = { _name ## Texture } +# define sampler2D BgfxSampler2D +# define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord) +# define texture2DBias(_sampler, _coord, _bias) bgfxTexture2DBias(_sampler, _coord, _bias) +# define texture2DLod(_sampler, _coord, _level) bgfxTexture2DLod(_sampler, _coord, _level) +# define texture2DLodOffset(_sampler, _coord, _level, _offset) bgfxTexture2DLodOffset(_sampler, _coord, _level, _offset) +# define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) +# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) bgfxTexture2DGrad(_sampler, _coord, _dPdx, _dPdy) + +# define SAMPLER2DARRAY(_name, _reg) \ + uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ + uniform Texture2DArray _name ## Texture : REGISTER(t, _reg); \ + static BgfxSampler2DArray _name = { _name ## Sampler, _name ## Texture } +# define sampler2DArray BgfxSampler2DArray +# define texture2DArray(_sampler, _coord) bgfxTexture2DArray(_sampler, _coord) +# define texture2DArrayLod(_sampler, _coord, _lod) bgfxTexture2DArrayLod(_sampler, _coord, _lod) +# define texture2DArrayLodOffset(_sampler, _coord, _level, _offset) bgfxTexture2DArrayLodOffset(_sampler, _coord, _level, _offset) + +# define SAMPLER2DMS(_name, _reg) \ + uniform Texture2DMS _name ## Texture : REGISTER(t, _reg); \ + static BgfxSampler2DMS _name = { _name ## Texture } +# define sampler2DMS BgfxSampler2DMS + +# define SAMPLER2DSHADOW(_name, _reg) \ + uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ + uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ + static BgfxSampler2DShadow _name = { _name ## SamplerComparison, _name ## Texture } +# define sampler2DShadow BgfxSampler2DShadow +# define shadow2D(_sampler, _coord) bgfxShadow2D(_sampler, _coord) +# define shadow2DProj(_sampler, _coord) bgfxShadow2DProj(_sampler, _coord) + +# define SAMPLER2DARRAYSHADOW(_name, _reg) \ + uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ + uniform Texture2DArray _name ## Texture : REGISTER(t, _reg); \ + static BgfxSampler2DArrayShadow _name = { _name ## SamplerComparison, _name ## Texture } +# define sampler2DArrayShadow BgfxSampler2DArrayShadow +# define shadow2DArray(_sampler, _coord) bgfxShadow2DArray(_sampler, _coord) + +# define SAMPLER3D(_name, _reg) \ + uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ + uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ + static BgfxSampler3D _name = { _name ## Sampler, _name ## Texture } +# define ISAMPLER3D(_name, _reg) \ + uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ + static BgfxISampler3D _name = { _name ## Texture } +# define USAMPLER3D(_name, _reg) \ + uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ + static BgfxUSampler3D _name = { _name ## Texture } +# define sampler3D BgfxSampler3D +# define texture3D(_sampler, _coord) bgfxTexture3D(_sampler, _coord) +# define texture3DLod(_sampler, _coord, _level) bgfxTexture3DLod(_sampler, _coord, _level) + +# define SAMPLERCUBE(_name, _reg) \ + uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ + uniform TextureCube _name ## Texture : REGISTER(t, _reg); \ + static BgfxSamplerCube _name = { _name ## Sampler, _name ## Texture } +# define samplerCube BgfxSamplerCube +# define textureCube(_sampler, _coord) bgfxTextureCube(_sampler, _coord) +# define textureCubeBias(_sampler, _coord, _bias) bgfxTextureCubeBias(_sampler, _coord, _bias) +# define textureCubeLod(_sampler, _coord, _level) bgfxTextureCubeLod(_sampler, _coord, _level) + +# define SAMPLERCUBESHADOW(_name, _reg) \ + uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ + uniform TextureCube _name ## Texture : REGISTER(t, _reg); \ + static BgfxSamplerCubeShadow _name = { _name ## SamplerComparison, _name ## Texture } +# define samplerCubeShadow BgfxSamplerCubeShadow +# define shadowCube(_sampler, _coord) bgfxShadowCube(_sampler, _coord) + +# define texelFetch(_sampler, _coord, _lod) bgfxTexelFetch(_sampler, _coord, _lod) +# define texelFetchOffset(_sampler, _coord, _lod, _offset) bgfxTexelFetchOffset(_sampler, _coord, _lod, _offset) +# define textureSize(_sampler, _lod) bgfxTextureSize(_sampler, _lod) +# define textureGather(_sampler, _coord) bgfxTextureGather(_sampler, _coord) +# define textureGatherOffset(_sampler, _coord, _offset) bgfxTextureGatherOffset(_sampler, _coord, _offset) +# else + +# define sampler2DShadow sampler2D + +vec4 bgfxTexture2DProj(sampler2D _sampler, vec3 _coord) +{ + return tex2Dproj(_sampler, vec4(_coord.xy, 0.0, _coord.z) ); +} + +vec4 bgfxTexture2DProj(sampler2D _sampler, vec4 _coord) +{ + return tex2Dproj(_sampler, _coord); +} + +float bgfxShadow2D(sampler2DShadow _sampler, vec3 _coord) +{ +#if 0 + float occluder = tex2D(_sampler, _coord.xy).x; + return step(_coord.z, occluder); +#else + return tex2Dproj(_sampler, vec4(_coord.xy, _coord.z, 1.0) ).x; +#endif // 0 +} + +float bgfxShadow2DProj(sampler2DShadow _sampler, vec4 _coord) +{ +#if 0 + vec3 coord = _coord.xyz * rcp(_coord.w); + float occluder = tex2D(_sampler, coord.xy).x; + return step(coord.z, occluder); +#else + return tex2Dproj(_sampler, _coord).x; +#endif // 0 +} + +# define SAMPLER2D(_name, _reg) uniform sampler2D _name : REGISTER(s, _reg) +# define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name : REGISTER(s, _reg) +# define texture2D(_sampler, _coord) tex2D(_sampler, _coord) +# define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) + +# define SAMPLER2DARRAY(_name, _reg) SAMPLER2D(_name, _reg) +# define texture2DArray(_sampler, _coord) texture2D(_sampler, (_coord).xy) +# define texture2DArrayLod(_sampler, _coord, _lod) texture2DLod(_sampler, _coord, _lod) + +# define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name : REGISTER(s, _reg) +# define shadow2D(_sampler, _coord) bgfxShadow2D(_sampler, _coord) +# define shadow2DProj(_sampler, _coord) bgfxShadow2DProj(_sampler, _coord) + +# define SAMPLER3D(_name, _reg) uniform sampler3D _name : REGISTER(s, _reg) +# define texture3D(_sampler, _coord) tex3D(_sampler, _coord) + +# define SAMPLERCUBE(_name, _reg) uniform samplerCUBE _name : REGISTER(s, _reg) +# define textureCube(_sampler, _coord) texCUBE(_sampler, _coord) + +# define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec4( (_coord).xy, 0.0, _level) ) +# define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) tex2Dgrad(_sampler, _coord, _dPdx, _dPdy) +# define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) ) +# define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) ) + +# endif // BGFX_SHADER_LANGUAGE_HLSL > 300 + +vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_mtx, _vec); } +vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_vec, _mtx); } +vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_mtx, _vec); } +vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_vec, _mtx); } + +bvec2 lessThan(vec2 _a, vec2 _b) { return _a < _b; } +bvec3 lessThan(vec3 _a, vec3 _b) { return _a < _b; } +bvec4 lessThan(vec4 _a, vec4 _b) { return _a < _b; } + +bvec2 lessThanEqual(vec2 _a, vec2 _b) { return _a <= _b; } +bvec3 lessThanEqual(vec3 _a, vec3 _b) { return _a <= _b; } +bvec4 lessThanEqual(vec4 _a, vec4 _b) { return _a <= _b; } + +bvec2 greaterThan(vec2 _a, vec2 _b) { return _a > _b; } +bvec3 greaterThan(vec3 _a, vec3 _b) { return _a > _b; } +bvec4 greaterThan(vec4 _a, vec4 _b) { return _a > _b; } + +bvec2 greaterThanEqual(vec2 _a, vec2 _b) { return _a >= _b; } +bvec3 greaterThanEqual(vec3 _a, vec3 _b) { return _a >= _b; } +bvec4 greaterThanEqual(vec4 _a, vec4 _b) { return _a >= _b; } + +bvec2 notEqual(vec2 _a, vec2 _b) { return _a != _b; } +bvec3 notEqual(vec3 _a, vec3 _b) { return _a != _b; } +bvec4 notEqual(vec4 _a, vec4 _b) { return _a != _b; } + +bvec2 equal(vec2 _a, vec2 _b) { return _a == _b; } +bvec3 equal(vec3 _a, vec3 _b) { return _a == _b; } +bvec4 equal(vec4 _a, vec4 _b) { return _a == _b; } + +float mix(float _a, float _b, float _t) { return lerp(_a, _b, _t); } +vec2 mix(vec2 _a, vec2 _b, vec2 _t) { return lerp(_a, _b, _t); } +vec3 mix(vec3 _a, vec3 _b, vec3 _t) { return lerp(_a, _b, _t); } +vec4 mix(vec4 _a, vec4 _b, vec4 _t) { return lerp(_a, _b, _t); } + +float mod(float _a, float _b) { return _a - _b * floor(_a / _b); } +vec2 mod(vec2 _a, vec2 _b) { return _a - _b * floor(_a / _b); } +vec3 mod(vec3 _a, vec3 _b) { return _a - _b * floor(_a / _b); } +vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); } + +#else +# define CONST(_x) const _x +# define atan2(_x, _y) atan(_x, _y) +# define mul(_a, _b) ( (_a) * (_b) ) +# define saturate(_x) clamp(_x, 0.0, 1.0) +# define SAMPLER2D(_name, _reg) uniform sampler2D _name +# define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name +# define SAMPLER3D(_name, _reg) uniform sampler3D _name +# define SAMPLERCUBE(_name, _reg) uniform samplerCube _name +# define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name + +# define SAMPLER2DARRAY(_name, _reg) uniform sampler2DArray _name +# define SAMPLER2DMSARRAY(_name, _reg) uniform sampler2DMSArray _name +# define SAMPLERCUBEARRAY(_name, _reg) uniform samplerCubeArray _name +# define SAMPLER2DARRAYSHADOW(_name, _reg) uniform sampler2DArrayShadow _name + +# define ISAMPLER2D(_name, _reg) uniform isampler2D _name +# define USAMPLER2D(_name, _reg) uniform usampler2D _name +# define ISAMPLER3D(_name, _reg) uniform isampler3D _name +# define USAMPLER3D(_name, _reg) uniform usampler3D _name + +# define texture2DBias(_sampler, _coord, _bias) texture2D(_sampler, _coord, _bias) +# define textureCubeBias(_sampler, _coord, _bias) textureCube(_sampler, _coord, _bias) + +# if BGFX_SHADER_LANGUAGE_GLSL >= 130 +# define texture2D(_sampler, _coord) texture(_sampler, _coord) +# define texture2DArray(_sampler, _coord) texture(_sampler, _coord) +# define texture3D(_sampler, _coord) texture(_sampler, _coord) +# define texture2DLod(_sampler, _coord, _lod) textureLod(_sampler, _coord, _lod) +# define texture2DLodOffset(_sampler, _coord, _lod, _offset) textureLodOffset(_sampler, _coord, _lod, _offset) +# endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 + +vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); } +vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_mtx, _vec); } +vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_vec, _mtx); } +vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_mtx, _vec); } + +float rcp(float _a) { return 1.0/_a; } +vec2 rcp(vec2 _a) { return vec2(1.0)/_a; } +vec3 rcp(vec3 _a) { return vec3(1.0)/_a; } +vec4 rcp(vec4 _a) { return vec4(1.0)/_a; } +#endif // BGFX_SHADER_LANGUAGE_* + +vec2 vec2_splat(float _x) { return vec2(_x, _x); } +vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); } +vec4 vec4_splat(float _x) { return vec4(_x, _x, _x, _x); } + +#if BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL +uvec2 uvec2_splat(uint _x) { return uvec2(_x, _x); } +uvec3 uvec3_splat(uint _x) { return uvec3(_x, _x, _x); } +uvec4 uvec4_splat(uint _x) { return uvec4(_x, _x, _x, _x); } +#endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL + +mat4 mtxFromRows(vec4 _0, vec4 _1, vec4 _2, vec4 _3) +{ +#if BGFX_SHADER_LANGUAGE_GLSL + return transpose(mat4(_0, _1, _2, _3) ); +#else + return mat4(_0, _1, _2, _3); +#endif // BGFX_SHADER_LANGUAGE_GLSL +} +mat4 mtxFromCols(vec4 _0, vec4 _1, vec4 _2, vec4 _3) +{ +#if BGFX_SHADER_LANGUAGE_GLSL + return mat4(_0, _1, _2, _3); +#else + return transpose(mat4(_0, _1, _2, _3) ); +#endif // BGFX_SHADER_LANGUAGE_GLSL +} +mat3 mtxFromRows(vec3 _0, vec3 _1, vec3 _2) +{ +#if BGFX_SHADER_LANGUAGE_GLSL + return transpose(mat3(_0, _1, _2) ); +#else + return mat3(_0, _1, _2); +#endif // BGFX_SHADER_LANGUAGE_GLSL +} +mat3 mtxFromCols(vec3 _0, vec3 _1, vec3 _2) +{ +#if BGFX_SHADER_LANGUAGE_GLSL + return mat3(_0, _1, _2); +#else + return transpose(mat3(_0, _1, _2) ); +#endif // BGFX_SHADER_LANGUAGE_GLSL +} + +#if BGFX_SHADER_LANGUAGE_GLSL +#define mtxFromRows3(_0, _1, _2) transpose(mat3(_0, _1, _2) ) +#define mtxFromRows4(_0, _1, _2, _3) transpose(mat4(_0, _1, _2, _3) ) +#define mtxFromCols3(_0, _1, _2) mat3(_0, _1, _2) +#define mtxFromCols4(_0, _1, _2, _3) mat4(_0, _1, _2, _3) +#else +#define mtxFromRows3(_0, _1, _2) mat3(_0, _1, _2) +#define mtxFromRows4(_0, _1, _2, _3) mat4(_0, _1, _2, _3) +#define mtxFromCols3(_0, _1, _2) transpose(mat3(_0, _1, _2) ) +#define mtxFromCols4(_0, _1, _2, _3) transpose(mat4(_0, _1, _2, _3) ) +#endif // BGFX_SHADER_LANGUAGE_GLSL + +uniform vec4 u_viewRect; +uniform vec4 u_viewTexel; +uniform mat4 u_view; +uniform mat4 u_invView; +uniform mat4 u_proj; +uniform mat4 u_invProj; +uniform mat4 u_viewProj; +uniform mat4 u_invViewProj; +uniform mat4 u_model[BGFX_CONFIG_MAX_BONES]; +uniform mat4 u_modelView; +uniform mat4 u_modelViewProj; +uniform vec4 u_alphaRef4; +#define u_alphaRef u_alphaRef4.x + +#endif // __cplusplus + +#endif // BGFX_SHADER_H_HEADER_GUARD diff --git a/resources/shaders/forward_pipeline.sh b/resources/shaders/forward_pipeline.sh index fc67b1e..a7fd130 100644 --- a/resources/shaders/forward_pipeline.sh +++ b/resources/shaders/forward_pipeline.sh @@ -1,94 +1,167 @@ -#include - -#define PI 3.14159265359 - -uniform vec4 uClock; // clock - -// Environment -uniform vec4 uFogColor; -uniform vec4 uFogState; // fog_near, 1.0/fog_range - -// Lighting environment -uniform vec4 uAmbientColor; - -uniform vec4 uLightPos[8]; // pos.xyz, 1.0/radius -uniform vec4 uLightDir[8]; // dir.xyz, inner_rim -uniform vec4 uLightDiffuse[8]; // diffuse.xyz, outer_rim -uniform vec4 uLightSpecular[8]; // specular.xyz, pssm_bias - -uniform mat4 uLinearShadowMatrix[4]; // slot 0: linear PSSM shadow matrices -uniform vec4 uLinearShadowSlice; // slot 0: PSSM slice distances linear light -uniform mat4 uSpotShadowMatrix; // slot 1: spot shadow matrix -uniform vec4 uShadowState; // slot 0: inverse resolution, slot1: inverse resolution, slot0: bias, slot1: bias - -uniform vec4 uResolution; // xy: backbuffer resolution -uniform vec4 uProjection; -uniform mat4 uMainProjection; // projection for the main render (used by screenspace post-processes) -uniform mat4 uMainInvProjection; // inverse projection for the main render (used by screenspace post-processes) - -uniform mat4 uPreviousViewProjection; -uniform mat4 uPreviousModel[BGFX_CONFIG_MAX_BONES]; -uniform mat4 uViewProjUnjittered; -uniform vec4 uAAAParams[2]; // [0].x: ssgi ratio, [0].y: ssr ratio, [0].z: temporal AA weight, [0].w: motion blur strength, [1].x: exposure, [1].y: 1/gamma, [1].z: sample count, [1].w: max radius - -uniform mat4 uMainInvView; // inversion view matrix - -#if FORWARD_PIPELINE_AAA -SAMPLER2D(uIrradianceMap, 8); -SAMPLER2D(uRadianceMap, 9); -#else -SAMPLERCUBE(uIrradianceMap, 8); -SAMPLERCUBE(uRadianceMap, 9); -#endif -SAMPLER2D(uBrdfMap, 10); -SAMPLER2D(uNoiseMap, 11); -SAMPLER2D(uAmbientOcclusion, 13); -SAMPLER2DSHADOW(uLinearShadowMap, 14); -SAMPLER2DSHADOW(uSpotShadowMap, 15); - -// -float sRGB2linear(float v) { - return (v < 0.04045) ? (v * 0.0773993808) : pow((v + 0.055) / 1.055, 2.4); -} - -vec3 sRGB2linear(vec3 v) { - return vec3(sRGB2linear(v.x), sRGB2linear(v.y), sRGB2linear(v.z)); -} - -// -mat3 MakeMat3(vec3 c0, vec3 c1, vec3 c2) { - return mat3(c0, c1, c2); -} - -vec3 GetT(mat4 m) { -#if BGFX_SHADER_LANGUAGE_GLSL - return vec3(m[3][0], m[3][1], m[3][2]); -#else - return vec3(m[0][3], m[1][3], m[2][3]); -#endif -} - -float LinearDepth(float z) { - return uProjection.w / (z - uProjection.z); -} - -// from screen space to view space -vec3 Unproject(vec3 frag_coord) { - vec4 clip = vec4(((frag_coord.xy - u_viewRect.xy) / u_viewRect.zw) * 2. - 1., frag_coord.z, 1.); - vec4 ndc = mul(clip, uMainInvProjection); - return ndc.xyz / ndc.w; -} - -vec3 ComputeFragCoordViewRay(vec2 frag_coord) -{ - vec2 sp = ((frag_coord - u_viewRect.xy) / u_viewRect.zw) * 2. - 1.; - sp.y *= -1.; - - vec4 ndc = mul(uMainInvProjection, vec4(sp, 1., 1.)); // far ndc frustum plane - ndc /= ndc.w; - ndc /= ndc.z; - - return ndc.xyz; -} - -bool isNan(float val) { return (val <= 0.0 || 0.0 <= val) ? false : true; } +// HARFANG(R) Copyright (C) 2022 Emmanuel Julien, NWNC HARFANG. Released under GPL/LGPL/Commercial Licence, see licence.txt for details. + +// DO NOT MODIFY THIS FILE! + +#include + +#define PI 3.14159265359 + +uniform vec4 uClock; // clock + +// Environment +uniform vec4 uFogColor; +uniform vec4 uFogState; // fog_near, 1.0/fog_range + +// Lighting environment +uniform vec4 uAmbientColor; + +uniform vec4 uLightPos[8]; // pos.xyz, 1.0/radius +uniform vec4 uLightDir[8]; // dir.xyz, inner_rim +uniform vec4 uLightDiffuse[8]; // diffuse.xyz, outer_rim +uniform vec4 uLightSpecular[8]; // specular.xyz, pssm_bias + +uniform mat4 uLinearShadowMatrix[4]; // slot 0: linear PSSM shadow matrices +uniform vec4 uLinearShadowSlice; // slot 0: PSSM slice distances linear light +uniform mat4 uSpotShadowMatrix; // slot 1: spot shadow matrix +uniform vec4 uShadowState; // slot 0: inverse resolution, slot1: inverse resolution, slot0: bias, slot1: bias + +uniform vec4 uResolution; // xy: backbuffer resolution +uniform vec4 uProjection; +uniform mat4 uMainProjection; // projection for the main render (used by screenspace post-processes) +uniform mat4 uMainInvProjection; // inverse projection for the main render (used by screenspace post-processes) + +uniform mat4 uPreviousViewProjection; +uniform mat4 uPreviousModel[BGFX_CONFIG_MAX_BONES]; +uniform mat4 uViewProjUnjittered; +uniform vec4 uAAAParams[3]; // [0].x: ssgi ratio, [0].y: ssr ratio, [0].z: temporal AA weight, [0].w: motion blur strength, + // [1].x: exposure, [1].y: 1/gamma, [1].z: sample count, [1].w: screenspace ray max length + // [2].x: specular weight, [2].y: sharpen + +uniform mat4 uMainInvView; // inversion view matrix +uniform mat4 uProbeMatrix; +uniform mat4 uInvProbeMatrix; +uniform vec4 uProbeData; + +/* + Reserved texture units for the AAA forward pipeline. + Do not modify these slots, they are hardcoded on the C++ side. + + If reserving new slots for the pipeline please keep in mind WebGL limitations: https://webglreport.com/?v=2 + At the moment it is not advisable to use texture units beyond 16 for embedded platforms. +*/ +SAMPLERCUBE(uIrradianceMap, 8); +SAMPLERCUBE(uRadianceMap, 9); +SAMPLER2D(uSSIrradianceMap, 10); +SAMPLER2D(uSSRadianceMap, 11); +SAMPLER2D(uBrdfMap, 12); +SAMPLER2D(uNoiseMap, 13); +SAMPLER2DSHADOW(uLinearShadowMap, 14); +SAMPLER2DSHADOW(uSpotShadowMap, 15); + +// +float sRGB2linear(float v) { + return (v < 0.04045) ? (v * 0.0773993808) : pow((v + 0.055) / 1.055, 2.4); +} + +vec3 sRGB2linear(vec3 v) { + return vec3(sRGB2linear(v.x), sRGB2linear(v.y), sRGB2linear(v.z)); +} + +// +mat3 MakeMat3(vec3 c0, vec3 c1, vec3 c2) { + return mat3(c0, c1, c2); +} + +vec3 GetT(mat4 m) { +#if BGFX_SHADER_LANGUAGE_GLSL + return vec3(m[3][0], m[3][1], m[3][2]); +#else + return vec3(m[0][3], m[1][3], m[2][3]); +#endif +} + +float LinearDepth(float z) { + return uProjection.w / (z - uProjection.z); +} + +// from screen space to view space +vec3 Unproject(vec3 frag_coord) { + vec4 clip = vec4(((frag_coord.xy - u_viewRect.xy) / u_viewRect.zw) * 2. - 1., frag_coord.z, 1.); + vec4 ndc = mul(clip, uMainInvProjection); + return ndc.xyz / ndc.w; +} + +vec3 ComputeFragCoordViewRay(vec2 frag_coord) { + vec2 sp = ((frag_coord - u_viewRect.xy) / u_viewRect.zw) * 2. - 1.; + sp.y *= -1.; + + vec4 ndc = mul(uMainInvProjection, vec4(sp, 1., 1.)); // far ndc frustum plane + ndc /= ndc.w; + ndc /= ndc.z; + + return ndc.xyz; +} + +bool isNan(float val) { return (val <= 0.0 || 0.0 <= val) ? false : true; } + +// +vec2 RaySphere(vec3 r0, vec3 rd, vec3 s0, float sr) { + float a = dot(rd, rd); + vec3 s0_r0 = r0 - s0; + + float b = 2.0 * dot(rd, s0_r0); + float c = dot(s0_r0, s0_r0) - (sr * sr); + float disc = b * b - 4.0 * a* c; + + if (disc < 0.0) + return vec2(-1.0, -1.0); + + return vec2(-b - sqrt(disc), -b + sqrt(disc)) / (2.0 * a); +} + +vec3 RayBox(vec3 ray_origin, vec3 ray_dir, vec3 minpos, vec3 maxpos) { + vec3 inverse_dir = 1.0 / ray_dir; + vec3 tbot = inverse_dir * (minpos - ray_origin); + vec3 ttop = inverse_dir * (maxpos - ray_origin); + vec3 tmin = min(ttop, tbot); + vec3 tmax = max(ttop, tbot); + vec2 traverse = max(tmin.xx, tmin.yz); + float traverselow = max(traverse.x, traverse.y); + traverse = min(tmax.xx, tmax.yz); + float traversehi = min(traverse.x, traverse.y); + return vec3(float(traversehi > max(traverselow, 0.0)), traversehi, traverselow); +} + +vec3 ReprojectProbe(vec3 O, vec3 V) { + vec3 W; + + if (uProbeData.x == 0.0) { + vec3 local_O = mul(uInvProbeMatrix, vec4(O, 1.0)).xyz; // move ray to probe volume space + vec3 local_V = mul(uInvProbeMatrix, vec4(V, 0.0)).xyz; + local_V = normalize(local_V); + + vec2 T = RaySphere(local_O, local_V, vec3(0.0, 0.0, 0.0), 0.5); + + if (T.y > -1.0) { + vec3 local_I = local_O + local_V * T.y; + W = normalize(mul(uProbeMatrix, vec4(local_I, 0.0)).xyz); + } else { + return V; + } + } else if (uProbeData.x == 1.0) { + vec3 local_O = mul(uInvProbeMatrix, vec4(O, 1.0)).xyz; // move ray to probe volume space + vec3 local_V = mul(uInvProbeMatrix, vec4(V, 0.0)).xyz; + local_V = normalize(local_V); + + vec3 T = RayBox(local_O, local_V, vec3(-0.5, -0.5, -0.5), vec3(0.5, 0.5, 0.5)); // intersect with volume + + if (T.x == 0.0) { + return V; + } else { + vec3 local_I = local_O + local_V * T.y; + W = normalize(mul(uProbeMatrix, vec4(local_I, 0.0)).xyz); // move intersection back to world space + } + } + + return normalize(mix(V, W, uProbeData.y)); +}