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

Displacement Effect #5573

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Conversation

defektu
Copy link
Contributor

@defektu defektu commented Aug 17, 2023

Fixes #5554

@mvaligursky requested PR from #5554 to look into it.

Known issues with PR is in issues thread.

It might be a poor implementation in terms of engine's workflow.

LitShader-forward-proc & LitShader-ShadowPass_1_0-proc does not get #define DISPLACEMENT argument possibly because of my poor implementation.

Project file in #5554 works perfectly (probably due to shader chunk rebuilds when replacing a chunk)

Did not implemented checks for implementation cause of draft PR

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

@mvaligursky
Copy link
Contributor

Would you have any way to use this? Engine example or Editor project?

@defektu
Copy link
Contributor Author

defektu commented Aug 17, 2023

Scene for changing transformVS
and engine example with use_local_engine

@mvaligursky
Copy link
Contributor

I had a quick look, and I think:

  1. you should use heightMap for this instead of introducing new texture channel. The useDisplacement would then use this map as displacement instead of for parallax.
  2. I think you need something like this to have normals attribute added to the vertex shader:
    Screenshot 2023-08-18 at 11 34 13

Give these a go please and let me know if there are further issues - there might be with supplying UVs to the vertex shader too, but maybe not with the heightMap.

@mvaligursky
Copy link
Contributor

Hi @defektu - any thoughts / progress on this? It'd be great to finish off if possible, thanks.

@defektu
Copy link
Contributor Author

defektu commented Sep 11, 2023

Sorry @mvaligursky, nowadays are a bit rough workwise.

Using heights was possible but uv's and texture is not passing through to shadowpass. (vertex's are displacing but shadow pass won't in this case.)

Shadows are rendered through Standart material shader as far as I inspected. Build process won't take the litOption arguments (like texture_shadowMap) while shadows are processing (useHeights=null). Or I might doing something wrong.

I can explore any thoughts in my spare time.

@defektu
Copy link
Contributor Author

defektu commented Sep 12, 2023

Today I noticed standart.js has // all other passes require only opacity part. So ShadowPass is not getting any info about anything except opacity.

@mvaligursky
Copy link
Contributor

Yep, we'll need to adjust this to pass on the height if used as well.

@defektu
Copy link
Contributor Author

defektu commented Sep 12, 2023

Also vertex_normals needed. But it does not pass into shadow pass as semantics as well Vertex shader attribute "vertex_normal" is not mapped to a semantic in shader definition, shader [Shader Id 2 LitShader-ShadowPass_1_0-proc]

@defektu
Copy link
Contributor Author

defektu commented Sep 12, 2023

Shaderpass does not get any litOptions (turns out to be undefined)
getShaderVariant passes this.shaderOptBuilder.updateMinRef if it is not FORWARD_PASS. So do you have any suggestions about this topic. Besides shadowPass it is working as intended (displacing the surface).
image

@mvaligursky
Copy link
Contributor

I suspect the StandardMaterialOptionsBuilder will need to be updated to generate required options in the shadow pass - probably in _updateSharedOptions, which I think is shared between forward and shadow pass, but not sure now based on you seeing litOptions being undefined.

Perhaps update the PR with what you have, using the height texture, and I'll see how I can fix the shadows using your example.

@defektu
Copy link
Contributor Author

defektu commented Sep 14, 2023

Rolled back previous changes and added mesh-displacement example draft.

@defektu
Copy link
Contributor Author

defektu commented Sep 14, 2023

Somehow I got it working with shared options. I will cleanup everything and send PR.

This change is for temporary purposes.
DISPLACEMENT definition is must (otherwise displacementVS must be created)
minimalOptions is disabled due to shaderpass definitions.
@defektu
Copy link
Contributor Author

defektu commented Sep 14, 2023

Pushed working version with minimalOptions = false. It is working as intended like this.
image

@defektu
Copy link
Contributor Author

