From a6eac3f81fffb1f7063f802464100348c19ce409 Mon Sep 17 00:00:00 2001 From: Matthieu Baumann Date: Fri, 12 Mar 2021 13:51:06 +0100 Subject: [PATCH] 10 bits per channel rgb --- src/core/src/renderable/ray_tracer.rs | 23 ++++++++++--------- .../src/shaders/hips/raytracer/color.frag | 5 ++-- .../hips/raytracer/grayscale_to_color.frag | 5 ++-- .../hips/raytracer/grayscale_to_color_i.frag | 5 ++-- .../hips/raytracer/grayscale_to_colormap.frag | 5 ++-- .../raytracer/grayscale_to_colormap_i.frag | 5 ++-- 6 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/core/src/renderable/ray_tracer.rs b/src/core/src/renderable/ray_tracer.rs index fc48f76a..b36f6231 100644 --- a/src/core/src/renderable/ray_tracer.rs +++ b/src/core/src/renderable/ray_tracer.rs @@ -75,7 +75,7 @@ use web_sys::{Request, RequestInit, RequestMode, Response}; use wasm_bindgen::JsValue; use std::mem; use crate::renderable::projection::Aitoff; -fn generate_position() -> Vec { +fn generate_position() -> Vec { let (w, h) = (2048.0, 2048.0); let mut data = vec![]; for y in 0..(h as u32) { @@ -87,14 +87,15 @@ fn generate_position() -> Vec { true, ) { let pos = pos.truncate().normalize(); + let mut d: u32 = 0; + d |= 3 << 30; + d |= (((pos.z * 0.5 + 0.5) * (1024.0 as f64)) as u32) << 20; + d |= (((pos.y * 0.5 + 0.5) * (1024.0 as f64)) as u32) << 10; + d |= ((pos.x * 0.5 + 0.5) * (1024.0 as f64)) as u32; - data.push(((pos.x * 0.5 + 0.5) * (std::u16::MAX as f64)) as u16); - data.push(((pos.y * 0.5 + 0.5) * (std::u16::MAX as f64)) as u16); - data.push(((pos.z * 0.5 + 0.5) * (std::u16::MAX as f64)) as u16); + data.push(d); } else { - data.push(std::u16::MAX); - data.push(std::u16::MAX); - data.push(std::u16::MAX); + data.push(!0); } } } @@ -210,12 +211,12 @@ impl RayTracer { WebGl2RenderingContext::CLAMP_TO_EDGE, ), ], - WebGl2RenderingContext::RGB16UI as i32, // internal format - WebGl2RenderingContext::RGB_INTEGER, // format - WebGl2RenderingContext::UNSIGNED_SHORT, // type + WebGl2RenderingContext::RGB10_A2 as i32, // internal format + WebGl2RenderingContext::RGBA, // format + WebGl2RenderingContext::UNSIGNED_INT_2_10_10_10_REV, // type ).unwrap(); - let buf_data = unsafe { js_sys::Uint16Array::view(&data) }; + let buf_data = unsafe { js_sys::Uint32Array::view(&data) }; position_tex .bind() .tex_sub_image_2d_with_i32_and_i32_and_u32_and_type_and_opt_array_buffer_view(0, 0, 2048, 2048, Some(&buf_data)); diff --git a/src/core/src/shaders/hips/raytracer/color.frag b/src/core/src/shaders/hips/raytracer/color.frag index e3e29597..b7975ceb 100644 --- a/src/core/src/shaders/hips/raytracer/color.frag +++ b/src/core/src/shaders/hips/raytracer/color.frag @@ -59,12 +59,11 @@ TileColor get_tile_color(vec3 pos) { const float duration = 500.f; // 500ms uniform int max_depth; // max depth of the HiPS -uniform usampler2D position_tex; +uniform sampler2D position_tex; uniform mat4 model; void main() { vec2 uv = out_clip_pos * 0.5 + 0.5; - uvec3 o = texture(position_tex, uv).rgb; - vec3 n = vec3(float(o.x)/65535.0, float(o.y)/65535.0, float(o.z)/65535.0) * 2.0 - 1.0; + vec3 n = texture(position_tex, uv).rgb * 2.0 - 1.0; vec3 frag_pos = vec3(model * vec4(n, 1.0)); diff --git a/src/core/src/shaders/hips/raytracer/grayscale_to_color.frag b/src/core/src/shaders/hips/raytracer/grayscale_to_color.frag index df700a50..3d0d6d5c 100644 --- a/src/core/src/shaders/hips/raytracer/grayscale_to_color.frag +++ b/src/core/src/shaders/hips/raytracer/grayscale_to_color.frag @@ -56,12 +56,11 @@ TileColor get_tile_color(vec3 pos) { const float duration = 500.f; // 500ms uniform int max_depth; // max depth of the HiPS -uniform usampler2D position_tex; +uniform sampler2D position_tex; uniform mat4 model; void main() { vec2 uv = out_clip_pos * 0.5 + 0.5; - uvec3 o = texture(position_tex, uv).rgb; - vec3 n = vec3(float(o.x)/65535.0, float(o.y)/65535.0, float(o.z)/65535.0) * 2.0 - 1.0; + vec3 n = texture(position_tex, uv).rgb * 2.0 - 1.0; vec3 frag_pos = vec3(model * vec4(n, 1.0)); diff --git a/src/core/src/shaders/hips/raytracer/grayscale_to_color_i.frag b/src/core/src/shaders/hips/raytracer/grayscale_to_color_i.frag index 7ca62a31..7bc83ed8 100644 --- a/src/core/src/shaders/hips/raytracer/grayscale_to_color_i.frag +++ b/src/core/src/shaders/hips/raytracer/grayscale_to_color_i.frag @@ -56,12 +56,11 @@ TileColor get_tile_color(vec3 pos) { const float duration = 500.f; // 500ms uniform int max_depth; // max depth of the HiPS -uniform usampler2D position_tex; +uniform sampler2D position_tex; uniform mat4 model; void main() { vec2 uv = out_clip_pos * 0.5 + 0.5; - uvec3 o = texture(position_tex, uv).rgb; - vec3 n = vec3(float(o.x)/65535.0, float(o.y)/65535.0, float(o.z)/65535.0) * 2.0 - 1.0; + vec3 n = texture(position_tex, uv).rgb * 2.0 - 1.0; vec3 frag_pos = vec3(model * vec4(n, 1.0)); diff --git a/src/core/src/shaders/hips/raytracer/grayscale_to_colormap.frag b/src/core/src/shaders/hips/raytracer/grayscale_to_colormap.frag index 6f54cd0e..44332a9e 100644 --- a/src/core/src/shaders/hips/raytracer/grayscale_to_colormap.frag +++ b/src/core/src/shaders/hips/raytracer/grayscale_to_colormap.frag @@ -56,12 +56,11 @@ TileColor get_tile_color(vec3 pos) { const float duration = 500.f; // 500ms uniform int max_depth; // max depth of the HiPS -uniform usampler2D position_tex; +uniform sampler2D position_tex; uniform mat4 model; void main() { vec2 uv = out_clip_pos * 0.5 + 0.5; - uvec3 o = texture(position_tex, uv).rgb; - vec3 n = vec3(float(o.x)/65535.0, float(o.y)/65535.0, float(o.z)/65535.0) * 2.0 - 1.0; + vec3 n = texture(position_tex, uv).rgb * 2.0 - 1.0; vec3 frag_pos = vec3(model * vec4(n, 1.0)); diff --git a/src/core/src/shaders/hips/raytracer/grayscale_to_colormap_i.frag b/src/core/src/shaders/hips/raytracer/grayscale_to_colormap_i.frag index 8aa50602..9c15397d 100644 --- a/src/core/src/shaders/hips/raytracer/grayscale_to_colormap_i.frag +++ b/src/core/src/shaders/hips/raytracer/grayscale_to_colormap_i.frag @@ -57,12 +57,11 @@ TileColor get_tile_color(vec3 pos) { const float duration = 500.f; // 500ms uniform int max_depth; // max depth of the HiPS -uniform usampler2D position_tex; +uniform sampler2D position_tex; uniform mat4 model; void main() { vec2 uv = out_clip_pos * 0.5 + 0.5; - uvec3 o = texture(position_tex, uv).rgb; - vec3 n = vec3(float(o.x)/65535.0, float(o.y)/65535.0, float(o.z)/65535.0) * 2.0 - 1.0; + vec3 n = texture(position_tex, uv).rgb * 2.0 - 1.0; vec3 frag_pos = vec3(model * vec4(n, 1.0));