mirror of
https://github.com/bevyengine/bevy
synced 2025-01-21 09:34:29 +00:00
70a592f31a
# Objective Keep up to date with wgpu. ## Solution Update the wgpu version. Currently blocked on naga_oil updating to naga 0.14 and releasing a new version. 3d scenes (or maybe any scene with lighting?) currently don't render anything due to ``` error: naga_oil bug, please file a report: composer failed to build a valid header: Type [2] '' is invalid = Capability Capabilities(CUBE_ARRAY_TEXTURES) is required ``` I'm not sure what should be passed in for `wgpu::InstanceFlags`, or if we want to make the gles3minorversion configurable (might be useful for debugging?) Currently blocked on https://github.com/bevyengine/naga_oil/pull/63, and https://github.com/gfx-rs/wgpu/issues/4569 to be fixed upstream in wgpu first. ## Known issues Amd+windows+vulkan has issues with texture_binding_arrays (see the image [here](https://github.com/bevyengine/bevy/pull/10266#issuecomment-1819946278)), but that'll be fixed in the next wgpu/naga version, and you can just use dx12 as a workaround for now (Amd+linux mesa+vulkan texture_binding_arrays are fixed though). --- ## Changelog Updated wgpu to 0.18, naga to 0.14.2, and naga_oil to 0.11. - Windows desktop GL should now be less painful as it no longer requires Angle. - You can now toggle shader validation and debug information for debug and release builds using `WgpuSettings.instance_flags` and [InstanceFlags](https://docs.rs/wgpu/0.18.0/wgpu/struct.InstanceFlags.html) ## Migration Guide - `RenderPassDescriptor` `color_attachments` (as well as `RenderPassColorAttachment`, and `RenderPassDepthStencilAttachment`) now use `StoreOp::Store` or `StoreOp::Discard` instead of a `boolean` to declare whether or not they should be stored. - `RenderPassDescriptor` now have `timestamp_writes` and `occlusion_query_set` fields. These can safely be set to `None`. - `ComputePassDescriptor` now have a `timestamp_writes` field. This can be set to `None` for now. - See the [wgpu changelog](https://github.com/gfx-rs/wgpu/blob/trunk/CHANGELOG.md#v0180-2023-10-25) for additional details
69 lines
2.8 KiB
WebGPU Shading Language
69 lines
2.8 KiB
WebGPU Shading Language
#define_import_path bevy_pbr::utils
|
|
#import bevy_pbr::rgb9e5
|
|
|
|
const PI: f32 = 3.141592653589793;
|
|
const HALF_PI: f32 = 1.57079632679;
|
|
const E: f32 = 2.718281828459045;
|
|
|
|
fn hsv2rgb(hue: f32, saturation: f32, value: f32) -> vec3<f32> {
|
|
let rgb = clamp(
|
|
abs(
|
|
((hue * 6.0 + vec3<f32>(0.0, 4.0, 2.0)) % 6.0) - 3.0
|
|
) - 1.0,
|
|
vec3<f32>(0.0),
|
|
vec3<f32>(1.0)
|
|
);
|
|
|
|
return value * mix(vec3<f32>(1.0), rgb, vec3<f32>(saturation));
|
|
}
|
|
|
|
fn random1D(s: f32) -> f32 {
|
|
return fract(sin(s * 12.9898) * 43758.5453123);
|
|
}
|
|
|
|
// returns the (0-1, 0-1) position within the given viewport for the current buffer coords .
|
|
// buffer coords can be obtained from `@builtin(position).xy`.
|
|
// the view uniform struct contains the current camera viewport in `view.viewport`.
|
|
// topleft = 0,0
|
|
fn coords_to_viewport_uv(position: vec2<f32>, viewport: vec4<f32>) -> vec2<f32> {
|
|
return (position - viewport.xy) / viewport.zw;
|
|
}
|
|
|
|
// https://jcgt.org/published/0003/02/01/paper.pdf
|
|
|
|
// For encoding normals or unit direction vectors as octahedral coordinates.
|
|
fn octahedral_encode(v: vec3<f32>) -> vec2<f32> {
|
|
var n = v / (abs(v.x) + abs(v.y) + abs(v.z));
|
|
let octahedral_wrap = (1.0 - abs(n.yx)) * select(vec2(-1.0), vec2(1.0), n.xy > vec2f(0.0));
|
|
let n_xy = select(octahedral_wrap, n.xy, n.z >= 0.0);
|
|
return n_xy * 0.5 + 0.5;
|
|
}
|
|
|
|
// For decoding normals or unit direction vectors from octahedral coordinates.
|
|
fn octahedral_decode(v: vec2<f32>) -> vec3<f32> {
|
|
let f = v * 2.0 - 1.0;
|
|
var n = vec3(f.xy, 1.0 - abs(f.x) - abs(f.y));
|
|
let t = saturate(-n.z);
|
|
let w = select(vec2(t), vec2(-t), n.xy >= vec2(0.0));
|
|
n = vec3(n.xy + w, n.z);
|
|
return normalize(n);
|
|
}
|
|
|
|
// https://blog.demofox.org/2022/01/01/interleaved-gradient-noise-a-different-kind-of-low-discrepancy-sequence
|
|
fn interleaved_gradient_noise(pixel_coordinates: vec2<f32>, frame: u32) -> f32 {
|
|
let xy = pixel_coordinates + 5.588238 * f32(frame % 64u);
|
|
return fract(52.9829189 * fract(0.06711056 * xy.x + 0.00583715 * xy.y));
|
|
}
|
|
|
|
// https://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare (slides 120-135)
|
|
// TODO: Use an array here instead of a bunch of constants, once arrays work properly under DX12.
|
|
// NOTE: The names have a final underscore to avoid the following error:
|
|
// `Composable module identifiers must not require substitution according to naga writeback rules`
|
|
const SPIRAL_OFFSET_0_ = vec2<f32>(-0.7071, 0.7071);
|
|
const SPIRAL_OFFSET_1_ = vec2<f32>(-0.0000, -0.8750);
|
|
const SPIRAL_OFFSET_2_ = vec2<f32>( 0.5303, 0.5303);
|
|
const SPIRAL_OFFSET_3_ = vec2<f32>(-0.6250, -0.0000);
|
|
const SPIRAL_OFFSET_4_ = vec2<f32>( 0.3536, -0.3536);
|
|
const SPIRAL_OFFSET_5_ = vec2<f32>(-0.0000, 0.3750);
|
|
const SPIRAL_OFFSET_6_ = vec2<f32>(-0.1768, -0.1768);
|
|
const SPIRAL_OFFSET_7_ = vec2<f32>( 0.1250, 0.0000);
|