-
Notifications
You must be signed in to change notification settings - Fork 119
Add entry about SEMANTIC_TYPE_TEXTURE_TRANSFORM_2D #609
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
Open
Jhonnyg
wants to merge
1
commit into
master
Choose a base branch
from
semantic-type-texture-transform
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ Semantic type | |
| - `SEMANTIC_TYPE_TANGENT` Produces per-vertex tangent data for the attribute | ||
| - `SEMANTIC_TYPE_WORLD_MATRIX` Produces per-vertex world matrix data for the attribute | ||
| - `SEMANTIC_TYPE_NORMAL_MATRIX` Produces per-vertex normal matrix data for the attribute | ||
| - `SEMANTIC_TYPE_TEXTURE_TRANSFORM_2D` Produces a per-vertex 3x3 texture transform matrix for the attribute. For particle components, the engine provides a matrix that transforms coordinates into atlas space for the image property on the component. For sprite components, the engine provides a matrix for each image the component is using (when using multi-texturing). For model components, an identity matrix is provided. | ||
|
|
||
| Data type | ||
| : The data type of the backing data for the attribute. | ||
|
|
@@ -119,6 +120,7 @@ The material system will assign a default semantic type automatically based on t | |
| - `tangent` - semantic type: `SEMANTIC_TYPE_TANGENT` | ||
| - `mtx_world` - semantic type: `SEMANTIC_TYPE_WORLD_MATRIX` | ||
| - `mtx_normal` - semantic type: `SEMANTIC_TYPE_NORMAL_MATRIX` | ||
| - `mtx_texture_transform_2d` - semantic type: `SEMANTIC_TYPE_TEXTURE_TRANSFORM_2D` | ||
|
|
||
| If you have entries for these attributes in the material, the default semantic type will be overridden with whatever you have configured in the material editor. | ||
|
|
||
|
|
@@ -136,10 +138,6 @@ go.animate("#sprite", "tint", go.PLAYBACK_LOOP_PINGPONG, vmath.vector4(1,0,0,1), | |
|
|
||
| There are some caveats to updating the vertex attributes however, whether or not a component can use the value depends on the semantic type of the attribute. For example, a sprite component supports the `SEMANTIC_TYPE_POSITION` so if you update an attribute that has this semantic type, the component will ignore the overridden value since the semantic type dictates that the data should always be produced by the sprites position. | ||
|
|
||
| ::: sidenote | ||
| Setting custom vertex data in runtime is currently only supported for sprite components. | ||
| ::: | ||
|
|
||
| In cases where that a vertex attribute is either a scalar or a vector type other than a `Vec4` you can still set the data using `go.set`: | ||
|
|
||
| ```lua | ||
|
|
@@ -150,6 +148,42 @@ go.animate("#sprite", "sprite_position_2d", go.PLAYBACK_LOOP_PINGPONG, vmath.vec | |
|
|
||
| The same is true for matrix attributes, if the attribute is a matrix type other than a `Mat4` you can still set the data using `go.set`. | ||
|
|
||
| ### Examples of using custom vertex attributes | ||
|
|
||
| Using a texture transform attribute to convert UV coordinates to atlas space: | ||
|
Comment on lines
+151
to
+153
Contributor
Author
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 don't know if we want examples like this, or if we should point to an actual example instead?
Contributor
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. Better to point to an actual example if we have one! |
||
|
|
||
| ```glsl | ||
| #version 140 | ||
|
|
||
| in vec3 position; | ||
| in vec4 texcoord0; | ||
| in mat3 texture_transform_2d; | ||
|
|
||
| out vec2 var_texcoord0; | ||
|
|
||
| void main() | ||
| { | ||
| // Extract position from the transform | ||
| vec2 atlas_pos = texture_transform_2d[2].xy; | ||
| // Extract the scale from the transform | ||
| vec2 atlas_size = vec2( | ||
| length(texture_transform_2d[0].xy), | ||
| length(texture_transform_2d[1].xy) | ||
| ); | ||
| // convert to local UV (0..1) | ||
| vec2 localUV = (texcoord0 - atlas_pos) / atlas_size; | ||
|
|
||
| // Alternatively, if the UV coordinates already are in the 0..1 range, | ||
| // you can transform into atlas space directly by multiplying the transform: | ||
| vec2 transformedUv = texture_transform_2d * texcoord0; | ||
|
|
||
| // Pass the value into the fragment shader | ||
| var_texcoord0 = localUV; | ||
|
|
||
| // ... rest of vertex shader | ||
| } | ||
| ``` | ||
|
|
||
| ### Instancing | ||
|
|
||
| Instancing is a technique used to efficiently draw multiple copies of the same object in a scene. Instead of creating a separate copy of the object each time it's used, instancing allows the graphics engine to create a single object and then reuse it multiple times. For example, in a game with a large forest, instead of creating a separate tree model for each tree, instancing allows you to create one tree model and then place it hundreds or thousands of times with different positions and scales. The forest can now be rendered with a single draw call instead of individual draw calls for each tree. | ||
|
|
||
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.
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.
Not true any more!