VisualShader: Add a CoordinateSpaceHelper node and add proper mat4 * vec4
operation to TransformVecMult node
#97215
+317
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Partially implements godotengine/godot-proposals#7666.
Resolves godotengine/godot-proposals#8376.
Problem summary:
The current visual shader node TransformVecMult is trying to serve two purposes: a way to transform vectors between coordinate spaces, and also a general
vec4 * mat4
node. It's failing at both purposes:A x B (3 x 3)
, making it hard to understand if you don't already know matrix math.vec4 * mat4
multiplication correctly, since it accepts avec3
and autofills thew
component of avec4
with either1.0
or0.0
.vec4
, so you can't use thew
component of the output. (Useful for some clip space operations).Solution:
Add a new, dedicated node to transform positions and directions between model, world, view, and clip space.
vec3
. This node is only for transforming positions and directions. If you need to use thew
component of the output, use the old node.Position
andDirection
for the vector types.Adjust the old
TransformVecMult
node. It now:vec4
. If you only want avec3
, you can plug thevec4
into avec3
input or swizzle thevec4
.A x B
,B x A
,A x B (3x3)
,B x A (3x)
. These still accept avec3
input, but they now output the wholevec4
. These modes function the same as before, except for outputtingw
.A x B (Vec4)
andB x A (Vec4)
. These accept avec4
input and return avec4
output. If you want to use these modes to do the coordinate space transform, you'll need to fill in the correctw
on the input.vec3
output, plugging it into avec4
input, and assuming that thew
component is0.0
, your shader may change.New node:
From spaces:
Model to...
,World to...
,View to...
,Clip to...
To spaces:
Model
,World
,View
,Clip
Vector types:
Position
,Direction
Visual summary of the two old and new node:
View to world snippet, old and new:
TransformVecMult compatibility
Images of current compatibility
4.3: Shader that uses all four current operater modes, and connects to both
vec3
andvec4
slots:This PR: Same shader, opened with this PR. All connections are still present. The only edge case is that the
vec3
output is now connected to avec4
slot. If your shader assumed that thew
component is0.0
, it will break.If 100% compatibility is needed, there are ways to do so. We could:
vec3
andvec4
for all operator modes ofTransformVecMult
, with the only difference being thew
field. IIRC Unity did this for some of its nodes. It makes the node more cluttered, though.vec3
or avec4
, dynamically switched with another enum dropdown. Again, more clutter.vec3
. For the newvec4 * mat4
operators, output avec4
. Old operators remain exactly as they are, and the correctvec4 * mat4
operator is now available if you needw
or for other uses.CoordinateSpaceHelper
(as described in this PR) and aTransformVector4Multiply
node, which only doesvec4 * mat4
ormat4 * vec4
multiplications. TheCoordinateSpaceHelper
does artist-friendly transforms, and theTransformVector4Multiply
node matches text shader behavior (since you can't dovec3 * mat4
ormat4 * vec3
in a text shader).So we could add those two nodes, and deprecate the current node. Users of the current
TransformVecMult
should switch to eitherCoordinateSpaceHelper
for the common use case, orTransformVector4Multiply
for more any other use case.Tasks:
TransformVecMult
's operators should maybe be changed, too.