diff --git a/assets/shader/volume.frag b/assets/shader/volume.frag index 75a0d08..369db42 100644 --- a/assets/shader/volume.frag +++ b/assets/shader/volume.frag @@ -20,6 +20,7 @@ uniform vec3 eyeposition; uniform vec3 ambient = vec3(0.15, 0.15, 0.20); +uniform mat4 modelinv; uniform int algorithm; uniform float isovalue; uniform float isorange; @@ -39,8 +40,8 @@ bool intersect(vec3 ray_origin, vec3 ray_dir, vec3 center, vec3 normal, out vec3 { float t = dot(center - ray_origin, normal) / denom; if (t >= 0){ - - return true; // you might want to allow an epsilon here too + intersect.xyz = ray_origin + (ray_dir * t); + return true; } } return false; @@ -199,7 +200,7 @@ void main() { vec4 color; vec3 dir = normalize(frag_vert - eyeposition); - + dir = vec3(modelinv * vec4(dir, 0)); if(algorithm == 0) color = isosurface(frag_uv, dir, step_size); else if(algorithm == 1) diff --git a/src/visualize/image_like.jl b/src/visualize/image_like.jl index 9cffc70..540c2c9 100644 --- a/src/visualize/image_like.jl +++ b/src/visualize/image_like.jl @@ -276,25 +276,29 @@ end glCullFace(GL_FRONT) end -_default{T <: VolumeElTypes}(main::VolumeTypes{T}, s::Style, data::Dict) = @gen_defaults! data begin - intensities = main => Texture - dimensions = Vec3f0(1) - hull::GLUVWMesh = AABB{Float32}(Vec3f0(0), dimensions) - light_position = Vec3f0(0.25, 1.0, 3.0) - light_intensity = Vec3f0(15.0) +function _default{T <: VolumeElTypes}(main::VolumeTypes{T}, s::Style, data::Dict) + modelinv = const_lift(inv, get(data, :model, eye(Mat4f0))) + @gen_defaults! data begin + intensities = main => Texture + dimensions = Vec3f0(1) + hull::GLUVWMesh = AABB{Float32}(Vec3f0(0), dimensions) + light_position = Vec3f0(0.25, 1.0, 3.0) + light_intensity = Vec3f0(15.0) + modelinv = modelinv - color_map = default(Vector{RGBA}, s) => Texture - color_norm = color_map == nothing ? nothing : const_lift(extrema2f0, main) - color = color_map == nothing ? default(RGBA, s) : nothing + color_map = default(Vector{RGBA}, s) => Texture + color_norm = color_map == nothing ? nothing : const_lift(extrema2f0, main) + color = color_map == nothing ? default(RGBA, s) : nothing - algorithm = MaximumIntensityProjection - boundingbox = hull - absorption = 1f0 - isovalue = 0.5f0 - isorange = 0.01f0 - shader = GLVisualizeShader("fragment_output.frag", "util.vert", "volume.vert", "volume.frag") - prerender = VolumePrerender() - postrender = () -> begin - glDisable(GL_CULL_FACE) + algorithm = MaximumIntensityProjection + boundingbox = hull + absorption = 1f0 + isovalue = 0.5f0 + isorange = 0.01f0 + shader = GLVisualizeShader("fragment_output.frag", "util.vert", "volume.vert", "volume.frag") + prerender = VolumePrerender() + postrender = () -> begin + glDisable(GL_CULL_FACE) + end end end