MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / sample_texture_srgb

Method sample_texture_srgb

tools/bloom-reference/src/main.rs:282–305  ·  view source on GitHub ↗

Bilinear sRGB-decoded texture sample at UV.

(&self, tex_idx: usize, uv: Vec2)

Source from the content-addressed store, hash-verified

280
281 /// Bilinear sRGB-decoded texture sample at UV.
282 fn sample_texture_srgb(&self, tex_idx: usize, uv: Vec2) -> Option<(f32, f32, f32)> {
283 let tex = self.textures.get(tex_idx)?;
284 let (x0, y0, tx, ty) = tex_sample_coords(tex, uv);
285 let w = tex.width as i32;
286 let h = tex.height as i32;
287 let fetch = |x: i32, y: i32| -> (f32, f32, f32) {
288 let idx = ((y.rem_euclid(h) as usize) * tex.width as usize
289 + (x.rem_euclid(w) as usize))
290 * 4;
291 (
292 srgb_u8_to_linear(tex.pixels[idx]),
293 srgb_u8_to_linear(tex.pixels[idx + 1]),
294 srgb_u8_to_linear(tex.pixels[idx + 2]),
295 )
296 };
297 let c00 = fetch(x0, y0);
298 let c10 = fetch(x0 + 1, y0);
299 let c01 = fetch(x0, y0 + 1);
300 let c11 = fetch(x0 + 1, y0 + 1);
301 let r = lerp(lerp(c00.0, c10.0, tx), lerp(c01.0, c11.0, tx), ty);
302 let g = lerp(lerp(c00.1, c10.1, tx), lerp(c01.1, c11.1, tx), ty);
303 let b = lerp(lerp(c00.2, c10.2, tx), lerp(c01.2, c11.2, tx), ty);
304 Some((r, g, b))
305 }
306
307 /// Sample occlusion in [0,1]. glTF packs occlusion in R of the
308 /// occlusion texture; strength blends between "no AO" (0) and

Callers 1

sample_emissiveMethod · 0.80

Calls 4

tex_sample_coordsFunction · 0.85
srgb_u8_to_linearFunction · 0.85
lerpFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected