Skip to content
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

Merged
merged 10 commits into from Aug 28, 2020

Conversation

troublemaker52025
Copy link
Contributor

Re: cocos-creator/2d-tasks#

Changes:
*

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Math.sqrt(2) 可以提取出来预先计算

Copy link
Contributor Author

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!);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里使用sphere,是因为球的中心不管从哪往中心点观察,都能窥视到半球
aabb的长方体中心,计算就不那么准确

* @zh
* 场景包围球
*/
public _sphere: sphere = new sphere(0.0, 0.0, 0.0, 0.01);
Copy link
Contributor

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 () {
Copy link
Contributor

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 的区域采样,我也不确定该怎么命名比较好

Copy link
Contributor Author

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吧 比较容易理解

* @property ShadowMap
* @readonly
*/
X1: 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

X1,X4 这个最好也跟 shader 中的命名统一

* @zh
* 球跟立方体合并
*/
public static mergeBox (out: sphere, s:sphere, a: aabb) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static 应该放在 public 函数之前。

这个函数也应该是 mergeAABB

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();}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这应该是 else if 吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前有语法错误 所以分开写了 现在纠正了语法错误,改成if else的分支判断了

@pandamicro pandamicro merged commit c99525c into cocos:3d-v1.2 Aug 28, 2020
@troublemaker52025 troublemaker52025 deleted the Repair-shadow-matrix branch August 28, 2020 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants