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

Feat: support spherical harmonic #392

Merged

Conversation

zhuxudong
Copy link
Member

@zhuxudong zhuxudong commented Jul 15, 2021

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Feature.

What is the current behavior? (You can also link to an open issue here)

#217 Use cubemap as diffuse reflection texture.

What is the new behavior (if this is a feature change)?

Use spherical harmonics as diffuse reflection.

Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

Yes.

  • Deleted AmbientLight.diffuseTexture
  • Added AmbientLight.diffuseSphericalHarmonics
  • Deleted DiffuseMode.Texture
  • Added DiffuseMode.SphericalHarmonics

Demo:

  const sh = new SphericalHarmonics3();
  // Generate spherical harmonics from array or baker 
  // ......
  ambientLight.diffuseMode = DiffuseMode.SphericalHarmonics;
  ambientLight.diffuseSphericalHarmonics = sh;

From Asset which includes sh array

 const array = [0.12,0.3,0.2,...]; // 27 numbers
 const sh = new SphericalHarmonics3();
 sh.setValueByArray(array)

From SH Baker

  const sh = new SphericalHarmonics3();
  SphericalHarmonics3Baker.fromTextureCubeMap(cubeMap, sh);

Export array from spherical harmonics

  const array = [];
  const sh = new SphericalHarmonics3();

  sh.toArray(array);

image

@zhuxudong zhuxudong added the enhancement New feature or request label Jul 15, 2021
@zhuxudong zhuxudong added this to the 0.5 milestone Jul 15, 2021
@zhuxudong zhuxudong requested a review from GuoLei1990 July 15, 2021 10:11
@zhuxudong zhuxudong self-assigned this Jul 15, 2021
@zhuxudong zhuxudong changed the title Feat/support spherical harmonic Feat: support spherical harmonic Jul 15, 2021
@zhuxudong zhuxudong linked an issue Jul 16, 2021 that may be closed by this pull request
@zhuxudong zhuxudong removed a link to an issue Jul 16, 2021
@GuoLei1990 GuoLei1990 requested a review from yangfengzzz August 4, 2021 03:18
packages/math/src/Color.ts Show resolved Hide resolved
packages/math/src/Color.ts Show resolved Hide resolved

return max(result, vec3(0.0));

}
Copy link
Member

Choose a reason for hiding this comment

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

You can check this :http://www.fractalforums.com/programming/shader-function-or-instruction-cost-(performance)/

How to say: many engine get irradiance use the func like this:

mediump vec3 shEvalLinearL0L1(mediump vec4 normal)
	{
		mediump vec3 x;
		// Linear (L1) + constant (L0) polynomial terms
		x.r = dot(u_AmbientSHAr, normal);
		x.g = dot(u_AmbientSHAg, normal);	
		x.b = dot(u_AmbientSHAb, normal);
		return x;
	}

	mediump vec3 shEvalLinearL2(mediump vec4 normal)
	{
		mediump vec3 x1,x2;
		// 4 of the quadratic (L2) polynomials
		mediump vec4 vB = normal.xyzz * normal.yzzx;
		x1.r = dot(u_AmbientSHBr, vB);
		x1.g = dot(u_AmbientSHBg, vB);
		x1.b = dot(u_AmbientSHBb, vB);
	
		// Final (5th) quadratic (L2) polynomial
		mediump float vC = normal.x*normal.x - normal.y*normal.y;
		x2 = u_AmbientSHC.rgb * vC;

		return x1 + x2;
	}

Because dot cost only 3 cycles in GPU, so is faster, If you do this you must do some modifies before Incoming shader.

@GuoLei1990
Copy link
Member

I create a PR:zhuxudong#4 to optimization.

Copy link
Member

@GuoLei1990 GuoLei1990 left a comment

Choose a reason for hiding this comment

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

+1

@GuoLei1990 GuoLei1990 merged commit 908a0fe into galacean:dev/0.5 Aug 6, 2021
GuoLei1990 added a commit that referenced this pull request Sep 2, 2021
* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: use new addChannel api

* style: format code

* feat: opt code

* feat: merge gltf animation parser

* feat: opt code

* fix:opt code

* refator: opt code

* refactor: opt code