defektu commented Sep 15, 2023

Effect fully works for now but noticed env goes blank (weird frustrum culling behaviour causes that)
Can't state if it is caused by PR or something else.

@mvaligursky
Copy link
Contributor

I fixed the culling that few days ago .. you're just probably not up to date.
Is it all ready for the review you reckon? Ping me when it is, I'll check it out, thanks!

@defektu
Copy link
Contributor Author

defektu commented Sep 15, 2023

Yes it is up and running @mvaligursky. UV transformations are not implemented. displacementOffset is nice to have and can be implemented by introducing new material attribute.

Displacement offset is introduced as material attribute.
@defektu
Copy link
Contributor Author

defektu commented Sep 15, 2023

Pushed new commit for displacementOffset too.

forgot console.log
This change is for temporary purposes.
DISPLACEMENT definition is must (otherwise displacementVS must be created)
minimalOptions is disabled due to shaderpass definitions.
@defektu
Copy link
Contributor Author

defektu commented Sep 18, 2023

There is specularityFactor. Since effect uses heightMap, displacementFactor and displacementOffset is good?

#endif
vec4 getPosition() {
dModelMatrix = getModelMatrix();

#ifdef DISPLACEMENT
vec4 dMapSample = texture2D(texture_heightMap, vertex_texCoord0.xy);
float displacer = dMapSample.r * material_heightMapFactor * 10.;
float displacer = dMapSample.r * material_heightMapFactor * 10. + material_displacementOffset;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about the *10 part here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That can be removed when material_heightMapFactor is replaced with new attribute.

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be more useful for vertex displacement to be implemented as an overridable shader chunk instead?

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 am not sure, you are the guys to call the shot.

@mvaligursky
Copy link
Contributor

There is specularityFactor. Since effect uses heightMap, displacementFactor and displacementOffset is good?

yeah actually, I missed you added an offset too. Sounds good in that case to me.

useDisplacement flag is setting from `displacementFactor !== 0`
- Fixed useDisplacement flag
- Minified mesh-displacement example
@defektu
Copy link
Contributor Author

defektu commented Sep 19, 2023

Hey @mvaligursky, Updated PR & ready for review.

Decided to keep useDisplacement attribute for code readability. It sets based on displacementFactor. Cleaned up mesh-displacement example.

I guess it is good to keep useDisplacement attribute in material parameters for debugging?

Not a code dev mainly so ignore commit chains <3

@defektu defektu marked this pull request as ready for review September 22, 2023 22:17
@defektu defektu marked this pull request as draft September 25, 2023 16:08
@defektu defektu marked this pull request as ready for review September 28, 2023 08:23
@defektu
Copy link
Contributor Author

defektu commented Sep 28, 2023

Added draft docs for attributes.

Things to consider:

  • This effect uses UV0 and R channel of height map.
  • You can't offset or transform map yet.
  • If there is no heightMap, useDisplacement will break vertex chunk.

@willeastcott
Copy link
Contributor

Hey @mvaligursky and @slimbuck - can we sync on this PR? I'm keen to make a decision on what to do with it.

@Maksims
Copy link
Contributor

Maksims commented Oct 29, 2023

Is there a way to change heightMap channel for displacement?
Also will it apply tiling and offsets?

Another question, will it be viable/common when devs use displacement in combination with parallax? In such case the heightMap textures might be different or the same?

@defektu
Copy link
Contributor Author

defektu commented Oct 31, 2023

Hi @Maksims, I think this vertex shader needs some special attributes for offsetting and tiling (which is totally possible). Concurrent options are bound to fragment shader. Don't think that back propagation is not possible unless changing where uniforms defined.

Not really experienced with engine, so this needs crosscheck.

@defektu
Copy link
Contributor Author

defektu commented Dec 16, 2023

Back from service. Ready to do changes if needed.

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.

Feature Request - Displacement Map
5 participants