目前经过反复测试。基本上已经定位到了。当节点非常多的时候。即使节点移除和加入都吃cpu。尤其在苹果上只能30帧。那怎么优化这种节点移除和加入父节点性能差的问题。操作节点显示隐藏?有其他方案吗
7 个帖 - 3 位参与者
目前经过反复测试。基本上已经定位到了。当节点非常多的时候。即使节点移除和加入都吃cpu。尤其在苹果上只能30帧。那怎么优化这种节点移除和加入父节点性能差的问题。操作节点显示隐藏?有其他方案吗
7 个帖 - 3 位参与者
2个1.0.5版本,其实一个是v2,一个是v3,只有下载下来之后,你才知道结果,用户体验很一般,能用但不好用,能优化最好。
1 个帖 - 1 位参与者
游戏开发中,我们可能只想把一个界面里的图文进行合图,那么基于节点的动态合图你可能用的上。比如设置界面、商店界面,你只需在该界面的根节点挂上脚本,那么该界面上的所有可合图的图文都会打到一张图集里。
1.支持对特定节点下图文动态合图,通常适用于单个界面,仅让该节点下图文合图,销毁该界面即销毁图集。
2.单个动态合图支持修改高宽,节省内存。
1.在项目脚本中的最外层,加上NodeDynaAtlasMgr.init(),不要写在onLoad/start等类函数中。
2.在需要合图的界面根节点,挂载上NodeDynaAtlasRoot.ts脚本。设置图集大小,例如2048、1024、512。
dc1.背景图
dc2.中间图文按钮动态合图,1024x1024
dc3.弹窗界面动态合图,512x512
dc4.Cocos自带FPS
注意:该源码替换了原有的动态合图,只有挂载了NodeDynaAtlasRoot.ts脚本的节点及其子节点才会触发合图;
链接:Cocos Store
4 个帖 - 2 位参与者
2 个帖 - 2 位参与者
偶现问题。
渲染的时候会突然出现【不是业务需要渲染的】奇形怪状的mesh,直接导致花屏。
但是在相同环境下无法复现,app重启之后就变成正常情况。
有可能是因为createmesh的时候pos或者index的问题但是没办法确定。
想问下有什么可以log的方式或者定位方式。
2 个帖 - 1 位参与者
如图,一个空白3.8.4项目,android发布后的帧耗时如下(设备OnePlus IN2010):
默认设为60fps 屏幕显示为60fps,frame time为 7-9ms
game.frameRate=55 屏幕显示为57fps,frame time为 2-4ms
game.frameRate=50 屏幕显示为52fps,frame time为 2-4ms
视频中帧率变化是手动修改cc.game.frameRate导致的,方便看效果
想了解的是:
1、空白项目帧耗时7-9毫秒是否正常?
2、为什么帧频设置60会明显导致 frame time变高? 按理说每帧计算/渲染的内容是一样的,帧频为何会影响耗时?
4 个帖 - 2 位参与者
版本cocos creator 3.8.4
在ios的浏览器上滚动特别卡 android浏览器也是一样的
帧率稳定在60帧
draw call 40~50
在论坛找了下
1、有些贴说的是滚动时候位置的精度导致的
2、有些贴说是渲染分离 不同步导致的
有大佬能给个解决方案么
7 个帖 - 3 位参与者
在编辑器中运行后。 如果在代码中修改了场景中物体的属性, 比如:动态创建一个RenderTexture,设置到Main Camera 和 targetTexture上,但编辑器中 Camera 上设置中, 并没有变化 。 在控制台中可以看到确实是正常的设置上了。 只是编辑器的参数面板 没有正常的刷新。 请问这个需要如何处理呢?
正常设置上了。
1 个帖 - 1 位参与者
1、可通过组件方式,添加战争迷雾。
2、迷雾分为纯黑绘制与资源图擦除两种形式。
3、迷雾的边缘虚化曲线和渐变虚提供参数设置。
价格与细节面议,本人是技术兼制作人,有意向的,欢迎直接与我沟通
wx:10578417
qq:277186604
1 个帖 - 1 位参与者
先上预览地址:cocos-godray-dist
源码地址:cocos-godray
PS. 如果一开始是黑的,那就用鼠标转一下
做独立项目的时候,boss说海底好看啊,blingbling的,我说我懂,焦散+体积光嘛,于是找个了简单的纹理加上UV动画当作焦散效果,但是体积光又怎么办呢?用面片加UV动画太low,干脆用 Cocos Creator 3.8 做个基于屏幕空间的体积光吧!(头发,out!)
网上有很多大佬都讲解过了,比如:
基于后处理光线步进的体积光的实现
先做个技术验证,在sketchfab找个好看的模型:
点赞下载解压一气呵成(我这里下载的是原格式),加个 license 感谢作者大大:
"Forest House" (https://skfb.ly/6QSKT) by peachyroyalty is licensed under Creative Commons Attribution-NonCommercial (http://creativecommons.org/licenses/by-nc/4.0/).
模型导入cocos 以后,材质不对劲!好端端的贴图全都叛变了:
看了下原模型和贴图,其实用不受光材质就可以,于是这里把effect改成不受光材质,然后手动把所有的贴图全部重新拖上去:
全部操作完以后,我们会发现像树木这种贴图中带有透明像素的显示不正确,把ALPHA_TEST勾选上就好啦
在Cocos中获取深度图是个论坛上很多人在问的问题,大部分老版本的思路就是自己写一个深度材质,配置一个深度专用的layer,再用一个专门的相机去渲染一次场景;在3.8的自定义管线出现以后,可以通过自己增加一个Pass来获取深度图。
我想了一下,我需要在场景中获取两张深度图,一个是通过屏幕坐标用来反算世界坐标的,一个是用来作为shadowMap用来计算阴影的,干脆就用老方法(才不是因为自定义管线很困难)来获取深度图,新建一个layer叫做DEPTH,新建一个深度材质,加上对应的相机,再加两个render-texture,咔咔一顿操作,两张深度图就有了。
这里需要注意的是,由于我们在制作材质时,有的材质勾选了USE ALPHA TEST
,所以我们的深度材质也要把透明度的判断逻辑加上,然后在复制场景的时候,把之前老的材质的贴图给复制过去:
// 复制场景,添加深度材质,然后复制贴图
private _setScene() {
this._clone = instantiate(this.scene);
setLayer(this._clone, DEPTH_LAYER);
this.scene.parent.addChild(this._clone);
this._clone
.getComponentsInChildren(Renderer)
?.forEach((renderer) => {
const mat = renderer.getSharedMaterial(0);
const tex = mat.getProperty("mainTexture") as Texture2D;
renderer.setMaterialInstance(this.depthMaterial, 0);
renderer.getMaterialInstance(0).setProperty("mainTexture", tex);
});
}
对应的shader代码:
vec4 depth_8bits () {
vec4 texColor = texture(mainTexture, v_uv);
if (texColor.a < 1.0) discard;
float depth = v_screenPos.z / v_screenPos.w * 0.5 + 0.5;
vec4 col = vec4(depth, depth, depth, 1.0);
return CCFragOutput(col);
}
深度图获取到了,接下来就是计算阴影
吃饭去了先,有空继续
2 个帖 - 2 位参与者
cocos 2.4.10 加载阿里云oss图片
ERROR 4930 中低端安卓手机就会出现 苹果14pro 没问题 可以正常加载 这是什么原因?
1 个帖 - 1 位参与者
半年多以前有个图片指定颜色变色的需求,因为不熟悉shader相关知识只能在网上找,当时用AI写的完全不能用,要么是直接报错要么就是和需求不搭边,然后通过谷歌、百度、github、论坛也没找到符合需求的,最后只能向技美朋友求助帮忙解决了,虽然需求并不复杂但是对于没有相关知识基础的人来说真是两眼一抹黑。
今天突然又想起之前的这个需求,结果用AI调教了几句就得到了符合需求的shader。这还是cocos相关的问题,对于unity和ue的匹配支持度估计更高…回头想想从ChatGPT发布到现在不过两年而已,发展速度真是日新月异。
下面提供下AI写的变色shader,tolerance为颜色匹配的容差值。
CCEffect %{
techniques:
- passes:
- vert: sprite-vs:vert
frag: sprite-fs:frag
depthStencilState:
depthTest: false
depthWrite: false
blendState:
targets:
- blend: true
blendSrc: src_alpha
blendDst: one_minus_src_alpha
blendSrcAlpha: src_alpha
blendDstAlpha: one_minus_src_alpha
rasterizerState:
cullMode: none
properties:
alphaThreshold: { value: 0.5 }
targetColor: { value: [1.0, 0.0, 0.0, 1.0], editor: { type: color } }
replaceColor: { value: [0.0, 1.0, 0.0, 1.0], editor: { type: color } }
tolerance: {
value: 0.1,
editor: {
type: float,
range: [0, 1.0],
step: 0.001,
slide: true
}
}
}%
CCProgram sprite-vs %{
precision highp float;
#include <cc-global>
#if USE_LOCAL
#include <cc-local>
#endif
in vec3 a_position;
in vec2 a_texCoord;
in vec4 a_color;
out vec2 v_uv;
out vec4 v_color;
vec4 vert () {
vec4 pos = vec4(a_position, 1);
#if USE_LOCAL
pos = cc_matWorld * pos;
#endif
#if USE_PIXEL_ALIGNMENT
pos = cc_matView * pos;
pos.xyz = floor(pos.xyz);
pos = cc_matProj * pos;
#else
pos = cc_matViewProj * pos;
#endif
v_uv = a_texCoord;
v_color = a_color;
return pos;
}
}%
CCProgram sprite-fs %{
precision highp float;
#include <embedded-alpha>
#include <alpha-test>
in vec2 v_uv;
in vec4 v_color;
#pragma builtin(local)
layout(set = 2, binding = 11) uniform sampler2D cc_spriteTexture;
uniform Constant {
vec4 targetColor;
vec4 replaceColor;
float tolerance;
};
vec4 frag () {
vec4 o = texture(cc_spriteTexture, v_uv);
o *= v_color;
// 只在不透明的地方进行颜色替换
if (o.a > 0.0) {
float diff = length(o.rgb - targetColor.rgb);
if (diff < tolerance) {
float lerpFactor = 1.0 - (diff / tolerance);
o.rgb = mix(o.rgb, replaceColor.rgb, lerpFactor);
}
}
ALPHA_TEST(o);
return o;
}
}%
效果图
3 个帖 - 2 位参与者
1、第一种是类似web的span布局,竖线左边的文字(服务端动态渲染的文本,不是写死)多了,竖线右边的字会自适应,往右边移动位置
2、第二种是类似web的 ul li 布局,外层 div 的宽度是固定宽,第一个 li 文字占据(服务端动态渲染的文本)空间多了,下一个 li 的开始位置会自适应
因为cocos 好像是得用 node 和 label这样的组件去搭页面,不存在行内元素和块元素的概念,大家一般都是怎么 实现这样 的布局的呢?求指导下思路 。
我个人的想法是js 代码硬控,就是下一个 li (node/label) 生成之前,先判断上一个li 所占据的真实高度,然后再开始定下一个 li 的 position的初始位置,但是好像很蠢的样子。。。。
2 个帖 - 2 位参与者
勾勾、选选就完事,WebEasyObfus 混淆項目代码就这样简单。
「走過路過,別錯過,點顆星星,支持我!」
下载项目成 ZIP 文件。
解压后将内容复制到 ${your_project_path}/extensions/web-easy-obfus
。
打开终端
输入 cd ${your_project_path}/extensions/web-zip-bundle
安装扩展依赖包 npm install
构建扩展 npm run build
到 Editor 菜单 Extension -> Extension Manager -> Installed 启用 web-easy-obfus
。
到 Build Setting 新增 New Build Task 并选择平台 WebMobile/WebDesktop。到 Panel 中下拉找到 web-easy-obfus 选项。
Enable:启用或关闭功能。
${your_project_path}/build/web-mobile/assets/main/index.js
进行混淆。Select Obfus Level:混淆分为五个等级,等级越高,混淆程度越彻底,但文件体积会增大,执行性能可能略受影响。
基础 (Minimal),對 javascript-obfuscator 設定分別為:
{
// Minifies the output code to reduce file size.
"compact": true,
// Disables converting code into a more complex control flow structure.
"controlFlowFlattening": false,
// Disables adding redundant dead code blocks.
"deadCodeInjection": false,
// Keeps global variable names unchanged.
"renameGlobals": false,
// Avoids extracting strings into a separate array for simplicity.
"stringArray": false
}
标准 (Standard),對 javascript-obfuscator 設定分別為:
{
// Minifies the output code to reduce file size.
"compact": true,
// Enables control flow flattening for added complexity.
"controlFlowFlattening": true,
// Applies control flow flattening to 75% of the code.
"controlFlowFlatteningThreshold": 0.75,
// Avoids injecting unnecessary dead code.
"deadCodeInjection": false,
// Moves strings into a separate array for obfuscation.
"stringArray": true,
// Applies string array obfuscation to 75% of strings.
"stringArrayThreshold": 0.75
}
增强 (Enhanced),對 javascript-obfuscator 設定分別為:
{
// Minifies the output code to reduce file size.
"compact": true,
// Enables control flow flattening for added complexity.
"controlFlowFlattening": true,
// Applies control flow flattening to 90% of the code.
"controlFlowFlatteningThreshold": 0.9,
// Adds dead code to make reverse engineering harder.
"deadCodeInjection": true,
// Inserts dead code in 40% of places.
"deadCodeInjectionThreshold": 0.4,
// Keeps global variable names unchanged for compatibility.
"renameGlobals": false,
// Moves strings into a separate array for obfuscation.
"stringArray": true,
// Encodes strings in the array using Base64.
"stringArrayEncoding": ["base64"],
// Applies string array obfuscation to 90% of strings.
"stringArrayThreshold": 0.9,
// Obfuscates object keys for added security.
"transformObjectKeys": true
}
安全 (Secure),對 javascript-obfuscator 設定分別為:
{
// Minifies the output code to reduce file size.
"compact": true,
// Enables control flow flattening for added complexity.
"controlFlowFlattening": true,
// Applies control flow flattening to all code.
"controlFlowFlatteningThreshold": 1,
// Adds dead code to make reverse engineering harder.
"deadCodeInjection": true,
// Inserts dead code in 50% of places.
"deadCodeInjectionThreshold": 0.5,
// Renames global variables for better obfuscation.
"renameGlobals": true,
// Moves strings into a separate array for obfuscation.
"stringArray": true,
// Encodes strings in the array using RC4 encryption.
"stringArrayEncoding": ["rc4"],
// Applies string array obfuscation to all strings.
"stringArrayThreshold": 1,
// Obfuscates object keys for added security.
"transformObjectKeys": true
}
极致 (Ultimate),對 javascript-obfuscator 設定分別為:
{
// Minifies the output code to reduce file size.
"compact": true,
// Enables control flow flattening for added complexity.
"controlFlowFlattening": true,
// Applies control flow flattening to all code.
"controlFlowFlatteningThreshold": 1,
// Adds dead code to make reverse engineering harder.
"deadCodeInjection": true,
// Inserts dead code in all possible places.
"deadCodeInjectionThreshold": 1,
// Renames global variables for better obfuscation.
"renameGlobals": true,
// Moves strings into a separate array for obfuscation.
"stringArray": true,
// Encodes strings using both Base64 and RC4 encryption.
"stringArrayEncoding": ["base64", "rc4"],
// Applies string array obfuscation to all strings.
"stringArrayThreshold": 1,
// Obfuscates object keys for added security.
"transformObjectKeys": true,
// Converts characters to Unicode escape sequences for obfuscation.
"unicodeEscapeSequence": true,
// Replaces console output calls with empty functions to hide debugging messages.
"disableConsoleOutput": true
}
本插件天然支持 CI/CD,只需從 Build Panel 导出当前平台的构建选项配置为 json 文件,用于命令行构建。
2 个帖 - 2 位参与者
1 个帖 - 1 位参与者
在cocos底层貌似是使用rollup、babel来打包ts代码的。
想请教一下目前能否自定义打包工具或者修改打包的流程?
例如,换用esbuild、swc等,或者给rollup增加一些plugin,来加速打包或实现一些特殊的需求
找了文档、论坛等很多地方没有找到方法
1 个帖 - 1 位参与者