* refactor: clear imports

* refactor:fix bug

* refactor: opt code

* refactor: opt code

* feat: fix tsc

* feat: opt code

* feat: opt crossfade performance

* feat: opt crossfade performance

* feat: opt crossfade

* feat: opt crossfade

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* feat: opt mergedCurveIndexList

* feat: opt mergedCurveIndexList

* feat: add revert

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* feat: opt corssfade from pose

* feat: resolve conflict from cm

* refactor: opt code

* feat: fix type

* fix: fix additive

* refactor: opt code

* refactor: opt struct of Animation Node data

* feat: fix comment

* feat: clear import

* refactor: add CM

* refactor: opt code

* refactor:  opt crossFade code

* refactor: opt code

* refactor: opt code

* refactor: opt Animator code

* refactor: opt code

* Delete package-lock.json

delete package-lock

* Merge main (#349)

* refactor: opt code

* refactor: opt code

* refactor: improve play API

* refactor: opt code

* refactor: opt code

* refactor: fix code

* refactor: opt code

* refactor: move internal class to internal folder

* refactor: remove generic

* refactor: save code

* refactor: opt code

* refactor: opt Layer update

* refactor: opt code

* refactor: reduce GC

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: remove playState

* refactor: solve CM

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: add layer opt

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt interface design

* refactor: opt code

* refactor: opt code

* refactor: clear imports

* Animator (#337)

* refactor: refactor animator #35

* refactor: sprite material add define USE_MODEL_MATRIX (#359)

* refactor(2d): sprite material add define USE_MODEL_MATRIX

* feat: add animator-event

* feat: add animator-event

* feat: opt event code

* feat: add animator-event

* feat: opt code

* feat: merge oasis dev/0,5

* feat: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: clear imports

* feat: add some commonly used methods for `Color`(#385)

* test: add color test (#391)

Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>

* feat: opt code

* feat: opt code

* feat: opt code

* feat: opt code

* feat: opt code

* feat: opt code

* feat: opt code

* feat: opt code

* refactor: opt code

* refactor: opt code

* Animator event (#372)

* feat: add AnimatorEvent system #35

* Dev/0.5 (#397)

* fix: fix Animator bug

* Dev/0.5 (#399)

* fix: fix Animator bug

* Blend shape animation (#374)

* feat: add BlendShape Animation

* feat: add ObjectKeyframe for  AnimationCurve (#403)

* Refactor physics Ray-cast and Collision detection (#404)

* feat: add trigger methods into Script and rewrite CollisionDetection

* Update README.md

* Fix Typos (#409)

* fix: typos fixed

* Add sprite atlas region offset (#407)

* feat: add ObjectKeyframe

* refactor: opt code

* refactor: opt code

* refactor: improve  comments

* Fix Typos (#410)

* fix: fix typos

* feat:Support atlas #197 (#402)

* feat:Support atlas #197

Co-authored-by: azhan <zhanyingwei.zyw@antgroup.com>
Co-authored-by: GuoLei1990 <gl3336563@163.com>

* refactor: add tips for developers when use draco and BlendShape at the same time (#414)

* refactor: new pbr interface (#418)

* refactor: new pbr interface

* Feat: support spherical harmonic (#392)

* feat: support spherical harmonics

* fix:opt atlas code. (#420)

* fix:opt atlas code

* fix: glTF vertexData parser error (#423)

* fix: set interpolation with `linear` by default (#424)

* fix: set interpolation with `linear` by default
Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>

* Fix material clone (#426)

* fix: fix material clone bug

* fix:atlas support rotation (#428)

* fix:atlas support rotation

* ci: compile error (#429)

Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>

* fix: `ModleMesh` destroy bug (#430)

* Fix the comments of RenderState (#431)

* fix: the comments of `RasterState`

* feat: add sh in editor (#433)

* Add Scene Background Texture (#427)

* feat: add scene background texture

* Background texture (#434)

* refactor: opt code

* Test/material (#422)

* feat: add material test

* v0.5.0-alpha.0

* Test: test for math (#437)

* test: add test for math library

* fix:Fixed sprite’s rect display error when packaged into an atlas and trimmed (#435)

* fix:Fixed sprite’s rect display error when packaged into an atlas and trimmed

* Fix BlendShape bug (#441)

* fix: `ModleMesh` memory access bug

* Add blendshape test  (#442)

* refactor: add `Blendshape` test

* Fix blend shape add frame (#445)

* refactor: fix  addFrame() of BlendShape

* Test for Background (#438)

* test: test for background

* Fix Background Texture Error (#446)

* refactor: fix background texture bug

* v0.5.1-alpha.0

* v0.5.2-alpha.0

* v0.5.3-alpha.0

* fix: temp fix type convert function (#449)

* v0.5.3-0.5.0-alpha.1.0

* v0.5.3-alpha.0

* v0.5.3-alpha.1

* feat: support vertex color for Blinnphone (#450)

* feat: support vertex color for Blinnphone

* fix: BlendShape  access bug (#451)

* feat:Add the function of relative path loading. (#439)

* feat:Add the function of relative path loading

* fix: fix 2d renderer order error (#452)

* fix: 2d renderer order error opt code

* feat: adapt to editor

* feat: adapt to editor

* feat: adapt to editor

* feat: adapt to editor

* feat: adapt to editor

* feat: adapt to editor

* refactor: opt animator

* v0.5.3-alpha.2

* refactor: opt code

* feat: update

* refactor: opt code

* fix: gltf no animation bug

* refactor: opt code

* refactor: oopt code

* refactor: opt code

* refactor: opt code

* feat: opt animator editor

* feat: opt animator editor

* fix: revert PHYSICALLY_CORRECT_LIGHTS

* fix: revert PHYSICALLY_CORRECT_LIGHTS (#455)

* v0.5.3-alpha.3

* refactor: revert gamma space

* refactor: revert gamma space (#457)

* v0.5.3-alpha.4

* Fix Caluculation Error in Background Size (#458)


* refactor: fix background calculation

* feat: opt animator editor

* fix: bugfix

* Animator editor (#454)

* fix: bugfix

* v0.5.3-alpha.5

* v0.5.3-alpha.6

* feat: remove log

* feat: remove log

* Animator editor (#463)

* refactor: remove log

* fix: check valid if sh is null (#464)

Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>

* v0.5.3-alpha.7

* feat: add more interface for raycast (#462)

* feat: add more interface for raycast

* feat:SpriteAtlas Adaptation Editor Workflow (#461)

* feat:SpriteAtlas Adaptation Editor Workflow

* feat: 上传编辑器clip数据改为引用

* fix: bugfix

* v0.5.3-alpha.8

* fix: code err (#467)

* fix: ccompile err

* v0.5.3-y.0

* v0.5.3-alpha.8

* v0.5.3-alpha.9

* fix(2d): spine texture uniform (#468)

* v0.5.3-alpha.10

* fix(2d): fix mask uniform (#471)

* fix: bugfix (#470)

* v0.5.3-alpha.11

* Merge main to dev/0.5 (#472)

* fix: ModelMesh destroy bug (#473)

* fix: `ModelMesh` destroy() bug

* v0.5.3-alpha.12

* v0.5.0

Co-authored-by: luzhuang <364439895@qq.com>
Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>
Co-authored-by: singlecoder <z18511751272@gmail.com>
Co-authored-by: zhuxudong <callzhuxudong@163.com>
Co-authored-by: yangfengzzz <yangfengzzz@hotmail.com>
Co-authored-by: AZhan <njktsmshh@163.com>
Co-authored-by: azhan <zhanyingwei.zyw@antgroup.com>
Co-authored-by: Hu Song <gz65555@gmail.com>
Co-authored-by: Izzy Chen <czizzy@163.com>
Co-authored-by: singlecoder <singlecoder2014@gmail.com>
luzhuang pushed a commit to luzhuang/engine that referenced this pull request Sep 6, 2022
* feat: support spherical harmonics
luzhuang added a commit to luzhuang/engine that referenced this pull request Sep 6, 2022
* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: use new addChannel api

* style: format code

* feat: opt code

* feat: merge gltf animation parser

* feat: opt code

* fix:opt code

* refator: opt code

* refactor: opt code

* refactor: clear imports

* refactor:fix bug

* refactor: opt code

* refactor: opt code

* feat: fix tsc

* feat: opt code

* feat: opt crossfade performance

* feat: opt crossfade performance

* feat: opt crossfade

* feat: opt crossfade

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* feat: opt mergedCurveIndexList

* feat: opt mergedCurveIndexList

* feat: add revert

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* feat: opt corssfade from pose

* feat: resolve conflict from cm

* refactor: opt code

* feat: fix type

* fix: fix additive

* refactor: opt code

* refactor: opt struct of Animation Node data

* feat: fix comment

* feat: clear import

* refactor: add CM

* refactor: opt code

* refactor:  opt crossFade code

* refactor: opt code

* refactor: opt code

* refactor: opt Animator code

* refactor: opt code

* Delete package-lock.json

delete package-lock

* Merge main (galacean#349)

* refactor: opt code

* refactor: opt code

* refactor: improve play API

* refactor: opt code

* refactor: opt code

* refactor: fix code

* refactor: opt code

* refactor: move internal class to internal folder

* refactor: remove generic

* refactor: save code

* refactor: opt code

* refactor: opt Layer update

* refactor: opt code

* refactor: reduce GC

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: remove playState

* refactor: solve CM

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: add layer opt

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt interface design

* refactor: opt code

* refactor: opt code

* refactor: clear imports

* Animator (galacean#337)

* refactor: refactor animator #35

* refactor: sprite material add define USE_MODEL_MATRIX (galacean#359)

* refactor(2d): sprite material add define USE_MODEL_MATRIX

* feat: add animator-event

* feat: add animator-event

* feat: opt event code

* feat: add animator-event

* feat: opt code

* feat: merge oasis dev/0,5

* feat: opt code

* refactor: opt code

* refactor: opt code

* refactor: opt code

* refactor: clear imports

* feat: add some commonly used methods for `Color`(galacean#385)

* test: add color test (galacean#391)

Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>

* feat: opt code

* feat: opt code

* feat: opt code

* feat: opt code

* feat: opt code

* feat: opt code

* feat: opt code

* feat: opt code

* refactor: opt code

* refactor: opt code

* Animator event (galacean#372)

* feat: add AnimatorEvent system #35

* Dev/0.5 (galacean#397)

* fix: fix Animator bug

* Dev/0.5 (galacean#399)

* fix: fix Animator bug

* Blend shape animation (galacean#374)

* feat: add BlendShape Animation

* feat: add ObjectKeyframe for  AnimationCurve (galacean#403)

* Refactor physics Ray-cast and Collision detection (galacean#404)

* feat: add trigger methods into Script and rewrite CollisionDetection

* Update README.md

* Fix Typos (galacean#409)

* fix: typos fixed

* Add sprite atlas region offset (galacean#407)

* feat: add ObjectKeyframe

* refactor: opt code

* refactor: opt code

* refactor: improve  comments

* Fix Typos (galacean#410)

* fix: fix typos

* feat:Support atlas galacean#197 (galacean#402)

* feat:Support atlas galacean#197

Co-authored-by: azhan <zhanyingwei.zyw@antgroup.com>
Co-authored-by: GuoLei1990 <gl3336563@163.com>

* refactor: add tips for developers when use draco and BlendShape at the same time (galacean#414)

* refactor: new pbr interface (galacean#418)

* refactor: new pbr interface

* Feat: support spherical harmonic (galacean#392)

* feat: support spherical harmonics

* fix:opt atlas code. (galacean#420)

* fix:opt atlas code

* fix: glTF vertexData parser error (galacean#423)

* fix: set interpolation with `linear` by default (galacean#424)

* fix: set interpolation with `linear` by default
Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>

* Fix material clone (galacean#426)

* fix: fix material clone bug

* fix:atlas support rotation (galacean#428)

* fix:atlas support rotation

* ci: compile error (galacean#429)

Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>

* fix: `ModleMesh` destroy bug (galacean#430)

* Fix the comments of RenderState (galacean#431)

* fix: the comments of `RasterState`

* feat: add sh in editor (galacean#433)

* Add Scene Background Texture (galacean#427)

* feat: add scene background texture

* Background texture (galacean#434)

* refactor: opt code

* Test/material (galacean#422)

* feat: add material test

* v0.5.0-alpha.0

* Test: test for math (galacean#437)

* test: add test for math library

* fix:Fixed sprite’s rect display error when packaged into an atlas and trimmed (galacean#435)

* fix:Fixed sprite’s rect display error when packaged into an atlas and trimmed

* Fix BlendShape bug (galacean#441)

* fix: `ModleMesh` memory access bug

* Add blendshape test  (galacean#442)

* refactor: add `Blendshape` test

* Fix blend shape add frame (galacean#445)

* refactor: fix  addFrame() of BlendShape

* Test for Background (galacean#438)

* test: test for background

* Fix Background Texture Error (galacean#446)

* refactor: fix background texture bug

* v0.5.1-alpha.0

* v0.5.2-alpha.0

* v0.5.3-alpha.0

* fix: temp fix type convert function (galacean#449)

* v0.5.3-0.5.0-alpha.1.0

* v0.5.3-alpha.0

* v0.5.3-alpha.1

* feat: support vertex color for Blinnphone (galacean#450)

* feat: support vertex color for Blinnphone

* fix: BlendShape  access bug (galacean#451)

* feat:Add the function of relative path loading. (galacean#439)

* feat:Add the function of relative path loading

* fix: fix 2d renderer order error (galacean#452)

* fix: 2d renderer order error opt code

* feat: adapt to editor

* feat: adapt to editor

* feat: adapt to editor

* feat: adapt to editor

* feat: adapt to editor

* feat: adapt to editor

* refactor: opt animator

* v0.5.3-alpha.2

* refactor: opt code

* feat: update

* refactor: opt code

* fix: gltf no animation bug

* refactor: opt code

* refactor: oopt code

* refactor: opt code

* refactor: opt code

* feat: opt animator editor

* feat: opt animator editor

* fix: revert PHYSICALLY_CORRECT_LIGHTS

* fix: revert PHYSICALLY_CORRECT_LIGHTS (galacean#455)

* v0.5.3-alpha.3

* refactor: revert gamma space

* refactor: revert gamma space (galacean#457)

* v0.5.3-alpha.4

* Fix Caluculation Error in Background Size (galacean#458)


* refactor: fix background calculation

* feat: opt animator editor

* fix: bugfix

* Animator editor (galacean#454)

* fix: bugfix

* v0.5.3-alpha.5

* v0.5.3-alpha.6

* feat: remove log

* feat: remove log

* Animator editor (galacean#463)

* refactor: remove log

* fix: check valid if sh is null (galacean#464)

Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>

* v0.5.3-alpha.7

* feat: add more interface for raycast (galacean#462)

* feat: add more interface for raycast

* feat:SpriteAtlas Adaptation Editor Workflow (galacean#461)

* feat:SpriteAtlas Adaptation Editor Workflow

* feat: 上传编辑器clip数据改为引用

* fix: bugfix

* v0.5.3-alpha.8

* fix: code err (galacean#467)

* fix: ccompile err

* v0.5.3-y.0

* v0.5.3-alpha.8

* v0.5.3-alpha.9

* fix(2d): spine texture uniform (galacean#468)

* v0.5.3-alpha.10

* fix(2d): fix mask uniform (galacean#471)

* fix: bugfix (galacean#470)

* v0.5.3-alpha.11

* Merge main to dev/0.5 (galacean#472)

* fix: ModelMesh destroy bug (galacean#473)

* fix: `ModelMesh` destroy() bug

* v0.5.3-alpha.12

* v0.5.0

Co-authored-by: luzhuang <364439895@qq.com>
Co-authored-by: shensi.zxd <shensi.zxd@alibaba-inc.com>
Co-authored-by: singlecoder <z18511751272@gmail.com>
Co-authored-by: zhuxudong <callzhuxudong@163.com>
Co-authored-by: yangfengzzz <yangfengzzz@hotmail.com>
Co-authored-by: AZhan <njktsmshh@163.com>
Co-authored-by: azhan <zhanyingwei.zyw@antgroup.com>
Co-authored-by: Hu Song <gz65555@gmail.com>
Co-authored-by: Izzy Chen <czizzy@163.com>
Co-authored-by: singlecoder <singlecoder2014@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants