New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repair shadow matrix for 3d-v1.2 #7223
Repair shadow matrix for 3d-v1.2 #7223
Conversation
cocos/core/renderer/scene/shadows.ts
Outdated
@@ -190,6 +198,16 @@ export class Shadows { | |||
} | |||
} | |||
|
|||
public getWorldMatrix (rotation: Quat, dir: Vec3) { | |||
Vec3.negate(_dir_negate, dir); | |||
Vec3.multiplyScalar(_vec3_p, _dir_negate, Math.sqrt(2) * this._sphere.radius); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Math.sqrt(2)
可以提取出来预先计算
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以提出来,我也写明了含义
@@ -84,6 +87,7 @@ export function sceneCulling (pipeline: ForwardPipeline, view: RenderView) { | |||
// shadow render Object | |||
if (model.castShadow) { | |||
model.updateUBOs(stamp); | |||
sphere.mergeBox(shadowSphere, shadowSphere, model.worldBounds!); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里使用sphere,是因为球的中心不管从哪往中心点观察,都能窥视到半球
aabb的长方体中心,计算就不那么准确
cocos/core/renderer/scene/shadows.ts
Outdated
* @zh | ||
* 场景包围球 | ||
*/ | ||
public _sphere: sphere = new sphere(0.0, 0.0, 0.0, 0.01); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private _sphere
然后添加一个 getSphere 或别的
else return vec4(0); | ||
} | ||
|
||
vec4 CCGetShadowFactorCommon () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easy Common Hard 命名不够清晰,另外,Easy 你使用的是 X 型采样,不是 pcf 标准的 NxN 采样,hard 用的是 3x3 的区域采样,我也不确定该怎么命名比较好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
查了一下根据显卡的性能而定 2x2倍采样确实是X型采样,3x3倍采样时九宫格,最后是5x5倍采样,我看到的文章基本上到5x5就截止了
https://zhuanlan.zhihu.com/p/61460686 --X型采样
https://zhuanlan.zhihu.com/p/26853641 --PCF滤波
shader命名的话 结尾加上NxN吧 比较容易理解
cocos/core/renderer/scene/shadows.ts
Outdated
* @property ShadowMap | ||
* @readonly | ||
*/ | ||
X1: 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
X1,X4 这个最好也跟 shader 中的命名统一
cocos/core/geometry/sphere.ts
Outdated
* @zh | ||
* 球跟立方体合并 | ||
*/ | ||
public static mergeBox (out: sphere, s:sphere, a: aabb) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static 应该放在 public 函数之前。
这个函数也应该是 mergeAABB
…w-matrix # Conflicts: # cocos/core/pipeline/forward/scene-culling.ts
vec4 shadow = vec4(1.0); | ||
float pcf = cc_shadowPCF.x + 0.001; | ||
if (pcf > 2.0) {shadow = CCGetShadowFactorX9();} | ||
if (2.0 > pcf && pcf > 1.0) {shadow = CCGetShadowFactorX5();} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这应该是 else if 吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前有语法错误 所以分开写了 现在纠正了语法错误,改成if else的分支判断了
Re: cocos-creator/2d-tasks#
Changes:
*