raytracer by default

This commit is contained in:
Matthieu Baumann
2021-10-10 11:31:48 +02:00
parent c3c4c3dfb3
commit d2f72f7f4a
6 changed files with 83 additions and 22 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
node_modules

View File

@@ -16,8 +16,8 @@
"vue-loader": "^15.9.6",
"vue-template-compiler": "^2.6.12",
"webpack": "^5.25.1",
"webpack-cli": "^3.3.12",
"webpack-dev-server": "^3.11.1",
"webpack-cli": "^4.9.0",
"webpack-dev-server": "^4.3.1",
"webpack-glsl-loader": "^1.0.1"
},
"dependencies": {

View File

@@ -559,6 +559,15 @@ impl ImageSurveyTextures {
]
}
// Get the textures in the buffer
// The resulting array is uniq sorted
fn get_textures(&self) -> Vec<&Texture> {
assert!(self.is_ready());
let mut textures = self.textures.values().collect::<Vec<_>>();
textures.sort_unstable();
textures
}
pub fn get_texture_array(&self) -> Rc<Texture2DArray> {
self.texture_2d_array.clone()
}
@@ -571,7 +580,8 @@ impl SendUniforms for ImageSurveyTextures {
fn attach_uniforms<'a>(&self, shader: &'a ShaderBound<'a>) -> &'a ShaderBound<'a> {
if self.is_ready() {
// Send the textures
let textures = self.get_allsky_textures();
//let textures = self.get_allsky_textures();
let textures = self.get_textures();
let mut num_textures = 0;
for texture in textures.iter() {
if texture.is_available() {
@@ -581,7 +591,11 @@ impl SendUniforms for ImageSurveyTextures {
num_textures += 1;
}
}
let num_tiles = textures.len() as i32;
unsafe { crate::log(&format!("{}", num_tiles)); }
shader
.attach_uniform("num_tiles", &num_tiles)
.attach_uniforms_from(&self.config)
.attach_uniforms_from(&*self.texture_2d_array);
}

View File

@@ -852,7 +852,8 @@ impl Draw for ImageSurvey {
//let textures_array = self.textures.get_texture_array();
let raytracing = camera.get_aperture() > P::RASTER_THRESHOLD_ANGLE;
//let raytracing = camera.get_aperture() > P::RASTER_THRESHOLD_ANGLE;
let raytracing = true;
if raytracing {
let shader = color
.get_raytracer_shader::<P>(

View File

@@ -20,7 +20,8 @@ struct Tile {
};
uniform int current_depth;
uniform Tile textures_tiles[12];
uniform Tile textures_tiles[192];
uniform int num_tiles;
uniform float current_time; // current time in ms
@@ -29,26 +30,54 @@ uniform float current_time; // current time in ms
uniform float opacity;
int binary_search_tile(int uniq) {
int l = 0;
int r = num_tiles - 1;
while (l < r) {
int a = (l + r) / 2;
Tile tile = textures_tiles[a];
if(tile.uniq == uniq) {
return a;
} else if(tile.uniq < uniq) {
l = a + 1;
} else {
r = a - 1;
}
}
return l;
}
vec4 get_tile_color(vec3 pos) {
HashDxDy result = hash_with_dxdy(0, pos.zxy);
int d = current_depth;
while (d >= 0) {
HashDxDy result = hash_with_dxdy(d, pos.zxy);
int idx = result.idx;
vec2 uv = vec2(result.dy, result.dx);
int idx = result.idx;
vec2 uv = vec2(result.dy, result.dx);
Tile tile = textures_tiles[idx];
int uniq = (16 << (d << 1)) | idx;
int tile_idx = binary_search_tile(uniq);
Tile tile = textures_tiles[tile_idx];
int idx_texture = tile.texture_idx >> 6;
int off = tile.texture_idx & 0x3F;
float idx_row = float(off >> 3); // in [0; 7]
float idx_col = float(off & 0x7); // in [0; 7]
if(tile.uniq == uniq) {
int idx_texture = tile.texture_idx >> 6;
int off = tile.texture_idx & 0x3F;
float idx_row = float(off >> 3); // in [0; 7]
float idx_col = float(off & 0x7); // in [0; 7]
vec2 offset = (vec2(idx_col, idx_row) + uv)*0.125;
vec3 UV = vec3(offset, float(idx_texture));
vec2 offset = (vec2(idx_col, idx_row) + uv)*0.125;
vec3 UV = vec3(offset, float(idx_texture));
vec4 color = get_color_from_texture(UV);
color.a = mix(color.a, blank_color.a, tile.empty);
return color;
vec4 color = get_color_from_texture(UV);
color.a = mix(color.a, blank_color.a, tile.empty);
return color;
}
d = d - 1;
}
}
const float duration = 500.f; // 500ms
@@ -57,8 +86,24 @@ uniform int max_depth; // max depth of the HiPS
uniform sampler2D position_tex;
uniform mat4 model;
void main() {
vec2 uv = out_clip_pos * 0.5 + 0.5;
vec3 n = texture(position_tex, uv).rgb;
vec3 n = vec3(0.0);
if(current_depth < 2) {
vec2 uv = out_clip_pos * 0.5 + 0.5;
n = texture(position_tex, uv).rgb;
} else {
float x = out_clip_pos.x;
float y = out_clip_pos.y;
float x2 = x*x;
float y2 = y*y;
float x4 = x2*x2;
float y4 = y2*y2;
n = vec3(
-x,
y,
-0.5*x2 - 0.5*y2 + 1.0
);
}
vec3 frag_pos = vec3(model * vec4(n, 1.0));

View File

@@ -31,7 +31,7 @@ module.exports = {
new VueLoaderPlugin()
],
devServer:{
contentBase: 'dist'
static: 'dist'
},
module: {
rules: [