Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
use inv(model) to correct ray dir
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Mar 21, 2017
1 parent f7aface commit 0fcb5b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
7 changes: 4 additions & 3 deletions assets/shader/volume.frag
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
40 changes: 22 additions & 18 deletions src/visualize/image_like.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0fcb5b7

Please sign in to comment.