-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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 Map: Add morph normal support #11271
Changes from 1 commit
4768ca0
78b236b
bdd12d1
68d46fc
13b6a37
60729cd
21d6826
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
#ifdef FLIP_SIDED | ||
|
||
objectNormal = -objectNormal; | ||
vec3 transformedNormal = - normalMatrix * objectNormal; | ||
|
||
#else | ||
|
||
vec3 transformedNormal = normalMatrix * objectNormal; | ||
|
||
#endif | ||
|
||
vec3 transformedNormal = normalMatrix * objectNormal; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#ifdef USE_DISPLACEMENTMAP | ||
|
||
transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias ); | ||
transformed += objectNormal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias ); | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
#ifdef USE_SKINNING | ||
vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 ); | ||
|
||
vec4 mvPosition = modelViewMatrix * skinned; | ||
|
||
#else | ||
|
||
vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 ); | ||
|
||
#endif | ||
|
||
gl_Position = projectionMatrix * mvPosition; | ||
gl_Position = projectionMatrix * mvPosition; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
skinned += boneMatY * skinVertex * skinWeight.y; | ||
skinned += boneMatZ * skinVertex * skinWeight.z; | ||
skinned += boneMatW * skinVertex * skinWeight.w; | ||
skinned = bindMatrixInverse * skinned; | ||
|
||
transformed = ( bindMatrixInverse * skinned ).xyz; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Continue mutating There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are not mutating Are you able to demonstrate that the w-component you are dropping is 1? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am making the assumption that the transformations applied to The matrices in question: Is there a reason to suspect these matrices may sometimes not be affine? Edit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not if the weights are all zero, for example. Of course, they shouldn't be. You are assuming the weights are normalized. They are normalized in the constructor, so I think you are OK here. I still think doing an experiment to verify the value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, but requiring the weights to be normalized actually follows from the original assumption that the matrices are affine. If the weights don't add up to one, then In any case, I explicitly checked the weights by logging them for a bunch of Three.js examples, and they all add up to one. I checked the matrices as well and the last row for each of them is [0, 0, 0, 1], making them affine. I believe in the end this is an entirely reasonable assumption to make. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for doing the experiment and confirming this. We should be OK, then. |
||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP ) | ||
|
||
#ifdef USE_SKINNING | ||
|
||
vec4 worldPosition = modelMatrix * skinned; | ||
|
||
#else | ||
|
||
vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 ); | ||
|
||
#endif | ||
vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 ); | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,9 +40,9 @@ void main() { | |
#endif | ||
|
||
#include <begin_vertex> | ||
#include <displacementmap_vertex> | ||
#include <morphtarget_vertex> | ||
#include <skinning_vertex> | ||
#include <displacementmap_vertex> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since displacement is done along the post-transformed normal, displacement mapping needs to take place after position vertices have been transformed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be as precise as possible, you are displacing along the "morph-skinning-adjusted" normal in object space. Ignoring skinning for the moment, morph normals do not have to be specified -- they are optional. One can specify morph targets only. In that case, the "adjusted" normal is the original normal. It seems to me that in that case, displacement should be first. That would be problematic, unless you can demonstrate that order does not matter... |
||
#include <project_vertex> | ||
#include <logdepthbuf_vertex> | ||
#include <clipping_planes_vertex> | ||
|
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.
Leave
objectNormal
un-negated for future transforms (like displacement) that don't care about surface orientation.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.
I agree. I prefer this.