diff --git a/native/cocos/bindings/auto/jsb_scene_auto.cpp b/native/cocos/bindings/auto/jsb_scene_auto.cpp index b60d96d79e..21df532bf8 100644 --- a/native/cocos/bindings/auto/jsb_scene_auto.cpp +++ b/native/cocos/bindings/auto/jsb_scene_auto.cpp @@ -438,6 +438,90 @@ bool js_register_scene_DirectionalLight(se::Object* obj) // NOLINT(readability-i se::Object* __jsb_cc_scene_Plane_proto = nullptr; se::Class* __jsb_cc_scene_Plane_class = nullptr; +static bool js_scene_Plane_clone(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Plane_clone : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + cc::scene::Plane result = cobj->clone(); + ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); + SE_PRECONDITION2(ok, false, "js_scene_Plane_clone : Error processing arguments"); + SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_FUNC(js_scene_Plane_clone) + +static bool js_scene_Plane_define(se::State& s) // NOLINT(readability-identifier-naming) +{ + CC_UNUSED bool ok = true; + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2( cobj, false, "js_scene_Plane_define : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + do { + if (argc == 2) { + HolderType arg0 = {}; + HolderType arg1 = {}; + + ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); + if (!ok) { ok = true; break; } + ok &= sevalue_to_native(args[1], &arg1, s.thisObject()); + if (!ok) { ok = true; break; } + cobj->define(arg0.value(), arg1.value()); + return true; + } + } while(false); + + do { + if (argc == 3) { + HolderType arg0 = {}; + HolderType arg1 = {}; + HolderType arg2 = {}; + + ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); + if (!ok) { ok = true; break; } + ok &= sevalue_to_native(args[1], &arg1, s.thisObject()); + if (!ok) { ok = true; break; } + ok &= sevalue_to_native(args[2], &arg2, s.thisObject()); + if (!ok) { ok = true; break; } + cobj->define(arg0.value(), arg1.value(), arg2.value()); + return true; + } + } while(false); + + SE_REPORT_ERROR("wrong number of arguments: %d", (int)argc); + return false; +} +SE_BIND_FUNC(js_scene_Plane_define) + +static bool js_scene_Plane_distance(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Plane_distance : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 1) { + HolderType arg0 = {}; + ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_scene_Plane_distance : Error processing arguments"); + float result = cobj->distance(arg0.value()); + ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); + SE_PRECONDITION2(ok, false, "js_scene_Plane_distance : Error processing arguments"); + SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; +} +SE_BIND_FUNC(js_scene_Plane_distance) + static bool js_scene_Plane_get_d(se::State& s) // NOLINT(readability-identifier-naming) { auto* cobj = SE_THIS_OBJECT(s); @@ -591,6 +675,9 @@ bool js_register_scene_Plane(se::Object* obj) // NOLINT(readability-identifier-n cls->defineProperty("d", _SE(js_scene_Plane_get_d), _SE(js_scene_Plane_set_d)); cls->defineProperty("n", _SE(js_scene_Plane_get_n), _SE(js_scene_Plane_set_n)); + cls->defineFunction("clone", _SE(js_scene_Plane_clone)); + cls->defineFunction("define", _SE(js_scene_Plane_define)); + cls->defineFunction("distance", _SE(js_scene_Plane_distance)); cls->defineFinalizeFunction(_SE(js_cc_scene_Plane_finalize)); cls->install(); JSBClassType::registerClass(cls); @@ -604,6 +691,98 @@ bool js_register_scene_Plane(se::Object* obj) // NOLINT(readability-identifier-n se::Object* __jsb_cc_scene_Frustum_proto = nullptr; se::Class* __jsb_cc_scene_Frustum_class = nullptr; +static bool js_scene_Frustum_clone(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Frustum_clone : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 0) { + cc::scene::Frustum result = cobj->clone(); + ok &= nativevalue_to_se(result, s.rval(), nullptr /*ctx*/); + SE_PRECONDITION2(ok, false, "js_scene_Frustum_clone : Error processing arguments"); + SE_HOLD_RETURN_VALUE(result, s.thisObject(), s.rval()); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 0); + return false; +} +SE_BIND_FUNC(js_scene_Frustum_clone) + +static bool js_scene_Frustum_createOrtho(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Frustum_createOrtho : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 5) { + HolderType arg0 = {}; + HolderType arg1 = {}; + HolderType arg2 = {}; + HolderType arg3 = {}; + HolderType arg4 = {}; + ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); + ok &= sevalue_to_native(args[1], &arg1, s.thisObject()); + ok &= sevalue_to_native(args[2], &arg2, s.thisObject()); + ok &= sevalue_to_native(args[3], &arg3, s.thisObject()); + ok &= sevalue_to_native(args[4], &arg4, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_scene_Frustum_createOrtho : Error processing arguments"); + cobj->createOrtho(arg0.value(), arg1.value(), arg2.value(), arg3.value(), arg4.value()); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 5); + return false; +} +SE_BIND_FUNC(js_scene_Frustum_createOrtho) + +static bool js_scene_Frustum_split(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Frustum_split : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 5) { + HolderType arg0 = {}; + HolderType arg1 = {}; + HolderType arg2 = {}; + HolderType arg3 = {}; + HolderType arg4 = {}; + ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); + ok &= sevalue_to_native(args[1], &arg1, s.thisObject()); + ok &= sevalue_to_native(args[2], &arg2, s.thisObject()); + ok &= sevalue_to_native(args[3], &arg3, s.thisObject()); + ok &= sevalue_to_native(args[4], &arg4, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_scene_Frustum_split : Error processing arguments"); + cobj->split(arg0.value(), arg1.value(), arg2.value(), arg3.value(), arg4.value()); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 5); + return false; +} +SE_BIND_FUNC(js_scene_Frustum_split) + +static bool js_scene_Frustum_transform(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Frustum_transform : Invalid Native Object"); + const auto& args = s.args(); + size_t argc = args.size(); + CC_UNUSED bool ok = true; + if (argc == 1) { + HolderType arg0 = {}; + ok &= sevalue_to_native(args[0], &arg0, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_scene_Frustum_transform : Error processing arguments"); + cobj->transform(arg0.value()); + return true; + } + SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 1); + return false; +} +SE_BIND_FUNC(js_scene_Frustum_transform) + static bool js_scene_Frustum_get_vertices(se::State& s) // NOLINT(readability-identifier-naming) { auto* cobj = SE_THIS_OBJECT(s); @@ -764,6 +943,10 @@ bool js_register_scene_Frustum(se::Object* obj) // NOLINT(readability-identifier cls->defineProperty("vertices", _SE(js_scene_Frustum_get_vertices), _SE(js_scene_Frustum_set_vertices)); cls->defineProperty("planes", _SE(js_scene_Frustum_get_planes), _SE(js_scene_Frustum_set_planes)); + cls->defineFunction("clone", _SE(js_scene_Frustum_clone)); + cls->defineFunction("createOrtho", _SE(js_scene_Frustum_createOrtho)); + cls->defineFunction("split", _SE(js_scene_Frustum_split)); + cls->defineFunction("transform", _SE(js_scene_Frustum_transform)); cls->defineFinalizeFunction(_SE(js_cc_scene_Frustum_finalize)); cls->install(); JSBClassType::registerClass(cls); @@ -2323,32 +2506,32 @@ static bool js_scene_Shadow_set_shadowMapDirty(se::State& s) // NOLINT(readabili } SE_BIND_PROP_SET(js_scene_Shadow_set_shadowMapDirty) -static bool js_scene_Shadow_get_autoAdapt(se::State& s) // NOLINT(readability-identifier-naming) +static bool js_scene_Shadow_get_fixedArea(se::State& s) // NOLINT(readability-identifier-naming) { auto* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_scene_Shadow_get_autoAdapt : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_scene_Shadow_get_fixedArea : Invalid Native Object"); CC_UNUSED bool ok = true; se::Value jsret; - ok &= nativevalue_to_se(cobj->autoAdapt, jsret, s.thisObject() /*ctx*/); + ok &= nativevalue_to_se(cobj->fixedArea, jsret, s.thisObject() /*ctx*/); s.rval() = jsret; - SE_HOLD_RETURN_VALUE(cobj->autoAdapt, s.thisObject(), s.rval()); + SE_HOLD_RETURN_VALUE(cobj->fixedArea, s.thisObject(), s.rval()); return true; } -SE_BIND_PROP_GET(js_scene_Shadow_get_autoAdapt) +SE_BIND_PROP_GET(js_scene_Shadow_get_fixedArea) -static bool js_scene_Shadow_set_autoAdapt(se::State& s) // NOLINT(readability-identifier-naming) +static bool js_scene_Shadow_set_fixedArea(se::State& s) // NOLINT(readability-identifier-naming) { const auto& args = s.args(); auto* cobj = SE_THIS_OBJECT(s); - SE_PRECONDITION2(cobj, false, "js_scene_Shadow_set_autoAdapt : Invalid Native Object"); + SE_PRECONDITION2(cobj, false, "js_scene_Shadow_set_fixedArea : Invalid Native Object"); CC_UNUSED bool ok = true; - ok &= sevalue_to_native(args[0], &cobj->autoAdapt, s.thisObject()); - SE_PRECONDITION2(ok, false, "js_scene_Shadow_set_autoAdapt : Error processing new value"); + ok &= sevalue_to_native(args[0], &cobj->fixedArea, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_scene_Shadow_set_fixedArea : Error processing new value"); return true; } -SE_BIND_PROP_SET(js_scene_Shadow_set_autoAdapt) +SE_BIND_PROP_SET(js_scene_Shadow_set_fixedArea) static bool js_scene_Shadow_get_shadowType(se::State& s) // NOLINT(readability-identifier-naming) { @@ -2377,6 +2560,60 @@ static bool js_scene_Shadow_set_shadowType(se::State& s) // NOLINT(readability-i } SE_BIND_PROP_SET(js_scene_Shadow_set_shadowType) +static bool js_scene_Shadow_get_invisibleOcclusionRange(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Shadow_get_invisibleOcclusionRange : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= nativevalue_to_se(cobj->invisibleOcclusionRange, jsret, s.thisObject() /*ctx*/); + s.rval() = jsret; + SE_HOLD_RETURN_VALUE(cobj->invisibleOcclusionRange, s.thisObject(), s.rval()); + return true; +} +SE_BIND_PROP_GET(js_scene_Shadow_get_invisibleOcclusionRange) + +static bool js_scene_Shadow_set_invisibleOcclusionRange(se::State& s) // NOLINT(readability-identifier-naming) +{ + const auto& args = s.args(); + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Shadow_set_invisibleOcclusionRange : Invalid Native Object"); + + CC_UNUSED bool ok = true; + ok &= sevalue_to_native(args[0], &cobj->invisibleOcclusionRange, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_scene_Shadow_set_invisibleOcclusionRange : Error processing new value"); + return true; +} +SE_BIND_PROP_SET(js_scene_Shadow_set_invisibleOcclusionRange) + +static bool js_scene_Shadow_get_shadowDistance(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Shadow_get_shadowDistance : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= nativevalue_to_se(cobj->shadowDistance, jsret, s.thisObject() /*ctx*/); + s.rval() = jsret; + SE_HOLD_RETURN_VALUE(cobj->shadowDistance, s.thisObject(), s.rval()); + return true; +} +SE_BIND_PROP_GET(js_scene_Shadow_get_shadowDistance) + +static bool js_scene_Shadow_set_shadowDistance(se::State& s) // NOLINT(readability-identifier-naming) +{ + const auto& args = s.args(); + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Shadow_set_shadowDistance : Invalid Native Object"); + + CC_UNUSED bool ok = true; + ok &= sevalue_to_native(args[0], &cobj->shadowDistance, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_scene_Shadow_set_shadowDistance : Error processing new value"); + return true; +} +SE_BIND_PROP_SET(js_scene_Shadow_set_shadowDistance) + static bool js_scene_Shadow_get_distance(se::State& s) // NOLINT(readability-identifier-naming) { auto* cobj = SE_THIS_OBJECT(s); @@ -2780,14 +3017,22 @@ bool sevalue_to_native(const se::Value &from, cc::scene::Shadow * to, se::Object if(!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->shadowMapDirty), ctx); } - json->getProperty("autoAdapt", &field); + json->getProperty("fixedArea", &field); if(!field.isNullOrUndefined()) { - ok &= sevalue_to_native(field, &(to->autoAdapt), ctx); + ok &= sevalue_to_native(field, &(to->fixedArea), ctx); } json->getProperty("shadowType", &field); if(!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->shadowType), ctx); } + json->getProperty("invisibleOcclusionRange", &field); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->invisibleOcclusionRange), ctx); + } + json->getProperty("shadowDistance", &field); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->shadowDistance), ctx); + } json->getProperty("distance", &field); if(!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->distance), ctx); @@ -2892,52 +3137,58 @@ static bool js_scene_Shadow_constructor(se::State& s) // NOLINT(readability-iden ok &= sevalue_to_native(args[2], &(cobj->shadowMapDirty), nullptr); } if (argc > 3 && !args[3].isUndefined()) { - ok &= sevalue_to_native(args[3], &(cobj->autoAdapt), nullptr); + ok &= sevalue_to_native(args[3], &(cobj->fixedArea), nullptr); } if (argc > 4 && !args[4].isUndefined()) { ok &= sevalue_to_native(args[4], &(cobj->shadowType), nullptr); } if (argc > 5 && !args[5].isUndefined()) { - ok &= sevalue_to_native(args[5], &(cobj->distance), nullptr); + ok &= sevalue_to_native(args[5], &(cobj->invisibleOcclusionRange), nullptr); } if (argc > 6 && !args[6].isUndefined()) { - ok &= sevalue_to_native(args[6], &(cobj->instancePass), nullptr); + ok &= sevalue_to_native(args[6], &(cobj->shadowDistance), nullptr); } if (argc > 7 && !args[7].isUndefined()) { - ok &= sevalue_to_native(args[7], &(cobj->planarPass), nullptr); + ok &= sevalue_to_native(args[7], &(cobj->distance), nullptr); } if (argc > 8 && !args[8].isUndefined()) { - ok &= sevalue_to_native(args[8], &(cobj->nearValue), nullptr); + ok &= sevalue_to_native(args[8], &(cobj->instancePass), nullptr); } if (argc > 9 && !args[9].isUndefined()) { - ok &= sevalue_to_native(args[9], &(cobj->farValue), nullptr); + ok &= sevalue_to_native(args[9], &(cobj->planarPass), nullptr); } if (argc > 10 && !args[10].isUndefined()) { - ok &= sevalue_to_native(args[10], &(cobj->pcfType), nullptr); + ok &= sevalue_to_native(args[10], &(cobj->nearValue), nullptr); } if (argc > 11 && !args[11].isUndefined()) { - ok &= sevalue_to_native(args[11], &(cobj->bias), nullptr); + ok &= sevalue_to_native(args[11], &(cobj->farValue), nullptr); } if (argc > 12 && !args[12].isUndefined()) { - ok &= sevalue_to_native(args[12], &(cobj->normalBias), nullptr); + ok &= sevalue_to_native(args[12], &(cobj->pcfType), nullptr); } if (argc > 13 && !args[13].isUndefined()) { - ok &= sevalue_to_native(args[13], &(cobj->saturation), nullptr); + ok &= sevalue_to_native(args[13], &(cobj->bias), nullptr); } if (argc > 14 && !args[14].isUndefined()) { - ok &= sevalue_to_native(args[14], &(cobj->orthoSize), nullptr); + ok &= sevalue_to_native(args[14], &(cobj->normalBias), nullptr); } if (argc > 15 && !args[15].isUndefined()) { - ok &= sevalue_to_native(args[15], &(cobj->color), nullptr); + ok &= sevalue_to_native(args[15], &(cobj->saturation), nullptr); } if (argc > 16 && !args[16].isUndefined()) { - ok &= sevalue_to_native(args[16], &(cobj->size), nullptr); + ok &= sevalue_to_native(args[16], &(cobj->orthoSize), nullptr); } if (argc > 17 && !args[17].isUndefined()) { - ok &= sevalue_to_native(args[17], &(cobj->normal), nullptr); + ok &= sevalue_to_native(args[17], &(cobj->color), nullptr); } if (argc > 18 && !args[18].isUndefined()) { - ok &= sevalue_to_native(args[18], &(cobj->matLight), nullptr); + ok &= sevalue_to_native(args[18], &(cobj->size), nullptr); + } + if (argc > 19 && !args[19].isUndefined()) { + ok &= sevalue_to_native(args[19], &(cobj->normal), nullptr); + } + if (argc > 20 && !args[20].isUndefined()) { + ok &= sevalue_to_native(args[20], &(cobj->matLight), nullptr); } if(!ok) { @@ -2974,8 +3225,10 @@ bool js_register_scene_Shadow(se::Object* obj) // NOLINT(readability-identifier- cls->defineProperty("enabled", _SE(js_scene_Shadow_get_enabled), _SE(js_scene_Shadow_set_enabled)); cls->defineProperty("dirty", _SE(js_scene_Shadow_get_dirty), _SE(js_scene_Shadow_set_dirty)); cls->defineProperty("shadowMapDirty", _SE(js_scene_Shadow_get_shadowMapDirty), _SE(js_scene_Shadow_set_shadowMapDirty)); - cls->defineProperty("autoAdapt", _SE(js_scene_Shadow_get_autoAdapt), _SE(js_scene_Shadow_set_autoAdapt)); + cls->defineProperty("fixedArea", _SE(js_scene_Shadow_get_fixedArea), _SE(js_scene_Shadow_set_fixedArea)); cls->defineProperty("shadowType", _SE(js_scene_Shadow_get_shadowType), _SE(js_scene_Shadow_set_shadowType)); + cls->defineProperty("invisibleOcclusionRange", _SE(js_scene_Shadow_get_invisibleOcclusionRange), _SE(js_scene_Shadow_set_invisibleOcclusionRange)); + cls->defineProperty("shadowDistance", _SE(js_scene_Shadow_get_shadowDistance), _SE(js_scene_Shadow_set_shadowDistance)); cls->defineProperty("distance", _SE(js_scene_Shadow_get_distance), _SE(js_scene_Shadow_set_distance)); cls->defineProperty("instancePass", _SE(js_scene_Shadow_get_instancePass), _SE(js_scene_Shadow_set_instancePass)); cls->defineProperty("planarPass", _SE(js_scene_Shadow_get_planarPass), _SE(js_scene_Shadow_set_planarPass)); @@ -6742,6 +6995,60 @@ static bool js_scene_Camera_set_clearDepth(se::State& s) // NOLINT(readability-i } SE_BIND_PROP_SET(js_scene_Camera_set_clearDepth) +static bool js_scene_Camera_get_fov(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Camera_get_fov : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= nativevalue_to_se(cobj->fov, jsret, s.thisObject() /*ctx*/); + s.rval() = jsret; + SE_HOLD_RETURN_VALUE(cobj->fov, s.thisObject(), s.rval()); + return true; +} +SE_BIND_PROP_GET(js_scene_Camera_get_fov) + +static bool js_scene_Camera_set_fov(se::State& s) // NOLINT(readability-identifier-naming) +{ + const auto& args = s.args(); + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Camera_set_fov : Invalid Native Object"); + + CC_UNUSED bool ok = true; + ok &= sevalue_to_native(args[0], &cobj->fov, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_scene_Camera_set_fov : Error processing new value"); + return true; +} +SE_BIND_PROP_SET(js_scene_Camera_set_fov) + +static bool js_scene_Camera_get_aspect(se::State& s) // NOLINT(readability-identifier-naming) +{ + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Camera_get_aspect : Invalid Native Object"); + + CC_UNUSED bool ok = true; + se::Value jsret; + ok &= nativevalue_to_se(cobj->aspect, jsret, s.thisObject() /*ctx*/); + s.rval() = jsret; + SE_HOLD_RETURN_VALUE(cobj->aspect, s.thisObject(), s.rval()); + return true; +} +SE_BIND_PROP_GET(js_scene_Camera_get_aspect) + +static bool js_scene_Camera_set_aspect(se::State& s) // NOLINT(readability-identifier-naming) +{ + const auto& args = s.args(); + auto* cobj = SE_THIS_OBJECT(s); + SE_PRECONDITION2(cobj, false, "js_scene_Camera_set_aspect : Invalid Native Object"); + + CC_UNUSED bool ok = true; + ok &= sevalue_to_native(args[0], &cobj->aspect, s.thisObject()); + SE_PRECONDITION2(ok, false, "js_scene_Camera_set_aspect : Error processing new value"); + return true; +} +SE_BIND_PROP_SET(js_scene_Camera_set_aspect) + static bool js_scene_Camera_get_viewPort(se::State& s) // NOLINT(readability-identifier-naming) { auto* cobj = SE_THIS_OBJECT(s); @@ -7288,6 +7595,14 @@ bool sevalue_to_native(const se::Value &from, cc::scene::Camera * to, se::Object if(!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->clearDepth), ctx); } + json->getProperty("fov", &field); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->fov), ctx); + } + json->getProperty("aspect", &field); + if(!field.isNullOrUndefined()) { + ok &= sevalue_to_native(field, &(to->aspect), ctx); + } json->getProperty("viewPort", &field); if(!field.isNullOrUndefined()) { ok &= sevalue_to_native(field, &(to->viewPort), ctx); @@ -7418,61 +7733,67 @@ static bool js_scene_Camera_constructor(se::State& s) // NOLINT(readability-iden ok &= sevalue_to_native(args[4], &(cobj->clearDepth), nullptr); } if (argc > 5 && !args[5].isUndefined()) { - ok &= sevalue_to_native(args[5], &(cobj->viewPort), nullptr); + ok &= sevalue_to_native(args[5], &(cobj->fov), nullptr); } if (argc > 6 && !args[6].isUndefined()) { - ok &= sevalue_to_native(args[6], &(cobj->clearStencil), nullptr); + ok &= sevalue_to_native(args[6], &(cobj->aspect), nullptr); } if (argc > 7 && !args[7].isUndefined()) { - ok &= sevalue_to_native(args[7], &(cobj->visibility), nullptr); + ok &= sevalue_to_native(args[7], &(cobj->viewPort), nullptr); } if (argc > 8 && !args[8].isUndefined()) { - ok &= sevalue_to_native(args[8], &(cobj->node), nullptr); + ok &= sevalue_to_native(args[8], &(cobj->clearStencil), nullptr); } if (argc > 9 && !args[9].isUndefined()) { - ok &= sevalue_to_native(args[9], &(cobj->scene), nullptr); + ok &= sevalue_to_native(args[9], &(cobj->visibility), nullptr); } if (argc > 10 && !args[10].isUndefined()) { - ok &= sevalue_to_native(args[10], &(cobj->window), nullptr); + ok &= sevalue_to_native(args[10], &(cobj->node), nullptr); } if (argc > 11 && !args[11].isUndefined()) { - ok &= sevalue_to_native(args[11], &(cobj->frustum), nullptr); + ok &= sevalue_to_native(args[11], &(cobj->scene), nullptr); } if (argc > 12 && !args[12].isUndefined()) { - ok &= sevalue_to_native(args[12], &(cobj->forward), nullptr); + ok &= sevalue_to_native(args[12], &(cobj->window), nullptr); } if (argc > 13 && !args[13].isUndefined()) { - ok &= sevalue_to_native(args[13], &(cobj->position), nullptr); + ok &= sevalue_to_native(args[13], &(cobj->frustum), nullptr); } if (argc > 14 && !args[14].isUndefined()) { - ok &= sevalue_to_native(args[14], &(cobj->clearColor), nullptr); + ok &= sevalue_to_native(args[14], &(cobj->forward), nullptr); } if (argc > 15 && !args[15].isUndefined()) { - ok &= sevalue_to_native(args[15], &(cobj->matView), nullptr); + ok &= sevalue_to_native(args[15], &(cobj->position), nullptr); } if (argc > 16 && !args[16].isUndefined()) { - ok &= sevalue_to_native(args[16], &(cobj->matViewProj), nullptr); + ok &= sevalue_to_native(args[16], &(cobj->clearColor), nullptr); } if (argc > 17 && !args[17].isUndefined()) { - ok &= sevalue_to_native(args[17], &(cobj->matViewProjInv), nullptr); + ok &= sevalue_to_native(args[17], &(cobj->matView), nullptr); } if (argc > 18 && !args[18].isUndefined()) { - ok &= sevalue_to_native(args[18], &(cobj->matProj), nullptr); + ok &= sevalue_to_native(args[18], &(cobj->matViewProj), nullptr); } if (argc > 19 && !args[19].isUndefined()) { - ok &= sevalue_to_native(args[19], &(cobj->matProjInv), nullptr); + ok &= sevalue_to_native(args[19], &(cobj->matViewProjInv), nullptr); } if (argc > 20 && !args[20].isUndefined()) { - ok &= sevalue_to_native(args[20], &(cobj->matViewProjOffscreen), nullptr); + ok &= sevalue_to_native(args[20], &(cobj->matProj), nullptr); } if (argc > 21 && !args[21].isUndefined()) { - ok &= sevalue_to_native(args[21], &(cobj->matViewProjInvOffscreen), nullptr); + ok &= sevalue_to_native(args[21], &(cobj->matProjInv), nullptr); } if (argc > 22 && !args[22].isUndefined()) { - ok &= sevalue_to_native(args[22], &(cobj->matProjOffscreen), nullptr); + ok &= sevalue_to_native(args[22], &(cobj->matViewProjOffscreen), nullptr); } if (argc > 23 && !args[23].isUndefined()) { - ok &= sevalue_to_native(args[23], &(cobj->matProjInvOffscreen), nullptr); + ok &= sevalue_to_native(args[23], &(cobj->matViewProjInvOffscreen), nullptr); + } + if (argc > 24 && !args[24].isUndefined()) { + ok &= sevalue_to_native(args[24], &(cobj->matProjOffscreen), nullptr); + } + if (argc > 25 && !args[25].isUndefined()) { + ok &= sevalue_to_native(args[25], &(cobj->matProjInvOffscreen), nullptr); } if(!ok) { @@ -7511,6 +7832,8 @@ bool js_register_scene_Camera(se::Object* obj) // NOLINT(readability-identifier- cls->defineProperty("clearFlag", _SE(js_scene_Camera_get_clearFlag), _SE(js_scene_Camera_set_clearFlag)); cls->defineProperty("exposure", _SE(js_scene_Camera_get_exposure), _SE(js_scene_Camera_set_exposure)); cls->defineProperty("clearDepth", _SE(js_scene_Camera_get_clearDepth), _SE(js_scene_Camera_set_clearDepth)); + cls->defineProperty("fov", _SE(js_scene_Camera_get_fov), _SE(js_scene_Camera_set_fov)); + cls->defineProperty("aspect", _SE(js_scene_Camera_get_aspect), _SE(js_scene_Camera_set_aspect)); cls->defineProperty("viewPort", _SE(js_scene_Camera_get_viewPort), _SE(js_scene_Camera_set_viewPort)); cls->defineProperty("clearStencil", _SE(js_scene_Camera_get_clearStencil), _SE(js_scene_Camera_set_clearStencil)); cls->defineProperty("visibility", _SE(js_scene_Camera_get_visibility), _SE(js_scene_Camera_set_visibility)); diff --git a/native/cocos/bindings/auto/jsb_scene_auto.h b/native/cocos/bindings/auto/jsb_scene_auto.h index d53a76fa54..146eeffbf2 100644 --- a/native/cocos/bindings/auto/jsb_scene_auto.h +++ b/native/cocos/bindings/auto/jsb_scene_auto.h @@ -85,6 +85,9 @@ bool register_all_scene(se::Object* obj); template<> bool sevalue_to_native(const se::Value &, cc::scene::Plane *, se::Object *ctx); JSB_REGISTER_OBJECT_TYPE(cc::scene::Plane); +SE_DECLARE_FUNC(js_scene_Plane_clone); +SE_DECLARE_FUNC(js_scene_Plane_define); +SE_DECLARE_FUNC(js_scene_Plane_distance); extern se::Object* __jsb_cc_scene_Frustum_proto; extern se::Class* __jsb_cc_scene_Frustum_class; @@ -95,6 +98,10 @@ bool register_all_scene(se::Object* obj); template<> bool sevalue_to_native(const se::Value &, cc::scene::Frustum *, se::Object *ctx); JSB_REGISTER_OBJECT_TYPE(cc::scene::Frustum); +SE_DECLARE_FUNC(js_scene_Frustum_clone); +SE_DECLARE_FUNC(js_scene_Frustum_createOrtho); +SE_DECLARE_FUNC(js_scene_Frustum_split); +SE_DECLARE_FUNC(js_scene_Frustum_transform); extern se::Object* __jsb_cc_scene_AABB_proto; extern se::Class* __jsb_cc_scene_AABB_class; diff --git a/native/cocos/bindings/jswrapper/v8/Object.cpp b/native/cocos/bindings/jswrapper/v8/Object.cpp index 17cd2bb3e7..072981c307 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.cpp +++ b/native/cocos/bindings/jswrapper/v8/Object.cpp @@ -40,8 +40,10 @@ namespace se { std::unique_ptr> __objectMap; // Currently, the value `void*` is always nullptr namespace { -v8::Isolate *__isolate = nullptr; //NOLINT -uint32_t nativeObjectId = 0; +v8::Isolate *__isolate = nullptr; //NOLINT + #if CC_DEBUG_JS_OBJECT_ID && CC_DEBUG +uint32_t nativeObjectId = 0; + #endif } // namespace Object::Object() @@ -279,7 +281,7 @@ bool Object::init(Class *cls, v8::Local obj) { __objectMap->emplace(this, nullptr); } - #if CC_DEBUG + #if CC_DEBUG && CC_DEBUG_JS_OBJECT_ID this->_objectId = ++nativeObjectId; this->setProperty("__object_id__", se::Value(this->_objectId)); this->setProperty("__native_class_name__", se::Value(cls ? cls->getName() : "[noname]")); diff --git a/native/cocos/bindings/jswrapper/v8/Object.h b/native/cocos/bindings/jswrapper/v8/Object.h index 6aab799536..ec2a3b5b1e 100644 --- a/native/cocos/bindings/jswrapper/v8/Object.h +++ b/native/cocos/bindings/jswrapper/v8/Object.h @@ -37,6 +37,12 @@ #include + // DEBUG ONLY: + // Set `__object_id__` && `__native_class_name__` for js object + #ifndef CC_DEBUG_JS_OBJECT_ID + #define CC_DEBUG_JS_OBJECT_ID 0 + #endif + namespace se { class Class; @@ -378,16 +384,16 @@ public: std::string toString() const; // Private API used in wrapper - static Object * _createJSObject(Class *cls, v8::Local obj); - v8::Local _getJSObject() const; - ObjectWrap & _getWrap(); - Class * _getClass() const; + static Object * _createJSObject(Class *cls, v8::Local obj); // NOLINT(readability-identifier-naming) + v8::Local _getJSObject() const; // NOLINT(readability-identifier-naming) + ObjectWrap & _getWrap(); // NOLINT(readability-identifier-naming) + Class * _getClass() const; // NOLINT(readability-identifier-naming) - void _setFinalizeCallback(V8FinalizeFunc finalizeCb); - bool _isNativeFunction() const; + void _setFinalizeCallback(V8FinalizeFunc finalizeCb); // NOLINT(readability-identifier-naming) + bool _isNativeFunction() const; // NOLINT(readability-identifier-naming) // - #if CC_DEBUG + #if CC_DEBUG && CC_DEBUG_JS_OBJECT_ID uint32_t getObjectId() const { return _objectId; } #endif @@ -410,12 +416,12 @@ private: V8FinalizeFunc _finalizeCb; internal::PrivateData *_internalData; - #if CC_DEBUG + #if CC_DEBUG && CC_DEBUG_JS_OBJECT_ID uint32_t _objectId = 0; #endif friend class ScriptEngine; }; - +// NOLINTNEXTLINE extern std::unique_ptr> __objectMap; // Currently, the value `void*` is always nullptr } // namespace se diff --git a/native/cocos/bindings/manual/JavaScriptJavaBridge.cpp b/native/cocos/bindings/manual/JavaScriptJavaBridge.cpp index e6315849f5..e0595135eb 100644 --- a/native/cocos/bindings/manual/JavaScriptJavaBridge.cpp +++ b/native/cocos/bindings/manual/JavaScriptJavaBridge.cpp @@ -286,9 +286,13 @@ bool JavaScriptJavaBridge::CallInfo::executeWithArgs(jvalue *args) { break; case JavaScriptJavaBridge::ValueType::STRING: { - _mRetjstring = static_cast(_mEnv->CallStaticObjectMethodA(_mClassID, _mMethodID, args)); - std::string strValue = cc::StringUtils::getStringUTFCharsJNI(_mEnv, _mRetjstring); - _mRet.stringValue = new std::string(strValue); + _mRetjstring = static_cast(_mEnv->CallStaticObjectMethodA(_mClassID, _mMethodID, args)); + if (_mRetjstring) { + std::string strValue = cc::StringUtils::getStringUTFCharsJNI(_mEnv, _mRetjstring); + _mRet.stringValue = new std::string(strValue); + } else { + _mRet.stringValue = nullptr; + } break; } diff --git a/native/cocos/math/Mat4.cpp b/native/cocos/math/Mat4.cpp index 121d164d81..7c7636d5e9 100644 --- a/native/cocos/math/Mat4.cpp +++ b/native/cocos/math/Mat4.cpp @@ -99,7 +99,7 @@ void Mat4::createPerspective(float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane, Mat4 *dst) { GP_ASSERT(dst); GP_ASSERT(zFarPlane != zNearPlane); - GP_ASSERT(fieldOfView != 0.0f); + GP_ASSERT(fieldOfView != 0.0F); const float minClipZ = -1.0F; const float projectionSignY = 1.0F; @@ -722,6 +722,11 @@ void Mat4::getBackVector(Vec3 *dst) const { dst->z = m[10]; } +Mat4 Mat4::clone() const { + Mat4 mat(*this); + return mat; +} + Mat4 Mat4::getInversed() const { Mat4 mat(*this); mat.inverse(); diff --git a/native/cocos/math/Mat4.h b/native/cocos/math/Mat4.h index 151c35a3a4..e9a2147691 100644 --- a/native/cocos/math/Mat4.h +++ b/native/cocos/math/Mat4.h @@ -500,6 +500,13 @@ public: */ bool inverse(); + /** + * Clone this matrix. + * + * @return a new clone matrix. + */ + Mat4 clone() const; + /** * Get the inversed matrix. */ diff --git a/native/cocos/math/Vec3.cpp b/native/cocos/math/Vec3.cpp index d8632fd70e..cf7cb76dc6 100644 --- a/native/cocos/math/Vec3.cpp +++ b/native/cocos/math/Vec3.cpp @@ -28,12 +28,6 @@ NS_CC_MATH_BEGIN -Vec3::Vec3() -: x(0.0f), - y(0.0f), - z(0.0f) { -} - Vec3::Vec3(float xx, float yy, float zz) : x(xx), y(yy), @@ -56,22 +50,19 @@ Vec3 Vec3::fromColor(unsigned int color) { float components[3]; int componentIndex = 0; for (int i = 2; i >= 0; --i) { - int component = (color >> i * 8) & 0x0000ff; + const unsigned int component = (color >> i * 8) & 0x0000ff; - components[componentIndex++] = static_cast(component) / 255.0f; + components[componentIndex++] = static_cast(component) / 255.0F; } Vec3 value(components); return value; } -Vec3::~Vec3() { -} - float Vec3::angle(const Vec3 &v1, const Vec3 &v2) { - float dx = v1.y * v2.z - v1.z * v2.y; - float dy = v1.z * v2.x - v1.x * v2.z; - float dz = v1.x * v2.y - v1.y * v2.x; + const float dx = v1.y * v2.z - v1.z * v2.y; + const float dy = v1.z * v2.x - v1.x * v2.z; + const float dz = v1.x * v2.y - v1.y * v2.x; return std::atan2(std::sqrt(dx * dx + dy * dy + dz * dz) + MATH_FLOAT_SMALL, dot(v1, v2)); } @@ -88,22 +79,28 @@ void Vec3::clamp(const Vec3 &min, const Vec3 &max) { GP_ASSERT(!(min.x > max.x || min.y > max.y || min.z > max.z)); // Clamp the x value. - if (x < min.x) + if (x < min.x) { x = min.x; - if (x > max.x) + } + if (x > max.x) { x = max.x; - + } + // Clamp the y value. - if (y < min.y) + if (y < min.y) { y = min.y; - if (y > max.y) + } + if (y > max.y) { y = max.y; + } // Clamp the z value. - if (z < min.z) + if (z < min.z) { z = min.z; - if (z > max.z) + } + if (z > max.z) { z = max.z; + } } void Vec3::clamp(const Vec3 &v, const Vec3 &min, const Vec3 &max, Vec3 *dst) { @@ -112,24 +109,30 @@ void Vec3::clamp(const Vec3 &v, const Vec3 &min, const Vec3 &max, Vec3 *dst) { // Clamp the x value. dst->x = v.x; - if (dst->x < min.x) + if (dst->x < min.x) { dst->x = min.x; - if (dst->x > max.x) + } + if (dst->x > max.x) { dst->x = max.x; + } // Clamp the y value. dst->y = v.y; - if (dst->y < min.y) + if (dst->y < min.y) { dst->y = min.y; - if (dst->y > max.y) + } + if (dst->y > max.y) { dst->y = max.y; + } // Clamp the z value. dst->z = v.z; - if (dst->z < min.z) + if (dst->z < min.z) { dst->z = min.z; - if (dst->z > max.z) + } + if (dst->z > max.z) { dst->z = max.z; + } } void Vec3::cross(const Vec3 &v) { @@ -145,6 +148,13 @@ void Vec3::cross(const Vec3 &v1, const Vec3 &v2, Vec3 *dst) { MathUtil::crossVec3(&v1.x, &v2.x, &dst->x); } +void Vec3::crossProduct(const Vec3 &v1, const Vec3 &v2, Vec3 *dst) { + dst->set( + v1.y * v2.z - v1.z * v2.y, + v1.z * v2.x - v1.x * v2.z, + v1.x * v2.y - v1.y * v2.x); +} + void Vec3::multiply(const Vec3 &v) { x *= v.x; y *= v.y; @@ -158,16 +168,20 @@ void Vec3::multiply(const Vec3 &v1, const Vec3 &v2, Vec3 *dst) { } void Vec3::transformMat3(const Vec3 &v, const Mat3 &m) { - float ix = v.x, iy = v.y, iz = v.z; + const float ix = v.x; + const float iy = v.y; + const float iz = v.z; x = ix * m.m[0] + iy * m.m[3] + iz * m.m[6]; y = ix * m.m[1] + iy * m.m[4] + iz * m.m[7]; z = ix * m.m[2] + iy * m.m[5] + iz * m.m[8]; } void Vec3::transformMat4(const Vec3 &v, const Mat4 &m) { - float ix = v.x, iy = v.y, iz = v.z; + const float ix = v.x; + const float iy = v.y; + const float iz = v.z; float rhw = m.m[3] * ix + m.m[7] * iy + m.m[11] * iz + m.m[15]; - rhw = rhw ? 1 / rhw : 1; + rhw = static_cast(rhw) ? 1.0F / rhw : 1.0F; x = (m.m[0] * ix + m.m[4] * iy + m.m[8] * iz + m.m[12]) * rhw; y = (m.m[1] * ix + m.m[5] * iy + m.m[9] * iz + m.m[13]) * rhw; @@ -175,13 +189,16 @@ void Vec3::transformMat4(const Vec3 &v, const Mat4 &m) { } void Vec3::transformQuat(const Quaternion &q) { - float qx = q.x, qy = q.y, qz = q.z, qw = q.w; + const float qx = q.x; + const float qy = q.y; + const float qz = q.z; + const float qw = q.w; // calculate quat * vec - float ix = qw * x + qy * z - qz * y; - float iy = qw * y + qz * x - qx * z; - float iz = qw * z + qx * y - qy * x; - float iw = -qx * x - qy * y - qz * z; + const float ix = qw * x + qy * z - qz * y; + const float iy = qw * y + qz * x - qx * z; + const float iz = qw * z + qx * y - qy * x; + const float iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat x = ix * qw + iw * -qx + iy * -qz - iz * -qy; @@ -190,17 +207,17 @@ void Vec3::transformQuat(const Quaternion &q) { } float Vec3::distance(const Vec3 &v) const { - float dx = v.x - x; - float dy = v.y - y; - float dz = v.z - z; + const float dx = v.x - x; + const float dy = v.y - y; + const float dz = v.z - z; return std::sqrt(dx * dx + dy * dy + dz * dz); } float Vec3::distanceSquared(const Vec3 &v) const { - float dx = v.x - x; - float dy = v.y - y; - float dz = v.z - z; + const float dx = v.x - x; + const float dy = v.y - y; + const float dz = v.z - z; return (dx * dx + dy * dy + dz * dz); } @@ -216,15 +233,17 @@ float Vec3::dot(const Vec3 &v1, const Vec3 &v2) { void Vec3::normalize() { float n = x * x + y * y + z * z; // Already normalized. - if (n == 1.0f) + if (n == 1.0F) { return; + } n = std::sqrt(n); // Too close to zero. - if (n < MATH_TOLERANCE) + if (n < MATH_TOLERANCE) { return; + } - n = 1.0f / n; + n = 1.0F / n; x *= n; y *= n; z *= n; @@ -263,15 +282,16 @@ void Vec3::min(const Vec3 &v1, const Vec3 &v2, Vec3 *dst) { } void Vec3::smooth(const Vec3 &target, float elapsedTime, float responseTime) { - if (elapsedTime > 0) { + if (elapsedTime > 0.0F) { *this += (target - *this) * (elapsedTime / (elapsedTime + responseTime)); } } -const Vec3 Vec3::ZERO(0.0f, 0.0f, 0.0f); -const Vec3 Vec3::ONE(1.0f, 1.0f, 1.0f); -const Vec3 Vec3::UNIT_X(1.0f, 0.0f, 0.0f); -const Vec3 Vec3::UNIT_Y(0.0f, 1.0f, 0.0f); -const Vec3 Vec3::UNIT_Z(0.0f, 0.0f, 1.0f); +const Vec3 Vec3::ZERO(0.0F, 0.0F, 0.0F); +const Vec3 Vec3::ONE(1.0F, 1.0F, 1.0F); +const Vec3 Vec3::UNIT_X(1.0F, 0.0F, 0.0F); +const Vec3 Vec3::UNIT_Y(0.0F, 1.0F, 0.0F); +const Vec3 Vec3::UNIT_Z(0.0F, 0.0F, 1.0F); +const Vec3 Vec3::FORWARD(0.0F, 0.0F, -1.0F); NS_CC_MATH_END diff --git a/native/cocos/math/Vec3.h b/native/cocos/math/Vec3.h index c5efa1dcc4..907a8628ca 100644 --- a/native/cocos/math/Vec3.h +++ b/native/cocos/math/Vec3.h @@ -23,7 +23,6 @@ #ifndef MATH_VEC3_H #define MATH_VEC3_H -#include #include "math/MathBase.h" /** @@ -51,22 +50,22 @@ public: /** * The x-coordinate. */ - float x; + float x{}; /** * The y-coordinate. */ - float y; + float y{}; /** * The z-coordinate. */ - float z; + float z{}; /** * Constructs a new vector initialized to all zeros. */ - Vec3(); + Vec3() = default; /** * Constructs a new vector initialized to the specified values. @@ -82,7 +81,7 @@ public: * * @param array An array containing the elements of the vector in the order x, y, z. */ - Vec3(const float *array); + explicit Vec3(const float *array); /** * Constructs a vector that describes the direction between the specified points. @@ -112,7 +111,7 @@ public: /** * Destructor. */ - ~Vec3(); + ~Vec3() = default; /** * Indicates whether this vector contains all zeros. @@ -188,6 +187,15 @@ public: */ void cross(const Vec3 &v); + /** + * Calculate cross product. + * + * @param v1 is a vector. + * @param v2 is a vector. + * @param dst is a vector used to calculate the cross product of v1 and v2. + */ + static void crossProduct(const Vec3 &v1, const Vec3 &v2, Vec3 *dst); + /** * Computes the cross product of the specified vectors and stores the result in dst. * @@ -525,9 +533,11 @@ public: * @return bool */ inline bool operator<(const Vec3 &rhs) const { - if (x < rhs.x && y < rhs.y && z < rhs.z) - return true; - return false; + bool temp = false; + if (x < rhs.x && y < rhs.y && z < rhs.z) { + temp = true; + } + return temp; } /** @@ -538,9 +548,11 @@ public: * @return bool */ inline bool operator>(const Vec3 &rhs) const { - if (x > rhs.x && y > rhs.y && z > rhs.z) - return true; - return false; + bool temp = false; + if (x > rhs.x && y > rhs.y && z > rhs.z) { + temp = true; + } + return temp; } /** @@ -580,6 +592,8 @@ public: static const Vec3 UNIT_Y; /** equals to Vec3(0,0,1) */ static const Vec3 UNIT_Z; + /** equals to Vec3(0,0,-1) */ + static const Vec3 FORWARD; }; /** diff --git a/native/cocos/math/Vec3.inl b/native/cocos/math/Vec3.inl index cf348f86f1..b34455d2ee 100644 --- a/native/cocos/math/Vec3.inl +++ b/native/cocos/math/Vec3.inl @@ -18,6 +18,8 @@ This file was modified to fit the cocos2d-x project */ +#pragma once +#include #include "math/Vec3.h" #include "math/Mat4.h" diff --git a/native/cocos/network/WebSocket-libwebsockets.cpp b/native/cocos/network/WebSocket-libwebsockets.cpp index 1b74566661..0cc073054e 100644 --- a/native/cocos/network/WebSocket-libwebsockets.cpp +++ b/native/cocos/network/WebSocket-libwebsockets.cpp @@ -67,7 +67,12 @@ #define WS_RX_BUFFER_SIZE (65536) #define WS_RESERVE_RECEIVE_BUFFER_SIZE (4096) -#define WS_ENABLE_LIBUV 1 + +#if CC_PLATFORM == CC_PLATFORM_ANDROID + #define WS_ENABLE_LIBUV 1 +#else + #define WS_ENABLE_LIBUV 0 +#endif #ifdef LOG_TAG #undef LOG_TAG @@ -428,6 +433,15 @@ bool WsThreadHelper::createWebSocketThread() { void WsThreadHelper::quitWebSocketThread() { _needQuit = true; +#if WS_ENABLE_LIBUV + // stop libuv loop + if (wsContext && wsPolling) { + auto *loop = lws_uv_getloop(wsContext, 0); + if (loop) { + uv_stop(loop); + } + } +#endif } void WsThreadHelper::onSubThreadLoop() { @@ -455,7 +469,7 @@ void WsThreadHelper::onSubThreadLoop() { // Windows: Cause delay 40ms for event WS_MSG_TO_SUBTHREAD_CREATE_CONNECTION // Android: Let libuv lws to decide when to stop wsPolling = true; - lws_service(wsContext, 40); + lws_service(wsContext, WS_ENABLE_LIBUV ? 40 : 4); wsPolling = false; } } diff --git a/native/cocos/physics/physx/PhysXRigidBody.cpp b/native/cocos/physics/physx/PhysXRigidBody.cpp index e520ee0066..dcb728e40a 100644 --- a/native/cocos/physics/physx/PhysXRigidBody.cpp +++ b/native/cocos/physics/physx/PhysXRigidBody.cpp @@ -63,7 +63,7 @@ void PhysXRigidBody::onDestroy() { } bool PhysXRigidBody::isAwake() { - if (getSharedBody().isStatic()) return false; + if (!getSharedBody().isInWorld() || getSharedBody().isStatic()) return false; return !getSharedBody().getImpl().rigidDynamic->isSleeping(); } @@ -72,7 +72,7 @@ bool PhysXRigidBody::isSleepy() { } bool PhysXRigidBody::isSleeping() { - if (getSharedBody().isStatic()) return true; + if (!getSharedBody().isInWorld() || getSharedBody().isStatic()) return true; return getSharedBody().getImpl().rigidDynamic->isSleeping(); } @@ -126,21 +126,23 @@ void PhysXRigidBody::setAllowSleep(bool v) { } void PhysXRigidBody::wakeUp() { - if (getSharedBody().isStatic()) return; + if (!getSharedBody().isInWorld() || getSharedBody().isStatic()) return; getSharedBody().getImpl().rigidDynamic->wakeUp(); } void PhysXRigidBody::sleep() { - if (getSharedBody().isStatic()) return; + if (!getSharedBody().isInWorld() || getSharedBody().isStatic()) return; getSharedBody().getImpl().rigidDynamic->putToSleep(); } void PhysXRigidBody::clearState() { + if (!getSharedBody().isInWorld()) return; clearForces(); clearVelocity(); } void PhysXRigidBody::clearForces() { + if (!getSharedBody().isInWorld()) return; getSharedBody().clearForces(); } @@ -182,7 +184,7 @@ void PhysXRigidBody::setAngularVelocity(float x, float y, float z) { } void PhysXRigidBody::applyForce(float x, float y, float z, float rx, float ry, float rz) { - if (getSharedBody().isStatic()) return; + if (!getSharedBody().isInWorld() || getSharedBody().isStaticOrKinematic()) return; const PxVec3 force{x, y, z}; if (force.isZero()) return; auto *body = getSharedBody().getImpl().rigidDynamic; @@ -192,7 +194,7 @@ void PhysXRigidBody::applyForce(float x, float y, float z, float rx, float ry, f } void PhysXRigidBody::applyLocalForce(float x, float y, float z, float rx, float ry, float rz) { - if (getSharedBody().isStatic()) return; + if (!getSharedBody().isInWorld() || getSharedBody().isStaticOrKinematic()) return; const PxVec3 force{x, y, z}; if (force.isZero()) return; auto * body = getSharedBody().getImpl().rigidDynamic; @@ -205,7 +207,7 @@ void PhysXRigidBody::applyLocalForce(float x, float y, float z, float rx, float } void PhysXRigidBody::applyImpulse(float x, float y, float z, float rx, float ry, float rz) { - if (getSharedBody().isStatic()) return; + if (!getSharedBody().isInWorld() || getSharedBody().isStaticOrKinematic()) return; const PxVec3 impulse{x, y, z}; if (impulse.isZero()) return; auto * body = getSharedBody().getImpl().rigidDynamic; @@ -215,7 +217,7 @@ void PhysXRigidBody::applyImpulse(float x, float y, float z, float rx, float ry, } void PhysXRigidBody::applyLocalImpulse(float x, float y, float z, float rx, float ry, float rz) { - if (getSharedBody().isStatic()) return; + if (!getSharedBody().isInWorld() || getSharedBody().isStaticOrKinematic()) return; const PxVec3 impulse{x, y, z}; if (impulse.isZero()) return; auto * body = getSharedBody().getImpl().rigidDynamic; @@ -228,14 +230,14 @@ void PhysXRigidBody::applyLocalImpulse(float x, float y, float z, float rx, floa } void PhysXRigidBody::applyTorque(float x, float y, float z) { - if (getSharedBody().isStatic()) return; + if (!getSharedBody().isInWorld() || getSharedBody().isStaticOrKinematic()) return; PxVec3 torque{x, y, z}; if (torque.isZero()) return; getSharedBody().getImpl().rigidDynamic->addTorque(torque, PxForceMode::eFORCE, true); } void PhysXRigidBody::applyLocalTorque(float x, float y, float z) { - if (getSharedBody().isStatic()) return; + if (!getSharedBody().isInWorld() || getSharedBody().isStaticOrKinematic()) return; PxVec3 torque{x, y, z}; if (torque.isZero()) return; auto * body = getSharedBody().getImpl().rigidDynamic; diff --git a/native/cocos/physics/physx/PhysXSharedBody.cpp b/native/cocos/physics/physx/PhysXSharedBody.cpp index ad5f0ddf77..2b636cb908 100644 --- a/native/cocos/physics/physx/PhysXSharedBody.cpp +++ b/native/cocos/physics/physx/PhysXSharedBody.cpp @@ -353,6 +353,7 @@ void PhysXSharedBody::setCollisionFilter(const PxFilterData &data) { } void PhysXSharedBody::clearForces() { + if (!isInWorld()) return; if (isStaticOrKinematic()) return; _mDynamicActor->clearForce(PxForceMode::eFORCE); _mDynamicActor->clearForce(PxForceMode::eIMPULSE); diff --git a/native/cocos/physics/physx/PhysXSharedBody.h b/native/cocos/physics/physx/PhysXSharedBody.h index 6249d2d341..e14ebc3e66 100644 --- a/native/cocos/physics/physx/PhysXSharedBody.h +++ b/native/cocos/physics/physx/PhysXSharedBody.h @@ -59,6 +59,7 @@ public: PhysXSharedBody(PhysXSharedBody &&other) = delete; void reference(bool v); void enabled(bool v); + inline bool isInWorld() { return _mIndex >= 0; } inline bool isStatic() { return static_cast(_mType) & static_cast(ERigidBodyType::STATIC); } inline bool isKinematic() { return static_cast(_mType) & static_cast(ERigidBodyType::KINEMATIC); } inline bool isStaticOrKinematic() { return static_cast(_mType) & static_cast(ERigidBodyType::STATIC) || static_cast(_mType) & static_cast(ERigidBodyType::KINEMATIC); } diff --git a/native/cocos/platform/android/Application-android.cpp b/native/cocos/platform/android/Application-android.cpp index 0226e78adc..8662aab259 100644 --- a/native/cocos/platform/android/Application-android.cpp +++ b/native/cocos/platform/android/Application-android.cpp @@ -27,6 +27,7 @@ #include #include +#include #include "audio/include/AudioEngine.h" #include "base/Scheduler.h" #include "cocos/bindings/event/EventDispatcher.h" @@ -58,13 +59,21 @@ namespace { bool setCanvasCallback(se::Object * /*global*/) { auto viewLogicalSize = cc::Application::getInstance()->getViewLogicalSize(); se::AutoHandleScope scope; - se::ScriptEngine * se = se::ScriptEngine::getInstance(); - char commandBuf[200] = {0}; - sprintf(commandBuf, "window.innerWidth = %d; window.innerHeight = %d; window.windowHandler = 0x%" PRIxPTR ";", - static_cast(viewLogicalSize.x), - static_cast(viewLogicalSize.y), - reinterpret_cast(cc::cocosApp.window)); - se->evalString(commandBuf); + se::ScriptEngine * se = se::ScriptEngine::getInstance(); + std::stringstream ss; + { + auto windowPtr = reinterpret_cast(cc::cocosApp.window); + ss << "window.innerWidth = " << static_cast(viewLogicalSize.x) << ";"; + ss << "window.innerHeight = " << static_cast(viewLogicalSize.y) << ";"; + ss << "window.windowHandler = "; + if constexpr (sizeof(windowPtr) == 8) { // use bigint + ss << static_cast(windowPtr) << "n;"; + } + if constexpr (sizeof(windowPtr) == 4) { + ss << static_cast(windowPtr) << ";"; + } + } + se->evalString(ss.str().c_str()); return true; } diff --git a/native/cocos/platform/android/java/src/com/cocos/lib/CocosActivity.java b/native/cocos/platform/android/java/src/com/cocos/lib/CocosActivity.java index 027b670147..4bf00f2683 100644 --- a/native/cocos/platform/android/java/src/com/cocos/lib/CocosActivity.java +++ b/native/cocos/platform/android/java/src/com/cocos/lib/CocosActivity.java @@ -165,6 +165,8 @@ public class CocosActivity extends Activity implements SurfaceHolder.Callback { mSurfaceHolder = null; } super.onDestroy(); + CocosHelper.unregisterBatteryLevelReceiver(this); + CanvasRenderingContext2DImpl.destroy(); } @Override diff --git a/native/cocos/platform/ios/Application-ios.mm b/native/cocos/platform/ios/Application-ios.mm index c572ec65f5..a5f4578ce6 100644 --- a/native/cocos/platform/ios/Application-ios.mm +++ b/native/cocos/platform/ios/Application-ios.mm @@ -90,30 +90,37 @@ namespace cc { namespace { - bool setCanvasCallback(se::Object *global) { - auto viewLogicalSize = cc::Application::getInstance()->getViewLogicalSize(); +bool setCanvasCallback(se::Object *global) { + auto viewLogicalSize = cc::Application::getInstance()->getViewLogicalSize(); + se::ScriptEngine *se = se::ScriptEngine::getInstance(); - int nativeWidth = static_cast(viewLogicalSize.x * Device::getDevicePixelRatio()); - int nativeHeight = static_cast(viewLogicalSize.y * Device::getDevicePixelRatio()); + int nativeWidth = static_cast(viewLogicalSize.x * Device::getDevicePixelRatio()); + int nativeHeight = static_cast(viewLogicalSize.y * Device::getDevicePixelRatio()); - // https://stackoverflow.com/questions/5795978/string-format-for-intptr-t-and-uintptr-t/41897226#41897226 - // format intptr_t - //set window.innerWidth/innerHeight in css pixel units - uintptr_t windowHandle = reinterpret_cast(UIApplication.sharedApplication.delegate.window.rootViewController.view); - std::stringstream commandBuf; - commandBuf << "window.innerWidth = " << viewLogicalSize.x - << "; window.innerHeight = " << viewLogicalSize.y - << "; window.nativeWidth= " << nativeWidth - << "; window.nativeHeight = " << nativeHeight - << "; window.windowHandler = " << windowHandle << ";"; - - se::ScriptEngine *se = se::ScriptEngine::getInstance(); - se->evalString(commandBuf.str().c_str()); - - return true; + // https://stackoverflow.com/questions/5795978/string-format-for-intptr-t-and-uintptr-t/41897226#41897226 + // format intptr_t + //set window.innerWidth/innerHeight in css pixel units + uintptr_t windowHandle = reinterpret_cast(UIApplication.sharedApplication.delegate.window.rootViewController.view); + std::stringstream ss; + { + ss << "window.innerWidth = " << viewLogicalSize.x + << "; window.innerHeight = " << viewLogicalSize.y + << "; window.nativeWidth= " << nativeWidth + << "; window.nativeHeight = " << nativeHeight + << "; window.windowHandler = "; + if constexpr (sizeof(windowHandle) == 8) { // use bigint + ss << static_cast(windowHandle) << "n;"; + } + if constexpr (sizeof(windowHandle) == 4) { + ss << static_cast(windowHandle) << ";"; + } } + se->evalString(ss.str().c_str()); - MyTimer *_timer; + return true; +} + +MyTimer *_timer; } Application * Application::instance = nullptr; diff --git a/native/cocos/platform/mac/Application-mac.mm b/native/cocos/platform/mac/Application-mac.mm index 8cbf02e0a7..c25de6f65b 100644 --- a/native/cocos/platform/mac/Application-mac.mm +++ b/native/cocos/platform/mac/Application-mac.mm @@ -101,11 +101,21 @@ bool setCanvasCallback(se::Object *global) { se::ScriptEngine *se = se::ScriptEngine::getInstance(); NSView * view = [[[[NSApplication sharedApplication] delegate] getWindow] contentView]; - std::stringstream commandBuf; - commandBuf << "window.innerWidth = " << viewLogicalSize.x + std::stringstream ss; + { + auto windowPtr = reinterpret_cast(view); + ss << "window.innerWidth = " << viewLogicalSize.x << "; window.innerHeight = " << viewLogicalSize.y - << "; window.windowHandler = " << reinterpret_cast(view) << ";"; - se->evalString(commandBuf.str().c_str()); + << "; window.windowHandler = "; + + if constexpr (sizeof(windowPtr) == 8) { // use bigint + ss << static_cast(windowPtr) << "n;"; + } + if constexpr (sizeof(windowPtr) == 4) { + ss << static_cast(windowPtr) << ";"; + } + } + se->evalString(ss.str().c_str()); return true; } diff --git a/native/cocos/platform/ohos/Application-ohos.cpp b/native/cocos/platform/ohos/Application-ohos.cpp index 04af914933..0a721748bb 100644 --- a/native/cocos/platform/ohos/Application-ohos.cpp +++ b/native/cocos/platform/ohos/Application-ohos.cpp @@ -48,13 +48,21 @@ namespace { bool setCanvasCallback(se::Object *global) { //NOLINT auto viewLogicalSize = cc::Application::getInstance()->getViewLogicalSize(); se::AutoHandleScope scope; - se::ScriptEngine * se = se::ScriptEngine::getInstance(); - char commandBuf[200] = {0}; - auto * view = cc::cocosApp.pendingWindow; + se::ScriptEngine * se = se::ScriptEngine::getInstance(); + auto * view = cc::cocosApp.pendingWindow; std::stringstream ss; - ss << "window.innerWidth = " << static_cast(viewLogicalSize.x) << ";" - << "window.innerHeight = " << static_cast(viewLogicalSize.y) << ";" - << "window.windowHandler = " << cc::cocosApp.pendingWindow << ";"; + { + auto windowPtr = reinterpret_cast(view); + ss << "window.innerWidth = " << static_cast(viewLogicalSize.x) << ";" + << "window.innerHeight = " << static_cast(viewLogicalSize.y) << ";" + << "window.windowHandler = "; + if constexpr (sizeof(windowPtr) == 8) { // use bigint + ss << static_cast(windowPtr) << "n;"; + } + if constexpr (sizeof(windowPtr) == 4) { + ss << static_cast(windowPtr) << ";"; + } + } se->evalString(ss.str().c_str()); return true; diff --git a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp index 84ba405442..0143f0766f 100644 --- a/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKCommandBuffer.cpp @@ -218,6 +218,8 @@ void CCVKCommandBuffer::bindDescriptorSet(uint set, DescriptorSet *descriptorSet if (dynamicOffsetCount) { _curDynamicOffsetsArray[set].assign(dynamicOffsets, dynamicOffsets + dynamicOffsetCount); if (set < _firstDirtyDescriptorSet) _firstDirtyDescriptorSet = set; + } else if (!_curDynamicOffsetsArray[set].empty()) { + _curDynamicOffsetsArray[set].assign(_curDynamicOffsetsArray[set].size(), 0); } } diff --git a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp index ee8911541f..ba126ba9b9 100644 --- a/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp +++ b/native/cocos/renderer/gfx-vulkan/VKDescriptorSet.cpp @@ -169,10 +169,10 @@ void CCVKDescriptorSet::doDestroy() { CCVKDescriptorInfo &descriptorInfo = instance.descriptorInfos[i]; if (binding.gpuBufferView) { - descriptorHub->disengage(binding.gpuBufferView, &descriptorInfo.buffer); + descriptorHub->disengage(_gpuDescriptorSet, binding.gpuBufferView, &descriptorInfo.buffer); } if (binding.gpuTextureView) { - descriptorHub->disengage(binding.gpuTextureView, &descriptorInfo.image); + descriptorHub->disengage(_gpuDescriptorSet, binding.gpuTextureView, &descriptorInfo.image); } if (binding.gpuSampler) { descriptorHub->disengage(binding.gpuSampler, &descriptorInfo.image); @@ -209,7 +209,7 @@ void CCVKDescriptorSet::update() { CCVKDescriptorInfo &descriptorInfo = _gpuDescriptorSet->instances[t].descriptorInfos[i]; if (binding.gpuBufferView) { - descriptorHub->disengage(binding.gpuBufferView, &descriptorInfo.buffer); + descriptorHub->disengage(_gpuDescriptorSet, binding.gpuBufferView, &descriptorInfo.buffer); } if (bufferView) { descriptorHub->connect(_gpuDescriptorSet, bufferView, &descriptorInfo.buffer, t); @@ -226,7 +226,7 @@ void CCVKDescriptorSet::update() { for (auto &instance : _gpuDescriptorSet->instances) { CCVKDescriptorInfo &descriptorInfo = instance.descriptorInfos[i]; if (binding.gpuTextureView) { - descriptorHub->disengage(binding.gpuTextureView, &descriptorInfo.image); + descriptorHub->disengage(_gpuDescriptorSet, binding.gpuTextureView, &descriptorInfo.image); } if (textureView) { descriptorHub->connect(_gpuDescriptorSet, textureView, &descriptorInfo.image); diff --git a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h index 2f8c4ba9c5..928d9ebcae 100644 --- a/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h +++ b/native/cocos/renderer/gfx-vulkan/VKGPUObjects.h @@ -976,9 +976,10 @@ public: } _buffers.erase(it); } - void disengage(const CCVKGPUBufferView *buffer, VkDescriptorBufferInfo *descriptor) { + void disengage(const CCVKGPUDescriptorSet *set, const CCVKGPUBufferView *buffer, VkDescriptorBufferInfo *descriptor) { auto it = _buffers.find(buffer); if (it == _buffers.end()) return; + it->second.sets.erase(set); auto &descriptors = it->second.descriptors; descriptors.fastRemove(descriptors.indexOf(descriptor)); _bufferInstanceIndices.erase(descriptor); @@ -988,9 +989,10 @@ public: if (it == _textures.end()) return; _textures.erase(it); } - void disengage(const CCVKGPUTextureView *texture, VkDescriptorImageInfo *descriptor) { + void disengage(const CCVKGPUDescriptorSet *set, const CCVKGPUTextureView *texture, VkDescriptorImageInfo *descriptor) { auto it = _textures.find(texture); if (it == _textures.end()) return; + it->second.sets.erase(set); auto &descriptors = it->second.descriptors; descriptors.fastRemove(descriptors.indexOf(descriptor)); } diff --git a/native/cocos/renderer/pipeline/Define.cpp b/native/cocos/renderer/pipeline/Define.cpp index c014930c1a..1880ff1d96 100644 --- a/native/cocos/renderer/pipeline/Define.cpp +++ b/native/cocos/renderer/pipeline/Define.cpp @@ -453,7 +453,8 @@ uint nextPow2(uint val) { bool supportsHalfFloatTexture(gfx::Device *device) { return device->hasFeature(gfx::Feature::COLOR_HALF_FLOAT) && - device->hasFeature(gfx::Feature::TEXTURE_HALF_FLOAT); + device->hasFeature(gfx::Feature::TEXTURE_HALF_FLOAT) && + device->getGfxAPI() != gfx::API::GLES2; } uint getPhaseID(const String &phase) { diff --git a/native/cocos/renderer/pipeline/PipelineSceneData.cpp b/native/cocos/renderer/pipeline/PipelineSceneData.cpp index 9726119681..d386f2c466 100644 --- a/native/cocos/renderer/pipeline/PipelineSceneData.cpp +++ b/native/cocos/renderer/pipeline/PipelineSceneData.cpp @@ -24,7 +24,6 @@ ****************************************************************************/ #include "PipelineSceneData.h" -#include "gfx-base/GFXCommandBuffer.h" #include "gfx-base/GFXDevice.h" #include "gfx-base/GFXFramebuffer.h" @@ -35,8 +34,6 @@ void PipelineSceneData::activate(gfx::Device *device, RenderPipeline *pipeline) { _device = device; _pipeline = pipeline; - - _sphere = CC_NEW(scene::Sphere); } void PipelineSceneData::setPipelineSharedSceneData(scene::PipelineSharedSceneData *data) @@ -46,8 +43,6 @@ void PipelineSceneData::setPipelineSharedSceneData(scene::PipelineSharedSceneDat void PipelineSceneData::destroy() { - CC_SAFE_DELETE(_sphere); - for (auto &pair : _shadowFrameBufferMap) { pair.second->destroy(); delete pair.second; diff --git a/native/cocos/renderer/pipeline/PipelineSceneData.h b/native/cocos/renderer/pipeline/PipelineSceneData.h index 3caebf5d5e..68d21868f5 100644 --- a/native/cocos/renderer/pipeline/PipelineSceneData.h +++ b/native/cocos/renderer/pipeline/PipelineSceneData.h @@ -55,16 +55,26 @@ public: inline const RenderObjectList & getShadowObjects() const { return _shadowObjects; } inline void setRenderObjects(RenderObjectList &&ro) { _renderObjects = std::forward(ro); } inline void setShadowObjects(RenderObjectList &&ro) { _shadowObjects = std::forward(ro); } - inline scene::Sphere * getSphere() const { return _sphere; } + inline float getShadowCameraFar() const { return _shadowCameraFar; } + inline void setShadowCameraFar(float shadowDistance) { _shadowCameraFar = shadowDistance; } + inline Mat4 getMatShadowView() const { return _matShadowView; } + inline void setMatShadowView(const Mat4 &matShadowView) { _matShadowView = matShadowView; } + inline Mat4 getMatShadowProj() const { return _matShadowProj; } + inline void setMatShadowProj(const Mat4 &matShadowProj) { _matShadowProj = matShadowProj; } + inline Mat4 getMatShadowViewProj() const { return _matShadowViewProj; } + inline void setMatShadowViewProj(const Mat4 &matShadowViewProj) { _matShadowViewProj = matShadowViewProj; } private: RenderObjectList _renderObjects; RenderObjectList _shadowObjects; - scene::PipelineSharedSceneData *_sharedSceneData = nullptr; - RenderPipeline * _pipeline = nullptr; - gfx::Device * _device = nullptr; - scene::Sphere * _sphere = nullptr; + scene::PipelineSharedSceneData *_sharedSceneData = nullptr; + RenderPipeline * _pipeline = nullptr; + gfx::Device * _device = nullptr; + float _shadowCameraFar = 0.0F; + Mat4 _matShadowView; + Mat4 _matShadowProj; + Mat4 _matShadowViewProj; std::unordered_map _shadowFrameBufferMap; }; diff --git a/native/cocos/renderer/pipeline/PipelineUBO.cpp b/native/cocos/renderer/pipeline/PipelineUBO.cpp index 2d1011a923..41228c7c81 100644 --- a/native/cocos/renderer/pipeline/PipelineUBO.cpp +++ b/native/cocos/renderer/pipeline/PipelineUBO.cpp @@ -47,9 +47,9 @@ namespace pipeline { Mat4 matShadowViewProj; void PipelineUBO::updateGlobalUBOView(const scene::Camera *camera, std::array *bufferView) { - auto *const root = scene::Root::instance; - auto * device = gfx::Device::getInstance(); - auto & uboGlobalView = *bufferView; + const scene::Root * root = scene::Root::instance; + const gfx::Device * device = gfx::Device::getInstance(); + std::array &uboGlobalView = *bufferView; const auto shadingWidth = std::floor(camera->window->getWidth()); const auto shadingHeight = std::floor(camera->window->getHeight()); @@ -84,8 +84,8 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *out auto *device = gfx::Device::getInstance(); - const auto shadingWidth = std::floor(camera->window->getWidth()); - const auto shadingHeight = std::floor(camera->window->getHeight()); + const auto shadingWidth = static_cast(std::floor(camera->window->getWidth())); + const auto shadingHeight = static_cast(std::floor(camera->window->getHeight())); output[UBOCamera::SCREEN_SCALE_OFFSET + 0] = static_cast(camera->width / shadingWidth * shadingScale); output[UBOCamera::SCREEN_SCALE_OFFSET + 1] = static_cast(camera->height / shadingHeight * shadingScale); @@ -99,8 +99,8 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *out output[UBOCamera::EXPOSURE_OFFSET + 3] = fpScale / exposure; if (mainLight) { - TO_VEC3(output, mainLight->getDirection(), UBOCamera::MAIN_LIT_DIR_OFFSET); - TO_VEC3(output, mainLight->getColor(), UBOCamera::MAIN_LIT_COLOR_OFFSET); + TO_VEC3(output, mainLight->getDirection(), UBOCamera::MAIN_LIT_DIR_OFFSET) + TO_VEC3(output, mainLight->getColor(), UBOCamera::MAIN_LIT_COLOR_OFFSET) if (mainLight->getUseColorTemperature()) { const auto &colorTempRGB = mainLight->getColorTemperatureRGB(); output[UBOCamera::MAIN_LIT_COLOR_OFFSET + 0] *= colorTempRGB.x; @@ -124,7 +124,7 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *out } else { skyColor.w = ambient->skyIllum * exposure; } - TO_VEC4(output, skyColor, UBOCamera::AMBIENT_SKY_OFFSET); + TO_VEC4(output, skyColor, UBOCamera::AMBIENT_SKY_OFFSET) output[UBOCamera::AMBIENT_GROUND_OFFSET + 0] = ambient->groundAlbedo.x; output[UBOCamera::AMBIENT_GROUND_OFFSET + 1] = ambient->groundAlbedo.y; @@ -136,7 +136,7 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *out memcpy(output + UBOCamera::MAT_VIEW_OFFSET, camera->matView.m, sizeof(cc::Mat4)); memcpy(output + UBOCamera::MAT_VIEW_INV_OFFSET, camera->node->getWorldMatrix().m, sizeof(cc::Mat4)); - TO_VEC3(output, camera->position, UBOCamera::CAMERA_POS_OFFSET); + TO_VEC3(output, camera->position, UBOCamera::CAMERA_POS_OFFSET) memcpy(output + UBOCamera::MAT_PROJ_OFFSET, camera->matProj.m, sizeof(cc::Mat4)); memcpy(output + UBOCamera::MAT_PROJ_INV_OFFSET, camera->matProjInv.m, sizeof(cc::Mat4)); @@ -145,7 +145,7 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *out output[UBOCamera::CAMERA_POS_OFFSET + 3] = getCombineSignY(); if (fog->enabled) { - TO_VEC4(output, fog->color, UBOCamera::GLOBAL_FOG_COLOR_OFFSET); + TO_VEC4(output, fog->color, UBOCamera::GLOBAL_FOG_COLOR_OFFSET) output[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 0] = fog->start; output[UBOCamera::GLOBAL_FOG_BASE_OFFSET + 1] = fog->end; @@ -158,70 +158,61 @@ void PipelineUBO::updateCameraUBOView(const RenderPipeline *pipeline, float *out } void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, std::array *bufferView, const scene::Camera *camera) { - const auto *const scene = camera->scene; - const scene::DirectionalLight *mainLight = scene->getMainLight(); - - auto * device = gfx::Device::getInstance(); - auto *const sceneData = pipeline->getPipelineSceneData(); - auto *const shadowInfo = sceneData->getSharedData()->shadow; - auto & shadowUBO = *bufferView; - auto * sphere = sceneData->getSphere(); - const bool hFTexture = supportsHalfFloatTexture(device); + const scene::RenderScene *const scene = camera->scene; + const scene::DirectionalLight * mainLight = scene->getMainLight(); + gfx::Device * device = gfx::Device::getInstance(); + const PipelineSceneData * sceneData = pipeline->getPipelineSceneData(); + scene::Shadow *const shadowInfo = sceneData->getSharedData()->shadow; + std::array &shadowUBO = *bufferView; + const bool hFTexture = supportsHalfFloatTexture(device); if (shadowInfo->enabled) { if (mainLight && shadowInfo->shadowType == scene::ShadowType::SHADOWMAP) { - auto *const node = mainLight->getNode(); - cc::Mat4 matShadowCamera; - - // light proj - float x; - float y; + float nearClamp; float farClamp; - if (shadowInfo->autoAdapt) { - Vec3 tmpCenter; - getShadowWorldMatrix(sphere, node->getWorldRotation(), mainLight->getDirection(), &matShadowCamera, &tmpCenter); - - const float radius = sphere->getRadius(); - x = radius; - y = radius; - - const float halfFar = tmpCenter.distance(sphere->getCenter()); - farClamp = std::min(halfFar * COEFFICIENT_OF_EXPANSION, SHADOW_CAMERA_MAX_FAR); - } else { - matShadowCamera = mainLight->getNode()->getWorldMatrix(); - - x = shadowInfo->orthoSize; - y = shadowInfo->orthoSize; - - farClamp = shadowInfo->farValue; - } - const auto matShadowView = matShadowCamera.getInversed(); - - const auto projectionSinY = device->getCapabilities().clipSpaceSignY; + Mat4 matShadowView; Mat4 matShadowProj; - Mat4::createOrthographicOffCenter(-x, x, -y, y, shadowInfo->nearValue, farClamp, device->getCapabilities().clipSpaceMinZ, projectionSinY, &matShadowProj); - matShadowViewProj = matShadowProj; - matShadowViewProj.multiply(matShadowView); + Mat4 matShadowViewProj; + if (!shadowInfo->fixedArea) { + nearClamp = shadowInfo->nearValue; + farClamp = sceneData->getShadowCameraFar(); + matShadowView = sceneData->getMatShadowView(); + matShadowProj = sceneData->getMatShadowProj(); + matShadowViewProj = sceneData->getMatShadowViewProj(); + } else { + const auto *node = mainLight->getNode(); + matShadowView = node->getWorldMatrix().getInversed(); + const float x = shadowInfo->orthoSize; + const float y = shadowInfo->orthoSize; + nearClamp = shadowInfo->nearValue; + farClamp = shadowInfo->farValue; + const float projectionSinY = device->getCapabilities().clipSpaceSignY; + const float clipSpaceMinZ = device->getCapabilities().clipSpaceMinZ; + Mat4::createOrthographicOffCenter(-x, x, -y, y, -nearClamp, + farClamp, clipSpaceMinZ, projectionSinY, &matShadowProj); + matShadowViewProj = matShadowProj * matShadowView; + } memcpy(shadowUBO.data() + UBOShadow::MAT_LIGHT_VIEW_OFFSET, matShadowView.m, sizeof(matShadowView)); + + const float shadowProjDepthInfos[4] = {matShadowProj.m[10], matShadowProj.m[14], matShadowProj.m[11], matShadowProj.m[15]}; + memcpy(shadowUBO.data() + UBOShadow::SHADOW_PROJ_DEPTH_INFO_OFFSET, &shadowProjDepthInfos, sizeof(shadowProjDepthInfos)); + + const float shadowProjInfos[4] = {matShadowProj.m[00], matShadowProj.m[05], 1.0F / matShadowProj.m[00], 1.0F / matShadowProj.m[05]}; + memcpy(shadowUBO.data() + UBOShadow::SHADOW_PROJ_INFO_OFFSET, &shadowProjInfos, sizeof(shadowProjInfos)); + memcpy(shadowUBO.data() + UBOShadow::MAT_LIGHT_VIEW_PROJ_OFFSET, matShadowViewProj.m, sizeof(matShadowViewProj)); - const float linear = hFTexture ? 1.0F : 0.0F; - float shadowNFLSInfos[4] = {shadowInfo->nearValue, farClamp, linear, 1.0F - shadowInfo->saturation}; + const float linear = 0.0F; + const float shadowNFLSInfos[4] = {nearClamp, farClamp, linear, 1.0F - shadowInfo->saturation}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_NEAR_FAR_LINEAR_SATURATION_INFO_OFFSET, &shadowNFLSInfos, sizeof(shadowNFLSInfos)); - float shadowWHPBInfos[4] = {shadowInfo->size.x, shadowInfo->size.y, static_cast(shadowInfo->pcfType), shadowInfo->bias}; + const float shadowWHPBInfos[4] = {shadowInfo->size.x, shadowInfo->size.y, static_cast(shadowInfo->pcfType), shadowInfo->bias}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_WIDTH_HEIGHT_PCF_BIAS_INFO_OFFSET, &shadowWHPBInfos, sizeof(shadowWHPBInfos)); const float packing = hFTexture ? 0.0F : 1.0F; - float shadowLPNNInfos[4] = {0.0F, packing, shadowInfo->normalBias, 0.0F}; + const float shadowLPNNInfos[4] = {0.0F, packing, shadowInfo->normalBias, 0.0F}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET, &shadowLPNNInfos, sizeof(shadowLPNNInfos)); - - float shadowProjDepthInfos[4] = {matShadowProj.m[10], matShadowProj.m[14], matShadowProj.m[11], matShadowProj.m[15]}; - memcpy(shadowUBO.data() + UBOShadow::SHADOW_PROJ_DEPTH_INFO_OFFSET, &shadowProjDepthInfos, sizeof(shadowProjDepthInfos)); - - float shadowProjInfos[4] = {matShadowProj.m[00], matShadowProj.m[05], 1.0F / matShadowProj.m[00], 1.0F / matShadowProj.m[05]}; - memcpy(shadowUBO.data() + UBOShadow::SHADOW_PROJ_INFO_OFFSET, &shadowProjInfos, sizeof(shadowProjInfos)); } else if (mainLight && shadowInfo->shadowType == scene::ShadowType::PLANAR) { updateDirLight(shadowInfo, mainLight, &shadowUBO); } @@ -231,51 +222,53 @@ void PipelineUBO::updateShadowUBOView(const RenderPipeline *pipeline, std::array } } -void PipelineUBO::updateShadowUBOLightView(const RenderPipeline *pipeline, std::array *bufferView, const scene::Light *light) { - auto *const sceneData = pipeline->getPipelineSceneData(); - auto * shadowInfo = sceneData->getSharedData()->shadow; +void PipelineUBO::updateShadowUBOLightView(const RenderPipeline *pipeline, std::array *bufferView, + const scene::Light *light) { + const auto *sceneData = pipeline->getPipelineSceneData(); + const auto *shadowInfo = sceneData->getSharedData()->shadow; auto * device = gfx::Device::getInstance(); - auto * sphere = sceneData->getSphere(); auto & shadowUBO = *bufferView; const bool hFTexture = supportsHalfFloatTexture(device); const float linear = 0.0F; const float packing = hFTexture ? 0.0F : 1.0F; switch (light->getType()) { case scene::LightType::DIRECTIONAL: { - const auto *directionalLight = static_cast(light); - cc::Mat4 matShadowCamera; - - float x; - float y; + float nearClamp; float farClamp; - if (shadowInfo->autoAdapt) { - Vec3 tmpCenter; - getShadowWorldMatrix(sphere, directionalLight->getNode()->getWorldRotation(), directionalLight->getDirection(), &matShadowCamera, &tmpCenter); - - const auto radius = sphere->getRadius(); - x = radius; - y = radius; - - const float halfFar = tmpCenter.distance(sphere->getCenter()); - farClamp = std::min(halfFar * COEFFICIENT_OF_EXPANSION, SHADOW_CAMERA_MAX_FAR); + Mat4 matShadowView; + Mat4 matShadowProj; + Mat4 matShadowViewProj; + if (!shadowInfo->fixedArea) { + nearClamp = 0.1F; + farClamp = sceneData->getShadowCameraFar(); + matShadowView = sceneData->getMatShadowView(); + matShadowProj = sceneData->getMatShadowProj(); + matShadowViewProj = sceneData->getMatShadowViewProj(); } else { - matShadowCamera = light->getNode()->getWorldMatrix(); - - x = shadowInfo->orthoSize; - y = shadowInfo->orthoSize; - - farClamp = shadowInfo->farValue; + auto *const node = light->getNode(); + matShadowView = node->getWorldMatrix().getInversed(); + const float x = shadowInfo->orthoSize; + const float y = shadowInfo->orthoSize; + nearClamp = shadowInfo->nearValue; + farClamp = shadowInfo->farValue; + const float projectionSinY = device->getCapabilities().clipSpaceSignY; + const float clipSpaceMinZ = device->getCapabilities().clipSpaceMinZ; + Mat4::createOrthographicOffCenter(-x, x, -y, y, -nearClamp, + farClamp, clipSpaceMinZ, projectionSinY, &matShadowProj); + matShadowViewProj = matShadowProj * matShadowView; } - const auto matShadowView = matShadowCamera.getInversed(); + memcpy(shadowUBO.data() + UBOShadow::MAT_LIGHT_VIEW_OFFSET, matShadowView.m, sizeof(matShadowView)); - const auto projectionSinY = device->getCapabilities().clipSpaceSignY; - Mat4::createOrthographicOffCenter(-x, x, -y, y, shadowInfo->nearValue, farClamp, device->getCapabilities().clipSpaceMinZ, projectionSinY, &matShadowViewProj); + float shadowProjDepthInfos[4] = {matShadowProj.m[10], matShadowProj.m[14], matShadowProj.m[11], matShadowProj.m[15]}; + memcpy(shadowUBO.data() + UBOShadow::SHADOW_PROJ_DEPTH_INFO_OFFSET, &shadowProjDepthInfos, sizeof(shadowProjDepthInfos)); + + float shadowProjInfos[4] = {matShadowProj.m[00], matShadowProj.m[05], 1.0F / matShadowProj.m[00], 1.0F / matShadowProj.m[05]}; + memcpy(shadowUBO.data() + UBOShadow::SHADOW_PROJ_INFO_OFFSET, &shadowProjInfos, sizeof(shadowProjInfos)); - matShadowViewProj.multiply(matShadowView); memcpy(shadowUBO.data() + UBOShadow::MAT_LIGHT_VIEW_PROJ_OFFSET, matShadowViewProj.m, sizeof(matShadowViewProj)); - float shadowNFLSInfos[4] = {shadowInfo->nearValue, farClamp, linear, 1.0F - shadowInfo->saturation}; + float shadowNFLSInfos[4] = {nearClamp, farClamp, linear, 1.0F - shadowInfo->saturation}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_NEAR_FAR_LINEAR_SATURATION_INFO_OFFSET, &shadowNFLSInfos, sizeof(shadowNFLSInfos)); float shadowLPNNInfos[4] = {0.0F, packing, shadowInfo->normalBias, 0.0F}; @@ -287,26 +280,28 @@ void PipelineUBO::updateShadowUBOLightView(const RenderPipeline *pipeline, std:: const auto matShadowView = matShadowCamera.getInversed(); memcpy(shadowUBO.data() + UBOShadow::MAT_LIGHT_VIEW_OFFSET, matShadowView.m, sizeof(matShadowView)); - cc::Mat4::createPerspective(spotLight->getSpotAngle(), spotLight->getAspect(), 0.001F, spotLight->getRange(), &matShadowViewProj); + Mat4::createPerspective(spotLight->getSpotAngle(), spotLight->getAspect(), 0.001F, spotLight->getRange(), &matShadowViewProj); matShadowViewProj.multiply(matShadowView); memcpy(shadowUBO.data() + UBOShadow::MAT_LIGHT_VIEW_PROJ_OFFSET, matShadowViewProj.m, sizeof(matShadowViewProj)); - float shadowNFLSInfos[4] = {0.01F, spotLight->getRange(), linear, 1.0F - shadowInfo->saturation}; + const float shadowNFLSInfos[4] = {0.01F, spotLight->getRange(), linear, 1.0F - shadowInfo->saturation}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_NEAR_FAR_LINEAR_SATURATION_INFO_OFFSET, &shadowNFLSInfos, sizeof(shadowNFLSInfos)); - float shadowLPNNInfos[4] = {1.0F, packing, shadowInfo->normalBias, 0.0F}; + const float shadowLPNNInfos[4] = {1.0F, packing, shadowInfo->normalBias, 0.0F}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_LIGHT_PACKING_NBIAS_NULL_INFO_OFFSET, &shadowLPNNInfos, sizeof(shadowLPNNInfos)); } break; + case scene::LightType::SPHERE: break; + case scene::LightType::UNKNOWN: break; default: break; } - float shadowWHPBInfos[4] = {shadowInfo->size.x, shadowInfo->size.y, static_cast(shadowInfo->pcfType), shadowInfo->bias}; + const float shadowWHPBInfos[4] = {shadowInfo->size.x, shadowInfo->size.y, static_cast(shadowInfo->pcfType), shadowInfo->bias}; memcpy(shadowUBO.data() + UBOShadow::SHADOW_WIDTH_HEIGHT_PCF_BIAS_INFO_OFFSET, &shadowWHPBInfos, sizeof(shadowWHPBInfos)); const float color[4] = {shadowInfo->color.x, shadowInfo->color.y, shadowInfo->color.z, shadowInfo->color.w}; - memcpy(shadowUBO.data() + UBOShadow::SHADOW_COLOR_OFFSET, &color, sizeof(float) * 4); + memcpy(shadowUBO.data() + UBOShadow::SHADOW_COLOR_OFFSET, &color, sizeof(color)); } static uint8_t combineSignY = 0; @@ -368,7 +363,7 @@ void PipelineUBO::activate(gfx::Device *device, RenderPipeline *pipeline) { void PipelineUBO::destroy() { for (auto &ubo : _ubos) { - CC_SAFE_DESTROY(ubo); + CC_SAFE_DESTROY(ubo) } _ubos.clear(); } @@ -385,18 +380,14 @@ void PipelineUBO::updateGlobalUBO(const scene::Camera *camera) { } void PipelineUBO::updateCameraUBO(const scene::Camera *camera) { - auto *const globalDSManager = _pipeline->getGlobalDSManager(); - auto *const ds = _pipeline->getDescriptorSet(); auto *const cmdBuffer = _pipeline->getCommandBuffers()[0]; PipelineUBO::updateCameraUBOView(_pipeline, _cameraUBOs.data(), camera); cmdBuffer->updateBuffer(_cameraBuffer, _cameraUBOs.data()); } void PipelineUBO::updateMultiCameraUBO(const vector &cameras) { - auto *const ds = _pipeline->getDescriptorSet(); - auto * device = _pipeline->getDevice(); - auto cameraCount = cameras.size(); - auto totalUboSize = static_cast(_alignedCameraUBOSize * cameraCount); + const auto cameraCount = cameras.size(); + const auto totalUboSize = static_cast(_alignedCameraUBOSize * cameraCount); if (_cameraBuffer->getSize() < totalUboSize) { _cameraBuffer->resize(totalUboSize); @@ -404,8 +395,8 @@ void PipelineUBO::updateMultiCameraUBO(const vector &cameras) { } for (uint cameraIdx = 0; cameraIdx < cameraCount; ++cameraIdx) { - auto *camera = cameras[cameraIdx]; - auto offset = cameraIdx * _alignedCameraUBOSize / sizeof(float); + const auto *camera = cameras[cameraIdx]; + const auto offset = cameraIdx * _alignedCameraUBOSize / sizeof(float); PipelineUBO::updateCameraUBOView(_pipeline, &_cameraUBOs[offset], camera); } _cameraBuffer->update(_cameraUBOs.data()); @@ -416,8 +407,8 @@ void PipelineUBO::updateMultiCameraUBO(const vector &cameras) { void PipelineUBO::updateShadowUBO(const scene::Camera *camera) { auto *const ds = _pipeline->getDescriptorSet(); auto *const cmdBuffer = _pipeline->getCommandBuffers()[0]; - auto *const sceneData = _pipeline->getPipelineSceneData(); - auto *const shadowInfo = sceneData->getSharedData()->shadow; + const auto * sceneData = _pipeline->getPipelineSceneData(); + const auto * shadowInfo = sceneData->getSharedData()->shadow; const auto *const scene = camera->scene; if (!shadowInfo->enabled) return; @@ -437,7 +428,7 @@ void PipelineUBO::updateShadowUBO(const scene::Camera *camera) { } void PipelineUBO::updateShadowUBOLight(const scene::Light *light) { - auto *const ds = _pipeline->getDescriptorSet(); + const auto *ds = _pipeline->getDescriptorSet(); auto *const cmdBuffer = _pipeline->getCommandBuffers()[0]; PipelineUBO::updateShadowUBOLightView(_pipeline, &_shadowUBO, light); cmdBuffer->updateBuffer(ds->getBuffer(UBOShadow::BINDING), _shadowUBO.data(), UBOShadow::SIZE); diff --git a/native/cocos/renderer/pipeline/SceneCulling.cpp b/native/cocos/renderer/pipeline/SceneCulling.cpp index c7e9c20fd9..c4120ebca2 100644 --- a/native/cocos/renderer/pipeline/SceneCulling.cpp +++ b/native/cocos/renderer/pipeline/SceneCulling.cpp @@ -29,8 +29,7 @@ #include "Define.h" #include "RenderPipeline.h" #include "SceneCulling.h" -#include "gfx-base/GFXBuffer.h" -#include "gfx-base/GFXDescriptorSet.h" +#include "gfx-base/GFXDevice.h" #include "math/Quaternion.h" #include "platform/Application.h" #include "scene/AABB.h" @@ -38,16 +37,15 @@ #include "scene/RenderScene.h" #include "scene/Sphere.h" #include "scene/SpotLight.h" +#include "scene/Frustum.h" namespace cc { namespace pipeline { -bool castBoundsInitialized = false; -scene::AABB castWorldBounds; RenderObject genRenderObject(const scene::Model *model, const scene::Camera *camera) { float depth = 0; if (model->getNode()) { - auto *const node = model->getTransform(); + const auto *node = model->getTransform(); cc::Vec3 position; cc::Vec3::subtract(node->getWorldPosition(), camera->position, &position); depth = position.dot(camera->forward); @@ -68,7 +66,7 @@ void getShadowWorldMatrix(const scene::Sphere *sphere, const cc::Quaternion &rot } void updateSphereLight(scene::Shadow *shadows, const scene::Light *light, std::array *shadowUBO) { - auto *const node = light->getNode(); + const auto *node = light->getNode(); if (!node->getFlagsChanged() && !shadows->dirty) { return; } @@ -106,9 +104,9 @@ void updateSphereLight(scene::Shadow *shadows, const scene::Light *light, std::a } void updateDirLight(scene::Shadow *shadows, const scene::Light *light, std::array *shadowUBO) { - auto *const node = light->getNode(); + const auto * node = light->getNode(); const auto &rotation = node->getWorldRotation(); - Quaternion qt(rotation.x, rotation.y, rotation.z, rotation.w); + const Quaternion qt(rotation.x, rotation.y, rotation.z, rotation.w); Vec3 forward(0, 0, -1.0F); forward.transformQuat(qt); const auto &normal = shadows->normal; @@ -140,8 +138,8 @@ void updateDirLight(scene::Shadow *shadows, const scene::Light *light, std::arra matLight.m[15] = 1; memcpy(shadowUBO->data() + UBOShadow::MAT_LIGHT_PLANE_PROJ_OFFSET, matLight.m, sizeof(matLight)); - float color[4] = {shadows->color.x, shadows->color.y, shadows->color.z, shadows->color.w}; - memcpy(shadowUBO->data() + UBOShadow::SHADOW_COLOR_OFFSET, &color, sizeof(float) * 4); + const float color[4] = {shadows->color.x, shadows->color.y, shadows->color.z, shadows->color.w}; + memcpy(shadowUBO->data() + UBOShadow::SHADOW_COLOR_OFFSET, &color, sizeof(color)); } void lightCollecting(scene::Camera *camera, std::vector *validLights) { @@ -159,21 +157,153 @@ void lightCollecting(scene::Camera *camera, std::vector *v } } - CC_SAFE_DELETE(sphere); + CC_SAFE_DELETE(sphere) } -void sceneCulling(RenderPipeline *pipeline, scene::Camera *camera) { - auto *const sceneData = pipeline->getPipelineSceneData(); - auto *const sharedData = sceneData->getSharedData(); - auto *const shadows = sharedData->shadow; - auto *const skyBox = sharedData->skybox; - const auto *const scene = camera->scene; +Mat4 getCameraWorldMatrix(const scene::Camera* camera) { + Mat4 out; + if (!camera || !camera->node) { + return out; + } + + const scene::Node *cameraNode = camera->node; + const Vec3 & position = cameraNode->getWorldPosition(); + const Quaternion & rotation = cameraNode->getWorldRotation(); + + Mat4::fromRT(rotation, position, &out); + out.m[8] *= -1.0F; + out.m[9] *= -1.0F; + out.m[10] *= -1.0F; + + return out; +} + +void updateDirFrustum(const scene::Sphere *cameraBoundingSphere, const Quaternion &rotation, float range, scene::Frustum *dirLightFrustum) { + const float radius = cameraBoundingSphere->getRadius(); + const Vec3 &position = cameraBoundingSphere->getCenter(); + Mat4 matWorldTrans; + Mat4::fromRT(rotation, position, &matWorldTrans); + matWorldTrans.m[8] *= -1.0F; + matWorldTrans.m[9] *= -1.0F; + matWorldTrans.m[10] *= -1.0F; + + dirLightFrustum->createOrtho(radius, radius, -range, radius, matWorldTrans); +} + +void quantizeDirLightShadowCamera(RenderPipeline *pipeline, const scene::Camera *camera, scene::Frustum *out) { + const gfx::Device * device = gfx::Device::getInstance(); + PipelineSceneData *const sceneData = pipeline->getPipelineSceneData(); + const scene::PipelineSharedSceneData *sharedData = sceneData->getSharedData(); + const scene::Shadow * shadowInfo = sharedData->shadow; + const scene::RenderScene *const scene = camera->scene; + const scene::DirectionalLight * mainLight = scene->getMainLight(); + const float invisibleOcclusionRange = shadowInfo->invisibleOcclusionRange; + const float shadowMapWidth = shadowInfo->size.x; + const auto * node = mainLight->getNode(); + const Quaternion & rotation = node->getWorldRotation(); + + // Raw data. + const Mat4 matWorldTrans = getCameraWorldMatrix(camera); + scene::Frustum validFrustum; + validFrustum.type = scene::ShapeEnums::SHAPE_FRUSTUM_ACCURATE; + validFrustum.split(0.1F, shadowInfo->shadowDistance, camera->aspect, camera->fov, matWorldTrans); + scene::Frustum lightViewFrustum = validFrustum.clone(); + + // view matrix with range back. + Mat4 matShadowTrans; + Mat4::fromRT(rotation, Vec3::ZERO, &matShadowTrans); + Mat4 matShadowView = matShadowTrans.getInversed(); + Mat4 matShadowViewInv = matShadowView.getInversed(); + + const Mat4 shadowViewArbitraryPos = matShadowView.clone(); + lightViewFrustum.transform(matShadowView); + // bounding box in light space. + scene::AABB castLightViewBounds; + scene::AABB::fromPoints(Vec3(10000000.0F, 10000000.0F, 10000000.0F), Vec3(-10000000.0F, -10000000.0F, -10000000.0F), &castLightViewBounds); + castLightViewBounds.merge(lightViewFrustum); + + const float r = castLightViewBounds.getHalfExtents().z * 2.0F; + Vec3 shadowPos(castLightViewBounds.getCenter().x, castLightViewBounds.getCenter().y, + castLightViewBounds.getCenter().z + castLightViewBounds.getHalfExtents().z + invisibleOcclusionRange); + shadowPos.transformMat4(shadowPos, matShadowViewInv); + + Mat4::fromRT(rotation, shadowPos, &matShadowTrans); + matShadowView = matShadowTrans.getInversed(); + matShadowViewInv = matShadowView.getInversed(); + + // calculate projection matrix params. + // min value may lead to some shadow leaks. + const float orthoSizeMin = validFrustum.vertices[0].distance(validFrustum.vertices[6]); + // max value is accurate but poor usage for shadowMap + scene::Sphere cameraBoundingSphere; + cameraBoundingSphere.setCenter(Vec3(0.0F, 0.0F, 0.0F)); + cameraBoundingSphere.setRadius(-1.0F); + cameraBoundingSphere.merge(validFrustum); + const float orthoSizeMax = cameraBoundingSphere.getRadius() * 2.0F; + // use lerp(min, accurate_max) to save shadowMap usage + const float orthoSize = orthoSizeMin * 0.8F + orthoSizeMax * 0.2F; + sceneData->setShadowCameraFar(r + invisibleOcclusionRange); + + // snap to whole texels + const float halfOrthoSize = orthoSize * 0.5F; + Mat4 matShadowProj; + const float projectionSinY = device->getCapabilities().clipSpaceSignY; + const float clipSpaceMinZ = device->getCapabilities().clipSpaceMinZ; + Mat4::createOrthographicOffCenter(-halfOrthoSize, halfOrthoSize, -halfOrthoSize, halfOrthoSize, 0.1F, sceneData->getShadowCameraFar(), + clipSpaceMinZ, projectionSinY, &matShadowProj); + + if (shadowMapWidth > 0.0F) { + const Mat4 matShadowViewProjArbitraryPos = matShadowProj * shadowViewArbitraryPos; + Vec3 projPos; + projPos.transformMat4(shadowPos, matShadowViewProjArbitraryPos); + const float invActualSize = 2.0F / shadowMapWidth; + const Vec2 texelSize(invActualSize, invActualSize); + const float modX = fmodf(projPos.x, texelSize.x); + const float modY = fmodf(projPos.y, texelSize.y); + const Vec3 projSnap(projPos.x - modX, projPos.y - modY, projPos.z); + + const Mat4 matShadowViewProjArbitaryPosInv = matShadowViewProjArbitraryPos.getInversed(); + Vec3 snap; + snap.transformMat4(projSnap, matShadowViewProjArbitaryPosInv); + Mat4::fromRT(rotation, snap, &matShadowTrans); + matShadowView = matShadowTrans.getInversed(); + matShadowViewInv = matShadowView.getInversed(); + out->createOrtho(orthoSize, orthoSize, 0.1F, sceneData->getShadowCameraFar(), matShadowViewInv); + } else { + for (uint i = 0; i < 8; i++) { + out->vertices[i].setZero(); + } + out->updatePlanes(); + } + + const Mat4 matShadowViewProj = matShadowProj * matShadowView; + sceneData->setMatShadowView(matShadowView); + sceneData->setMatShadowProj(matShadowProj); + sceneData->setMatShadowViewProj(matShadowViewProj); +} +void sceneCulling(RenderPipeline *pipeline, scene::Camera *camera) { + PipelineSceneData *const sceneData = pipeline->getPipelineSceneData(); + const scene::PipelineSharedSceneData *sharedData = sceneData->getSharedData(); + const scene::Shadow * shadowInfo = sharedData->shadow; + const scene::Skybox * skyBox = sharedData->skybox; + const scene::RenderScene *const scene = camera->scene; + const scene::DirectionalLight * mainLight = scene->getMainLight(); + scene::Frustum dirLightFrustum; - castBoundsInitialized = false; RenderObjectList shadowObjects; bool isShadowMap = false; - if (shadows->enabled && shadows->shadowType == scene::ShadowType::SHADOWMAP) { + if (shadowInfo->enabled && shadowInfo->shadowType == scene::ShadowType::SHADOWMAP) { isShadowMap = true; + + // update dirLightFrustum + if (mainLight && mainLight->getNode()) { + quantizeDirLightShadowCamera(pipeline, camera, &dirLightFrustum); + } else { + for (Vec3 &vertex : dirLightFrustum.vertices) { + vertex.setZero(); + } + dirLightFrustum.updatePlanes(); + } } RenderObjectList renderObjects; @@ -193,12 +323,9 @@ void sceneCulling(RenderPipeline *pipeline, scene::Camera *camera) { // shadow render Object const auto *modelWorldBounds = model->getWorldBounds(); if (isShadowMap && model->getCastShadow() && modelWorldBounds) { - if (!castBoundsInitialized) { - castWorldBounds.set(modelWorldBounds->getCenter(), modelWorldBounds->getHalfExtents()); - castBoundsInitialized = true; - } - castWorldBounds.merge(*modelWorldBounds); - shadowObjects.emplace_back(genRenderObject(model, camera)); + if (!modelWorldBounds->aabbFrustum(dirLightFrustum)){ + shadowObjects.emplace_back(genRenderObject(model, camera)); + } } // frustum culling if (modelWorldBounds && !modelWorldBounds->aabbFrustum(camera->frustum)) { @@ -211,7 +338,6 @@ void sceneCulling(RenderPipeline *pipeline, scene::Camera *camera) { } if (isShadowMap) { - sceneData->getSphere()->define(castWorldBounds); sceneData->setShadowObjects(std::move(shadowObjects)); } diff --git a/native/cocos/renderer/pipeline/SceneCulling.h b/native/cocos/renderer/pipeline/SceneCulling.h index 58cad43afc..cf8e62f8bb 100644 --- a/native/cocos/renderer/pipeline/SceneCulling.h +++ b/native/cocos/renderer/pipeline/SceneCulling.h @@ -29,6 +29,7 @@ #include "scene/Define.h" #include "scene/Light.h" #include "scene/Sphere.h" +#include "scene/Frustum.h" namespace cc { class Mat4; @@ -40,11 +41,13 @@ struct RenderObject; class RenderPipeline; RenderObject genRenderObject(const scene::Model *, const scene::Camera *); - -void lightCollecting(scene::Camera *, std::vector *); -void sceneCulling(RenderPipeline *, scene::Camera *); -void updateSphereLight(scene::Shadow *shadows, const scene::Light *light, std::array *); -void updateDirLight(scene::Shadow *shadows, const scene::Light *light, std::array *); -void getShadowWorldMatrix(const scene::Sphere *sphere, const cc::Quaternion &rotation, const cc::Vec3 &dir, cc::Mat4 *shadowWorldMat, cc::Vec3 *out); +void quantizeDirLightShadowCamera(RenderPipeline *pipeline, const scene::Camera *camera, scene::Frustum *out); +void lightCollecting(scene::Camera *, std::vector *); +void sceneCulling(RenderPipeline *, scene::Camera *); +void updateSphereLight(scene::Shadow *shadows, const scene::Light *light, std::array *); +void updateDirLight(scene::Shadow *shadows, const scene::Light *light, std::array *); +void getShadowWorldMatrix(const scene::Sphere *sphere, const cc::Quaternion &rotation, const cc::Vec3 &dir, cc::Mat4 *shadowWorldMat, cc::Vec3 *out); +Mat4 getCameraWorldMatrix(const scene::Camera *camera); +void updateDirFrustum(const scene::Sphere *cameraBoundingSphere, const Quaternion &rotation, float range, scene::Frustum *dirLightFrustum); } // namespace pipeline } // namespace cc diff --git a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp index 22e24b65d4..12f0c04a99 100644 --- a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp +++ b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.cpp @@ -72,8 +72,16 @@ void ShadowMapBatchedQueue::gatherLightPasses(const scene::Light *light, gfx::Co add(model, cmdBuffer); } } break; - default: - break; + + case scene::LightType::SPHERE: { + } break; + + case scene::LightType::UNKNOWN: { + } break; + + default: { + + } break; } } } @@ -137,9 +145,9 @@ void ShadowMapBatchedQueue::recordCommandBuffer(gfx::Device *device, gfx::Render } void ShadowMapBatchedQueue::destroy() { - CC_SAFE_DELETE(_batchedQueue); + CC_SAFE_DELETE(_batchedQueue) - CC_SAFE_DELETE(_instancedQueue); + CC_SAFE_DELETE(_instancedQueue) _buffer = nullptr; } diff --git a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.h b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.h index 4e883f54ce..99806ba41e 100644 --- a/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.h +++ b/native/cocos/renderer/pipeline/ShadowMapBatchedQueue.h @@ -29,6 +29,7 @@ #include "scene/Light.h" #include "scene/Model.h" #include "scene/SubModel.h" +#include "scene/Camera.h" namespace cc { namespace pipeline { diff --git a/native/cocos/scene/AABB.cpp b/native/cocos/scene/AABB.cpp index 2a1f44cf3a..595a5e95fd 100644 --- a/native/cocos/scene/AABB.cpp +++ b/native/cocos/scene/AABB.cpp @@ -25,6 +25,8 @@ #include "AABB.h" +#include "base/TypeDef.h" + namespace cc { namespace scene { bool AABB::aabbAabb(AABB *aabb) const { @@ -74,21 +76,55 @@ void AABB::getBoundary(cc::Vec3 *minPos, cc::Vec3 *maxPos) const { } void AABB::merge(const AABB &aabb) { - cc::Vec3 minA = getCenter() - getHalfExtents(); - cc::Vec3 minB = aabb.getCenter() - aabb.getHalfExtents(); - cc::Vec3 maxA = getCenter() + getHalfExtents(); - cc::Vec3 maxB = aabb.getCenter() + aabb.getHalfExtents(); + const cc::Vec3 minA = getCenter() - getHalfExtents(); + const cc::Vec3 minB = aabb.getCenter() - aabb.getHalfExtents(); + const cc::Vec3 maxA = getCenter() + getHalfExtents(); + const cc::Vec3 maxB = aabb.getCenter() + aabb.getHalfExtents(); cc::Vec3 maxP; cc::Vec3 minP; cc::Vec3::max(maxA, maxB, &maxP); cc::Vec3::min(minA, minB, &minP); - cc::Vec3 addP = maxP + minP; - cc::Vec3 subP = maxP - minP; + const cc::Vec3 addP = maxP + minP; + const cc::Vec3 subP = maxP - minP; setCenter(addP * 0.5F); setHalfExtents(subP * 0.5F); } +void AABB::merge(const cc::Vec3& point) { + cc::Vec3 minPos = getCenter() - getHalfExtents(); + cc::Vec3 maxPos = getCenter() + getHalfExtents(); + if (point.x < minPos.x) { + minPos.x = point.x; + } + if (point.y < minPos.y) { + minPos.y = point.y; + } + if (point.z < minPos.z) { + minPos.z = point.z; + } + if (point.x > maxPos.x) { + maxPos.x = point.x; + } + if (point.y > maxPos.y) { + maxPos.y = point.y; + } + if (point.z > maxPos.z) { + maxPos.z = point.z; + } + + const Vec3 center = (minPos + maxPos) * 0.5F; + setCenter(center); + setHalfExtents(maxPos.x - center.x, maxPos.y - center.y, maxPos.z - center.z); +} + +void AABB::merge(const Frustum& frustum) { + const std::array &vertices = frustum.vertices; + for (uint i = 0; i < vertices.max_size(); ++i) { + merge(vertices[i]); + } +} + void AABB::set(const cc::Vec3 ¢erVal, const cc::Vec3 &halfExtentVal) { setCenter(centerVal); setHalfExtents(halfExtentVal); diff --git a/native/cocos/scene/AABB.h b/native/cocos/scene/AABB.h index f2c73b8ed4..a306cee299 100644 --- a/native/cocos/scene/AABB.h +++ b/native/cocos/scene/AABB.h @@ -55,6 +55,8 @@ public: int aabbPlane(const Plane &) const; void getBoundary(cc::Vec3 *minPos, cc::Vec3 *maxPos) const; void merge(const AABB &aabb); + void merge(const cc::Vec3 &point); + void merge(const Frustum &frustum); void set(const cc::Vec3 ¢erVal, const cc::Vec3 &halfExtentVal); void transform(const Mat4 &m, AABB *out) const; inline void setCenter(float x, float y, float z) { _aabbLayout->center.set(x, y, z); } diff --git a/native/cocos/scene/Camera.h b/native/cocos/scene/Camera.h index b1c59fd148..5a86a087fb 100644 --- a/native/cocos/scene/Camera.h +++ b/native/cocos/scene/Camera.h @@ -44,8 +44,10 @@ struct Camera final { uint32_t width{0}; uint32_t height{0}; uint32_t clearFlag{0}; - float exposure{0}; - float clearDepth{0}; + float exposure{0.0F}; + float clearDepth{0.0F}; + float fov{0.0F}; + float aspect{0.0F}; Vec4 viewPort; uint32_t clearStencil{0}; uint32_t visibility{0}; diff --git a/native/cocos/scene/Define.h b/native/cocos/scene/Define.h index e57c4f2462..719921d24e 100644 --- a/native/cocos/scene/Define.h +++ b/native/cocos/scene/Define.h @@ -69,8 +69,10 @@ struct Shadow { bool enabled{false}; bool dirty{false}; bool shadowMapDirty{false}; - bool autoAdapt{false}; + bool fixedArea{false}; ShadowType shadowType{ShadowType::PLANAR}; + float invisibleOcclusionRange{0.0F}; + float shadowDistance{0.0F}; float distance{0.0F}; Pass * instancePass{nullptr}; Pass * planarPass{nullptr}; diff --git a/native/cocos/scene/Frustum.cpp b/native/cocos/scene/Frustum.cpp index a296496694..29d19a1fa1 100644 --- a/native/cocos/scene/Frustum.cpp +++ b/native/cocos/scene/Frustum.cpp @@ -39,6 +39,85 @@ const std::vector VEC_VALS{ {-1, -1, -1}, {1, -1, -1}}; } // namespace + +// Define from 3 vertices. +void Plane::define(const Vec3 &v0, const Vec3 &v1, const Vec3 &v2) { + const Vec3 dist1 = v1 - v0; + const Vec3 dist2 = v2 - v0; + + Vec3 dist; + Vec3::crossProduct(dist1, dist2, &dist); + define(dist, v0); +} + +// Define from a normal vector and a point on the plane. +void Plane::define(const Vec3 &normal, const Vec3 &point) { + n = normal.getNormalized(); + d = -normal.dot(point); +} + +// Return signed distance to a point. +float Plane::distance(const Vec3 &point) const { + return n.dot(point) + d; +} + +Plane Plane::clone() const { + Plane plane; + plane.n.set(n); + plane.d = d; + + return plane; +} + +void Frustum::createOrtho(const float width, const float height, const float near, const float far, const Mat4& transform) { + const float halfWidth = width * 0.5F; + const float halfHeight = height * 0.5F; + + vertices[0].transformMat4( Vec3(halfWidth, halfHeight, near), transform); + vertices[1].transformMat4(Vec3(-halfWidth, halfHeight, near), transform); + vertices[2].transformMat4(Vec3(-halfWidth, -halfHeight, near), transform); + vertices[3].transformMat4(Vec3(halfWidth, -halfHeight, near), transform); + vertices[4].transformMat4(Vec3(halfWidth, halfHeight, far), transform); + vertices[5].transformMat4(Vec3(-halfWidth, halfHeight, far), transform); + vertices[6].transformMat4(Vec3(-halfWidth, -halfHeight, far), transform); + vertices[7].transformMat4(Vec3(halfWidth, -halfHeight, far), transform); + + updatePlanes(); +} + +void Frustum::split(float start, float end, float aspect, float fov, const Mat4& transform) { + const float h = tanf(fov * 0.5F); + const float w = h * aspect; + const Vec3 nearTemp(start * w, start * h, start); + const Vec3 farTemp(end * w, end * h, end); + + vertices[0].transformMat4(Vec3(nearTemp.x, nearTemp.y, nearTemp.z), transform); + vertices[1].transformMat4(Vec3(-nearTemp.x, nearTemp.y, nearTemp.z), transform); + vertices[2].transformMat4(Vec3(-nearTemp.x, -nearTemp.y, nearTemp.z), transform); + vertices[3].transformMat4(Vec3(nearTemp.x, -nearTemp.y, nearTemp.z), transform); + vertices[4].transformMat4(Vec3(farTemp.x, farTemp.y, farTemp.z), transform); + vertices[5].transformMat4(Vec3(-farTemp.x, farTemp.y, farTemp.z), transform); + vertices[6].transformMat4(Vec3(-farTemp.x, -farTemp.y, farTemp.z), transform); + vertices[7].transformMat4(Vec3(farTemp.x, -farTemp.y, farTemp.z), transform); + + updatePlanes(); +} + +void Frustum::updatePlanes() { + // left plane + planes[0].define(vertices[1], vertices[5], vertices[6]); + // right plane + planes[1].define(vertices[3], vertices[7], vertices[4]); + // bottom plane + planes[2].define(vertices[6], vertices[7], vertices[3]); + // top plane + planes[3].define(vertices[0], vertices[4], vertices[5]); + // near plane + planes[4].define(vertices[2], vertices[3], vertices[0]); + // far plane + planes[5].define(vertices[7], vertices[6], vertices[5]); +} + void Frustum::update(const Mat4 &m, const Mat4 &inv) { // left plane planes[0].n.set(m.m[3] + m.m[0], m.m[7] + m.m[4], m.m[11] + m.m[8]); @@ -74,5 +153,32 @@ void Frustum::update(const Mat4 &m, const Mat4 &inv) { i++; } } + +Frustum Frustum::clone() { + Frustum frustum; + for (uint i = 0; i < planes.size(); ++i) { + frustum.planes[i] = planes[i].clone(); + } + + frustum.type = type; + + for (uint i = 0; i < vertices.size(); ++i) { + frustum.vertices[i].set(vertices[i]); + } + + return frustum; +} + +void Frustum::transform(const Mat4 &transform) { + vertices[0].transformMat4(vertices[0], transform); + vertices[1].transformMat4(vertices[1], transform); + vertices[2].transformMat4(vertices[2], transform); + vertices[3].transformMat4(vertices[3], transform); + vertices[4].transformMat4(vertices[4], transform); + vertices[5].transformMat4(vertices[5], transform); + vertices[6].transformMat4(vertices[6], transform); + vertices[7].transformMat4(vertices[7], transform); +} + } // namespace scene } // namespace cc \ No newline at end of file diff --git a/native/cocos/scene/Frustum.h b/native/cocos/scene/Frustum.h index f0a057c749..7c99541a7c 100644 --- a/native/cocos/scene/Frustum.h +++ b/native/cocos/scene/Frustum.h @@ -42,16 +42,28 @@ enum class ShapeEnums { SHAPE_FRUSTUM_ACCURATE = (1 << 8), SHAPE_CAPSULE = (1 << 9), }; + struct Plane final { float d{0.F}; Vec3 n; + + void define(const Vec3 &v0, const Vec3 &v1, const Vec3 &v2); + void define(const Vec3 &normal, const Vec3 &point); + float distance(const Vec3 &point) const; + Plane clone() const; }; struct Frustum final { std::array vertices; std::array planes; - void update(const Mat4 &m, const Mat4 &inv); - ShapeEnums type{ShapeEnums::SHAPE_FRUSTUM}; + + void createOrtho(float width, float height, float near, float far, const Mat4 &transform); + void split(float start, float end, float aspect, float fov, const Mat4 &transform); + void updatePlanes(); + void update(const Mat4 &m, const Mat4 &inv); + Frustum clone(); + void transform(const Mat4 &transform); + ShapeEnums type{ShapeEnums::SHAPE_FRUSTUM}; }; } // namespace scene diff --git a/native/cocos/scene/Sphere.cpp b/native/cocos/scene/Sphere.cpp index 1b88f7d5d4..057826022c 100644 --- a/native/cocos/scene/Sphere.cpp +++ b/native/cocos/scene/Sphere.cpp @@ -23,8 +23,9 @@ THE SOFTWARE. ****************************************************************************/ -#include "scene/Sphere.h" #include +#include "scene/Sphere.h" +#include "base/TypeDef.h" namespace cc { namespace scene { @@ -52,18 +53,16 @@ bool Sphere::interset(const Frustum &frustum) const { [self](const Plane &plane) { return self->interset(plane) != -1; }); } -void Sphere::mergePoint(const Vec3 &point) { +void Sphere::merge(const Vec3 &point) { if (_radius < 0.0F) { _center = point; _radius = 0.0F; return; } - auto offset = point - _center; - auto distance = offset.length(); - - if (distance > _radius) { - auto half = (distance - _radius) * 0.5F; + Vec3 offset = point - _center; + if (const float distance = offset.length(); distance > _radius) { + const float half = (distance - _radius) * 0.5F; _radius += half; offset.scale(half / distance); _center += offset; @@ -88,12 +87,12 @@ void Sphere::define(const AABB &aabb) { _center += (half / dist) * offset; } -void Sphere::mergeAABB(const AABB *aabb) { +void Sphere::merge(const AABB *aabb) { cc::Vec3 minPos; cc::Vec3 maxPos; aabb->getBoundary(&minPos, &maxPos); - mergePoint(minPos); - mergePoint(maxPos); + merge(minPos); + merge(maxPos); } int Sphere::spherePlane(const Plane &plane) { @@ -108,7 +107,7 @@ int Sphere::spherePlane(const Plane &plane) { return 1; } -bool Sphere::sphereFrustum(const Frustum &frustum) { +bool Sphere::sphereFrustum(const Frustum &frustum) const { const auto &planes = frustum.planes; const auto *self = this; return std::all_of(planes.begin(), @@ -117,5 +116,12 @@ bool Sphere::sphereFrustum(const Frustum &frustum) { [self](const Plane &plane) { return self->interset(plane) != -1; }); } +void Sphere::merge(const Frustum &frustum) { + const std::array &vertices = frustum.vertices; + for (uint i = 0; i < vertices.max_size(); ++i) { + merge(vertices[i]); + } +} + } // namespace scene } // namespace cc diff --git a/native/cocos/scene/Sphere.h b/native/cocos/scene/Sphere.h index 645934bf78..5b45e6c501 100644 --- a/native/cocos/scene/Sphere.h +++ b/native/cocos/scene/Sphere.h @@ -47,15 +47,16 @@ public: inline void setRadius(float val) { _radius = val; } void define(const AABB &aabb); - void mergeAABB(const AABB *aabb); - void mergePoint(const Vec3 &point); + void merge(const AABB *aabb); + void merge(const Vec3 &point); bool interset(const Frustum &frustum) const; int interset(const Plane &plane) const; int spherePlane(const Plane &plane); - bool sphereFrustum(const Frustum &frustum); + bool sphereFrustum(const Frustum &frustum) const; + void merge(const Frustum &frustum); private: - float _radius{0}; + float _radius{-1.0F}; Vec3 _center; }; diff --git a/native/templates/windows/AppDelegate.cpp b/native/templates/windows/AppDelegate.cpp index 84029ef03b..96ff1da834 100644 --- a/native/templates/windows/AppDelegate.cpp +++ b/native/templates/windows/AppDelegate.cpp @@ -1,68 +1,75 @@ #include "AppDelegate.h" +// clang-format off #include #include #include #include +// clang-format on +#include "cocos/bindings/jswrapper/SeApi.h" #include "platform/StdC.h" #include "platform/win32/View-win32.h" -#include "cocos/bindings/jswrapper/SeApi.h" namespace { - std::weak_ptr gView; - /** +std::weak_ptr gView; +/** @brief This function changes the PVRFrame show/hide setting in register. @param bEnable If true show the PVRFrame window, otherwise hide. */ - void PVRFrameEnableControlWindow(bool bEnable) { - HKEY hKey = 0; +void PVRFrameEnableControlWindow(bool bEnable) { + HKEY hKey = 0; - // Open PVRFrame control key, if not exist create it. - if (ERROR_SUCCESS != RegCreateKeyExW(HKEY_CURRENT_USER, - L"Software\\Imagination Technologies\\PVRVFRame\\STARTUP\\", - 0, - 0, - REG_OPTION_NON_VOLATILE, - KEY_ALL_ACCESS, - 0, - &hKey, - nullptr)) { - return; - } - - const WCHAR* wszValue = L"hide_gui"; - const WCHAR* wszNewData = (bEnable) ? L"NO" : L"YES"; - WCHAR wszOldData[256] = {0}; - DWORD dwSize = sizeof(wszOldData); - LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, nullptr, (LPBYTE)wszOldData, &dwSize); - if (ERROR_FILE_NOT_FOUND == status // the key not exist - || (ERROR_SUCCESS == status // or the hide_gui value is exist - && 0 != wcscmp(wszNewData, wszOldData))) // but new data and old data not equal - { - dwSize = sizeof(WCHAR) * (wcslen(wszNewData) + 1); - RegSetValueEx(hKey, wszValue, 0, REG_SZ, (const BYTE*)wszNewData, dwSize); - } - - RegCloseKey(hKey); + // Open PVRFrame control key, if not exist create it. + if (ERROR_SUCCESS != RegCreateKeyExW(HKEY_CURRENT_USER, + L"Software\\Imagination Technologies\\PVRVFRame\\STARTUP\\", + 0, + 0, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + 0, + &hKey, + nullptr)) { + return; } - bool setCanvasCallback(se::Object* global) { - std::stringstream ss; - se::ScriptEngine* se = se::ScriptEngine::getInstance(); - auto view = gView.lock(); - auto handler = view->getWindowHandler(); - auto viewSize = view->getViewSize(); - char commandBuf[200] = {0}; - ss << "window.innerWidth = " << viewSize[0] << "; " - << "window.innerHeight = " << viewSize[1] << "; " - << "window.windowHandler = " - << reinterpret_cast(handler) - << ";"; - - se->evalString(ss.str().c_str()); - return true; + const WCHAR* wszValue = L"hide_gui"; + const WCHAR* wszNewData = (bEnable) ? L"NO" : L"YES"; + WCHAR wszOldData[256] = {0}; + DWORD dwSize = sizeof(wszOldData); + LSTATUS status = RegQueryValueExW(hKey, wszValue, 0, nullptr, (LPBYTE)wszOldData, &dwSize); + if (ERROR_FILE_NOT_FOUND == status // the key not exist + || (ERROR_SUCCESS == status // or the hide_gui value is exist + && 0 != wcscmp(wszNewData, wszOldData))) // but new data and old data not equal + { + dwSize = sizeof(WCHAR) * (wcslen(wszNewData) + 1); + RegSetValueEx(hKey, wszValue, 0, REG_SZ, (const BYTE*)wszNewData, dwSize); } + + RegCloseKey(hKey); +} + +bool setCanvasCallback(se::Object* global) { + std::stringstream ss; + se::ScriptEngine* se = se::ScriptEngine::getInstance(); + auto view = gView.lock(); + auto handler = view->getWindowHandler(); + auto viewSize = view->getViewSize(); + { + auto windowPtr = reinterpret_cast(handler); + ss << "window.innerWidth = " << viewSize[0] << "; "; + ss << "window.innerHeight = " << viewSize[1] << "; "; + ss << "window.windowHandler = "; + if constexpr (sizeof(windowPtr) == 8) { // use bigint + ss << static_cast(windowPtr) << "n;"; + } + if constexpr (sizeof(windowPtr) == 4) { + ss << static_cast(windowPtr) << ";"; + } + } + se->evalString(ss.str().c_str()); + return true; +} } // namespace //exported function diff --git a/native/tests/unit-test/.gitignore b/native/tests/unit-test/.gitignore new file mode 100644 index 0000000000..5c24e5ccc3 --- /dev/null +++ b/native/tests/unit-test/.gitignore @@ -0,0 +1,2 @@ +build/ +build* \ No newline at end of file diff --git a/native/utils/generate_compile_commands_android.sh b/native/utils/generate_compile_commands_android.sh index aad9e5b7a1..9d06175ee5 100755 --- a/native/utils/generate_compile_commands_android.sh +++ b/native/utils/generate_compile_commands_android.sh @@ -27,6 +27,7 @@ cmake -Sbuild -Bbuild -DCC_USE_GLES2=ON -DCC_USE_VULKAN=ON -DCC_USE_GLES3=ON \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DCMAKE_TOOLCHAIN_FILE="$ndk_path/build/cmake/android.toolchain.cmake" \ -DANDROID_PLATFORM=android-21 \ + -DCMAKE_BUILD_TYPE=Debug \ -G "$GENERATER" $MAKE_BIN cp build/compile_commands.json . \ No newline at end of file