Crafter.Graphics/examples/RTVolume/anyhit.glsl

33 lines
1.2 KiB
GLSL

//SPDX-License-Identifier: MIT
//SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
#version 460
#extension GL_EXT_ray_tracing : enable
// RTVolume any-hit shader — runs on every candidate sphere hit because
// the geometry is built non-opaque (BuildProcedural opaque=false) and
// the instances don't force-opaque. Punches a spherical checkerboard of
// holes: for half the cells it calls ignoreIntersectionEXT, so the ray
// passes straight through and the background / spheres behind show
// through — the visible proof the any-hit path runs. Mirrors
// anyhit.wgsl on the WebGPU path.
hitAttributeEXT vec2 attribs;
layout(location = 0) rayPayloadInEXT vec3 hitValue;
void main() {
// Object-space hit point on the unit sphere → its normal/direction.
vec3 posObj = gl_ObjectRayOriginEXT + gl_ObjectRayDirectionEXT * gl_HitTEXT;
vec3 n = normalize(posObj);
const float PI = 3.14159265;
float longitude = atan(n.z, n.x); // [-PI, PI]
float latitude = asin(clamp(n.y, -1.0, 1.0)); // [-PI/2, PI/2]
int cu = int(floor((longitude + PI) / PI * 6.0));
int cv = int(floor((latitude + PI * 0.5) / PI * 6.0));
if (((cu + cv) & 1) == 0) {
ignoreIntersectionEXT; // cut-out cell — see through
}
}