mirror of https://github.com/sotrh/learn-wgpu
more work on hdr tutorial
parent
0bde203056
commit
67e78d9c65
@ -0,0 +1,28 @@
|
||||
@group(0)
|
||||
@binding(0)
|
||||
var src: texture_2d<f32>;
|
||||
|
||||
@group(0)
|
||||
@binding(1)
|
||||
var output: texture_storage_2d_array<rgba32float, write>;
|
||||
|
||||
|
||||
@compute
|
||||
@workgroup_size(1, 1, 1)
|
||||
fn compute_equirect_to_cubemap(
|
||||
@builtin(global_invocation_id)
|
||||
gid: vec3<u32>,
|
||||
) {
|
||||
var SIDES: array<vec3<f32>, 6> = array(
|
||||
vec3(1.0, 0.0, 0.0), // POSX
|
||||
vec3(-1.0, 0.0, 0.0), // NEGX
|
||||
vec3(0.0, 1.0, 0.0), // POSY
|
||||
vec3(0.0, -1.0, 0.0), // NEGY
|
||||
vec3(0.0, 0.0, 1.0), // POSZ
|
||||
vec3(0.0, 0.0, -1.0), // NEGZ
|
||||
);
|
||||
var side = SIDES[gid.z];
|
||||
// We use textureLoad() as textureSample() is not allowed in compute shaders
|
||||
let samp = textureLoad(src, vec2(0, 0), 0);
|
||||
textureStore(output, gid.xy, gid.z, vec4(side * 2.0 + 1.0, 1.0));
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
use tutorial13_hdr::run;
|
||||
|
||||
fn main() {
|
||||
pollster::block_on(run());
|
||||
pollster::block_on(run()).unwrap();
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
struct Camera {
|
||||
view_pos: vec4<f32>,
|
||||
view_proj: mat4x4<f32>,
|
||||
inv_view_proj: mat4x4<f32>,
|
||||
}
|
||||
@group(0) @binding(0)
|
||||
var<uniform> camera: Camera;
|
||||
|
||||
@group(1)
|
||||
@binding(0)
|
||||
var env_map: texture_cube<f32>;
|
||||
@group(1)
|
||||
@binding(1)
|
||||
var env_sampler: sampler;
|
||||
|
||||
struct VertexOutput {
|
||||
@builtin(position) clip_position: vec4<f32>,
|
||||
@location(0) view_dir: vec3<f32>,
|
||||
}
|
||||
|
||||
@vertex
|
||||
fn vs_main(
|
||||
@builtin(vertex_index) id: u32,
|
||||
) -> VertexOutput {
|
||||
let uv = vec2<f32>(vec2<u32>(
|
||||
(id << 1u) & 2u,
|
||||
id & 2u
|
||||
));
|
||||
var out: VertexOutput;
|
||||
out.clip_position = vec4(uv * 2.0 - 1.0, 1.0, 1.0);
|
||||
out.view_dir = normalize((camera.inv_view_proj * vec4(normalize(out.clip_position.xyz), 1.0)).xyz);
|
||||
return out;
|
||||
}
|
||||
|
||||
@fragment
|
||||
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||
// let sample = textureSample(env_map, env_sampler, in.view_dir);
|
||||
let sample = vec4(in.view_dir, 1.0);
|
||||
return sample;
|
||||
}
|
Loading…
Reference in New Issue