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

AO Detail Map #5270

Merged
merged 7 commits into from May 17, 2023
Merged

AO Detail Map #5270

merged 7 commits into from May 17, 2023

Conversation

Mistale
Copy link
Contributor

@Mistale Mistale commented Apr 25, 2023

Fixes #4807
Uses the concepts introduced by #1968.

PR adds the following properties to pc.StandardMaterial with documentation and tests:

  • aoDetailMap (texture)
  • aoDetailMapChannel ("r", "g", "b", "a", default is "g")
  • aoDetailMapUv (number)
  • aoDetailMapTiling (vec2)
  • aoDetailMapOffset (vec2)
  • aoDetailMode (pc.DETAILMODE_*)

When combined with a baked aoMap, this PR allows for high- and low-frequency AO to be mixed without requiring excessively large baked textures. Typical use-cases may be a fence, a car grille or similar where one might want to use a baked AO texture for the entire object, but use a tiling baked AO texture for the intricate details.

Example:

image (3)

From left to right: baked AO, baked AO + detail Normal, baked AO + detail Normal + detail AO

I confirm I have read the contributing guidelines and signed the Contributor License Agreement.

@slimbuck
Copy link
Member

slimbuck commented May 10, 2023

Hi @Mistale,

Sorry for our slow response on your PR - it's awesome, so we'll review/test/merge real soon.

Thanks!!

* @property {number} aoDetailMapRotation Controls the 2D rotation (in degrees) of the detail
* (secondary) AO map.
* @property {string} aoDetailMapChannel Color channels of the detail (secondary) AO map
* to use. Can be "r", "g", "b" or "a".
Copy link
Contributor

Choose a reason for hiding this comment

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

This should mention the default value is 'g'

Copy link
Contributor

@Maksims Maksims May 11, 2023

Choose a reason for hiding this comment

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

Is it common to use default value 'g' instead or 'r' in other similar properties?
We should avoid making assumptions of how artist should pack their channels, even as a default option while it is configurable.

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't seem to have that mentioned elsewhere in the docs, but we do set 'g' as the default channel in the material. It should be down to how textures are packed, surely, unless there is some bit depth favor for green channels (which would make sense perceptually) for certain file formats?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a clarification about the default value. I can't figure out why 'g' is the default for ao either, but I figured I'd just follow the same standard as aoMapChannel.
When packing ORM-textures for glTF, "r" is used for occlusion. But it may be related to inherent precision issues as @GSterbrant mentions.

Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

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

I'm approving this, with a small JSDocs suggestion, but would like @GSterbrant to have a look as well.

My question is regarding the aoDetailMode parameter - did you find this useful when testing, versus just using one fixed way to blend those ao maps?

@GSterbrant GSterbrant added the open source contribution Issues related to contributions from people outside the PlayCanvas team label May 12, 2023
Copy link
Contributor

@GSterbrant GSterbrant left a comment

Choose a reason for hiding this comment

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

Looks good! Just remember to update the chunk API version to 1.63 before merge.

It does spawn a conversation I think we've had before on the team which is that perhaps we should add details maps as an intrinsic engine feature instead of having to add a bunch of extra parameters manually for each texture you'd want to detail map.

src/scene/shader-lib/chunks/chunk-validation.js Outdated Show resolved Hide resolved
* @property {number} aoDetailMapRotation Controls the 2D rotation (in degrees) of the detail
* (secondary) AO map.
* @property {string} aoDetailMapChannel Color channels of the detail (secondary) AO map
* to use. Can be "r", "g", "b" or "a".
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't seem to have that mentioned elsewhere in the docs, but we do set 'g' as the default channel in the material. It should be down to how textures are packed, surely, unless there is some bit depth favor for green channels (which would make sense perceptually) for certain file formats?

@Mistale
Copy link
Contributor Author

Mistale commented May 15, 2023

I'm approving this, with a small JSDocs suggestion, but would like @GSterbrant to have a look as well.

My question is regarding the aoDetailMode parameter - did you find this useful when testing, versus just using one fixed way to blend those ao maps?

I think that using DETAILMODE_MUL as default covers a lot of normal use-cases, with one specific exception:

  • When multiplying primary and secondary AO together using mul, the results will always vary (slightly) by the pattern of the secondary map, even in areas where the primary occlusion should be dark enough to completely remove details.
    In this case a choice between DETAILMODE_MIN and DETAILMODE_MAX can make the results "flatter" while at the same time allowing the artist to introduce a bias towards the lighter or darker spectrum.

The other options are mainly there for artistic freedom.

@willeastcott
Copy link
Contributor

This now has two approvals - any objections to merging @mvaligursky and @slimbuck? Last call for comments! ⌛

@mvaligursky
Copy link
Contributor

Lets merge it in.

@mvaligursky mvaligursky merged commit f4523fc into playcanvas:main May 17, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue feature request open source contribution Issues related to contributions from people outside the PlayCanvas team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AO detail maps
6 participants