-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Gizmos Billboards #14995
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
lynn-lumen
wants to merge
13
commits into
bevyengine:main
Choose a base branch
from
lynn-lumen:billboards
base: main
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
Gizmos Billboards #14995
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f2ae662
Move line gizmos to its own module
lynn-lumen 7d518a7
Add billboard gizmo storage
lynn-lumen 3a3c221
Add billboard shader
lynn-lumen d973775
Add billboard gizmos
lynn-lumen 8dc1693
Mionr fixes
lynn-lumen 55bdac9
Fix shader
lynn-lumen 8c35979
Add billboard 2d
lynn-lumen f8902b1
Fix doc tests
lynn-lumen 59e6310
Remove double configuration of sets
lynn-lumen 683aaef
Fix format
lynn-lumen 39cb226
Fix format
lynn-lumen ab516e4
Merge branch 'main' into billboards
lynn-lumen 43f4ca9
Fix ambiguities pls :)
lynn-lumen 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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// TODO use common view binding | ||
#import bevy_render::view::View | ||
|
||
@group(0) @binding(0) var<uniform> view: View; | ||
|
||
|
||
struct BillboardGizmoUniform { | ||
size: f32, | ||
depth_bias: f32, | ||
#ifdef SIXTEEN_BYTE_ALIGNMENT | ||
// WebGL2 structs must be 16 byte aligned. | ||
_padding: vec2<f32>, | ||
#endif | ||
} | ||
|
||
@group(1) @binding(0) var<uniform> billboard_gizmo: BillboardGizmoUniform; | ||
|
||
struct VertexInput { | ||
@location(0) position: vec3<f32>, | ||
@location(1) color: vec4<f32>, | ||
@builtin(vertex_index) index: u32, | ||
}; | ||
|
||
struct VertexOutput { | ||
@builtin(position) clip_position: vec4<f32>, | ||
@location(0) color: vec4<f32>, | ||
}; | ||
|
||
const EPSILON: f32 = 4.88e-04; | ||
|
||
@vertex | ||
fn vertex(vertex: VertexInput) -> VertexOutput { | ||
var positions = array<vec2<f32>, 6>( | ||
vec2(-0.5, -0.5), | ||
vec2(-0.5, 0.5), | ||
vec2(0.5, 0.5), | ||
vec2(-0.5, -0.5), | ||
vec2(0.5, 0.5), | ||
vec2(0.5, -0.5) | ||
); | ||
var offset = positions[vertex.index]; | ||
|
||
let center_clip = view.clip_from_world * vec4(vertex.position, 1.0); | ||
|
||
let resolution = view.viewport.zw; | ||
let screen_center = resolution * (0.5 * center_clip.xy / center_clip.w + 0.5); | ||
|
||
var color = vertex.color; | ||
var billboard_size = billboard_gizmo.size; | ||
#ifdef PERSPECTIVE | ||
billboard_size /= center_clip.w; | ||
#endif | ||
if billboard_size < 1. { | ||
color.a *= billboard_size; | ||
billboard_size = 1.; | ||
} | ||
|
||
let screen = screen_center + offset * billboard_size; | ||
|
||
var depth: f32; | ||
if billboard_gizmo.depth_bias >= 0. { | ||
depth = center_clip.z * (1. - billboard_gizmo.depth_bias); | ||
} else { | ||
// depth * (center_clip.w / depth)^-depth_bias. So that when -depth_bias is 1.0, this is equal to center_clip.w | ||
// and when equal to 0.0, it is exactly equal to depth. | ||
// the epsilon is here to prevent the depth from exceeding center_clip.w when -depth_bias = 1.0 | ||
// center_clip.w represents the near plane in homogeneous clip space in bevy, having a depth | ||
// of this value means nothing can be in front of this | ||
// The reason this uses an exponential function is that it makes it much easier for the | ||
// user to chose a value that is convenient for them | ||
depth = center_clip.z * exp2(-billboard_gizmo.depth_bias * log2(center_clip.w / center_clip.z - EPSILON)); | ||
} | ||
|
||
var clip_position = vec4(center_clip.w * ((2. * screen) / resolution - 1.), depth, center_clip.w); | ||
|
||
var result: VertexOutput; | ||
result.clip_position = clip_position; | ||
result.color = color; | ||
return result; | ||
} | ||
|
||
struct FragmentOutput { | ||
@location(0) color: vec4<f32>, | ||
}; | ||
|
||
@fragment | ||
fn fragment(in: VertexOutput) -> FragmentOutput { | ||
return FragmentOutput(in.color); | ||
} |
Oops, something went wrong.
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.
please format this shader fn
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'm not really sure what you mean. In terms of formatting it looks like the
lines.wgsl
shader to me.