Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GraPa
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kai Westerkamp
GraPa
Commits
4fe659ca
Commit
4fe659ca
authored
Dec 05, 2015
by
Kai Westerkamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ray marching
parent
4685d45b
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
181 additions
and
33 deletions
+181
-33
controler.cpp
A3/controler.cpp
+1
-1
display.frag
A3/display.frag
+60
-6
glview.cpp
A3/glview.cpp
+47
-11
glview.h
A3/glview.h
+3
-0
hellocube.pro.user
A3/hellocube.pro.user
+1
-1
mainwindow.cpp
A3/mainwindow.cpp
+1
-1
phong.frag
A3/phong.frag
+18
-12
scenevolume.cpp
A3/scenevolume.cpp
+50
-1
No files found.
A3/controler.cpp
View file @
4fe659ca
...
...
@@ -176,7 +176,7 @@ void Controler::addVolume(QString filePath){
int
count
=
0
;
// std::cout<<std::hex;
int
printLine
=
150
;
int
printLine
=
400
;
// z/2
;
for
(
int
k
=
0
;
k
<
z
;
k
++
)
{
...
...
A3/display.frag
View file @
4fe659ca
uniform
sampler2D
Texture
;
uniform
sampler2D
TextureID
;
uniform
int
active
;
uniform
sampler2D
PickID
;
uniform
sampler2D
StartRay
;
uniform
sampler2D
StopRay
;
uniform
sampler3D
volumeData
;
varying
vec4
qt_TexCoord0
;
uniform
bool
MIP
;
vec4
transfer
(
float
scalar
){
return
vec4
(
scalar
);
}
void
main
(
void
)
{
gl_FragColor
=
texture2D
(
Texture
,
gl_TexCoord
[
0
].
st
);
//gl_FragColor = texture2D(TextureID,gl_TexCoord[0].st)/255;
//gl_FragColor = vec4(active);
// gl_FragColor = vec4(gl_TexCoord[0].st,0,1);
//gl_FragColor = texture2D(PickID,gl_TexCoord[0].st);
//gl_FragColor = texture2D(StartRay,gl_TexCoord[0].st);
gl_FragColor
=
vec4
(
texture2D
(
StopRay
,
gl_TexCoord
[
0
].
st
).
xyz
,
1
);
// gl_FragColor = vec4(gl_TexCoord[0].st,0,1);
vec3
front
=
texture2D
(
StartRay
,
gl_TexCoord
[
0
].
st
).
xyz
;
vec3
back
=
texture2D
(
StopRay
,
gl_TexCoord
[
0
].
st
).
xyz
;
if
(
front
==
back
){
gl_FragColor
=
vec4
(
texture2D
(
Texture
,
gl_TexCoord
[
0
].
st
).
xyz
,
1
);
}
else
{
vec3
ray
=
back
-
front
;
float
rayLength
=
length
(
ray
);
vec3
stepVector
=
0
.
01
*
ray
/
rayLength
;
vec3
pos
=
front
;
vec4
dst
=
vec4
(
0
);
float
maxfloat
=
0
;
while
(
dst
.
a
<
1
&&
rayLength
>
0
)
{
float
density
=
texture3D
(
volumeData
,
pos
).
x
;
maxfloat
=
max
(
density
,
maxfloat
);
vec4
src
=
transfer
(
density
);
src
.
rgb
*=
src
.
a
;
dst
=
(
1
.
0
-
dst
.
a
)
*
src
+
dst
;
pos
+=
stepVector
;
rayLength
-=
0
.
01
;
}
if
(
MIP
)
{
gl_FragColor
=
transfer
(
maxfloat
);
}
else
{
gl_FragColor
=
dst
;
}
// gl_FragColor = vec4(gl_TexCoord[0].xyz,1);
//gl_FragColor = vec4(vec3(count),1);
//gl_FragColor = vec4(normalize(step),1);
//gl_FragColor = vec4(normalize(gl_ModelViewProjectionMatrixInverse*vec4(0,1,0,0.0)));
//gl_FragColor = vec4(texture3D(volumeData,vec3(front.xy,0.5)).x);
}
}
A3/glview.cpp
View file @
4fe659ca
...
...
@@ -56,8 +56,9 @@ void GLView::initShader()
shader
->
addShader
(
vertex
);
shader
->
addShader
(
fragment
);
shader
->
bindAttributeLocation
(
"pickID"
,
4
);
if
(
!
shader
->
link
())
if
(
!
shader
->
link
())
{
qCritical
()
<<
"Linking failed"
<<
shader
->
log
();
}
...
...
@@ -72,8 +73,10 @@ void GLView::initShader()
displayShader
=
new
QGLShaderProgram
(
this
);
displayShader
->
addShader
(
vertex
);
displayShader
->
addShader
(
fragment
);
if
(
!
displayShader
->
link
())
qCritical
()
<<
"Linking failed"
<<
displayShader
->
log
();
if
(
!
displayShader
->
link
()){
qCritical
()
<<
"Linking 2 failed:"
<<
displayShader
->
log
();
}
}
void
GLView
::
home
(){
...
...
@@ -93,8 +96,8 @@ void GLView::paintGL ()
shader
->
bind
();
if
(
useFBO
){
glBindFramebuffer
(
GL_FRAMEBUFFER
,
fbo
);
GLenum
buffers
[]
=
{
GL_COLOR_ATTACHMENT0
,
GL_COLOR_ATTACHMENT1
};
glDrawBuffers
(
2
,
buffers
);
GLenum
buffers
[]
=
{
GL_COLOR_ATTACHMENT0
,
GL_COLOR_ATTACHMENT1
,
GL_COLOR_ATTACHMENT2
,
GL_COLOR_ATTACHMENT3
};
glDrawBuffers
(
4
,
buffers
);
//http://stackoverflow.com/questions/7207422/setting-up-opengl-multiple-render-targets
}
...
...
@@ -102,6 +105,7 @@ void GLView::paintGL ()
glClear
(
GL_COLOR_BUFFER_BIT
|
GL_DEPTH_BUFFER_BIT
);
glEnable
(
GL_DEPTH_TEST
);
glDisable
(
GL_CULL_FACE
);
glViewport
(
0
,
0
,
this
->
width
(),
this
->
height
());
...
...
@@ -110,9 +114,7 @@ void GLView::paintGL ()
glMatrixMode
(
GL_PROJECTION
);
glLoadIdentity
();
glActiveTexture
(
GL_TEXTURE0
);
glBindTexture
(
GL_TEXTURE_3D
,
texture3D
);
displayShader
->
setUniformValue
(
"volumeData"
,
0
);
shader
->
setUniformValue
(
"shaded"
,
true
);
...
...
@@ -172,9 +174,21 @@ void GLView::paintGL ()
glActiveTexture
(
GL_TEXTURE1
);
glBindTexture
(
GL_TEXTURE_2D
,
picID
);
displayShader
->
setUniformValue
(
"TextureID"
,
1
);
displayShader
->
setUniformValue
(
"PickID"
,
1
);
glActiveTexture
(
GL_TEXTURE2
);
glBindTexture
(
GL_TEXTURE_2D
,
startRay
);
displayShader
->
setUniformValue
(
"StartRay"
,
2
);
displayShader
->
setUniformValue
(
"active"
,
scene
->
getActive
()
->
getID
());
glActiveTexture
(
GL_TEXTURE3
);
glBindTexture
(
GL_TEXTURE_2D
,
stopRay
);
displayShader
->
setUniformValue
(
"StopRay"
,
3
);
glActiveTexture
(
GL_TEXTURE4
);
glBindTexture
(
GL_TEXTURE_3D
,
texture3D
);
displayShader
->
setUniformValue
(
"volumeData"
,
4
);
//displayShader->setUniformValue("active",scene->getActive()->getID());
glBegin
(
GL_QUADS
);
glTexCoord2d
(
0
,
0
);
...
...
@@ -315,7 +329,7 @@ void GLView::resizeGL(int width , int height )
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
GL_RGBA
,
width
,
height
,
0
,
GL_RGBA
,
GL_UNSIGNED_BYTE
,
NULL
);
// Create the
color
buffer
// Create the
pcik
buffer
glGenTextures
(
1
,
&
picID
);
glBindTexture
(
GL_TEXTURE_2D
,
picID
);
glTexParameterf
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_S
,
GL_CLAMP_TO_EDGE
);
...
...
@@ -325,6 +339,26 @@ void GLView::resizeGL(int width , int height )
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
GL_RGBA
,
width
,
height
,
0
,
GL_RGBA
,
GL_UNSIGNED_BYTE
,
NULL
);
// Create the pcik startRay
glGenTextures
(
1
,
&
startRay
);
glBindTexture
(
GL_TEXTURE_2D
,
startRay
);
glTexParameterf
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_S
,
GL_CLAMP_TO_EDGE
);
glTexParameterf
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_T
,
GL_CLAMP_TO_EDGE
);
glTexParameterf
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
glTexParameterf
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR
);
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
GL_RGBA
,
width
,
height
,
0
,
GL_RGBA
,
GL_UNSIGNED_BYTE
,
NULL
);
// Create the pcik stopRay
glGenTextures
(
1
,
&
stopRay
);
glBindTexture
(
GL_TEXTURE_2D
,
stopRay
);
glTexParameterf
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_S
,
GL_CLAMP_TO_EDGE
);
glTexParameterf
(
GL_TEXTURE_2D
,
GL_TEXTURE_WRAP_T
,
GL_CLAMP_TO_EDGE
);
glTexParameterf
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
glTexParameterf
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR
);
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
GL_RGBA
,
width
,
height
,
0
,
GL_RGBA
,
GL_UNSIGNED_BYTE
,
NULL
);
// Create the depth buffer
glGenRenderbuffers
(
1
,
&
depth
);
glBindRenderbuffer
(
GL_RENDERBUFFER
,
depth
);
...
...
@@ -332,6 +366,8 @@ void GLView::resizeGL(int width , int height )
glFramebufferTexture2D
(
GL_FRAMEBUFFER
,
GL_COLOR_ATTACHMENT0
,
GL_TEXTURE_2D
,
color
,
0
);
glFramebufferTexture2D
(
GL_FRAMEBUFFER
,
GL_COLOR_ATTACHMENT1
,
GL_TEXTURE_2D
,
picID
,
0
);
glFramebufferTexture2D
(
GL_FRAMEBUFFER
,
GL_COLOR_ATTACHMENT2
,
GL_TEXTURE_2D
,
startRay
,
0
);
glFramebufferTexture2D
(
GL_FRAMEBUFFER
,
GL_COLOR_ATTACHMENT3
,
GL_TEXTURE_2D
,
stopRay
,
0
);
glFramebufferRenderbuffer
(
GL_FRAMEBUFFER
,
GL_DEPTH_ATTACHMENT
,
GL_RENDERBUFFER
,
depth
);
GLenum
err
=
glCheckFramebufferStatus
(
GL_FRAMEBUFFER
);
...
...
A3/glview.h
View file @
4fe659ca
...
...
@@ -58,6 +58,9 @@ private:
GLuint
picID
;
GLuint
depth
;
GLuint
startRay
;
GLuint
stopRay
;
GLuint
texture3D
;
...
...
A3/hellocube.pro.user
View file @
4fe659ca
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2015-12-0
3T11:54:44
. -->
<!-- Written by QtCreator 3.5.1, 2015-12-0
5T11:07:00
. -->
<qtcreator>
<data>
<variable>
EnvironmentId
</variable>
...
...
A3/mainwindow.cpp
View file @
4fe659ca
...
...
@@ -303,7 +303,7 @@ MainWindow::MainWindow(QWidget *parent)
void
MainWindow
::
initScene
(){
//scene->simpleScene();
controler
->
addVolume
(
"D:/Projekte/GraPa/A3/lobster
.raw"
);
// controler->addVolume("D:/Projekte/GraPa/A3/MRI-head
.raw");
timer
->
stop
();
}
...
...
A3/phong.frag
View file @
4fe659ca
...
...
@@ -12,14 +12,7 @@ void main(void)
{
vec3
V
=
normalize
(
-
position
);
if
(
volume
){
// gl_FragData[0] = vec4(gl_TexCoord[0].xyz,1);
gl_FragData
[
0
]
=
vec4
(
texture3D
(
volumeData
,
gl_TexCoord
[
0
].
xyz
).
x
);
}
else
if
(
shaded
){
if
(
shaded
){
vec3
N
=
normalize
(
normal
);
vec3
L
=
normalize
(
gl_LightSource
[
0
].
position
.
xyz
-
position
);
...
...
@@ -39,10 +32,23 @@ void main(void)
vec4
color
=
(
Iamb
+
Idiff
+
Ispec
);
gl_FragData
[
0
]
=
color
;
}
else
}
else
gl_FragData
[
0
]
=
vec4
(
1
,
1
,
0
,
1
);
gl_FragData
[
1
]
=
pick
;
//gl_FragData[1] = vec4(abs(normal),1);
//gl_FragData[1] = pick;
gl_FragData
[
1
]
=
vec4
(
abs
(
normal
),
1
);
if
(
volume
){
if
(
gl_FrontFacing
){
gl_FragData
[
2
]
=
gl_TexCoord
[
0
];
// gl_FragData[3] = vec4(0);
}
else
{
// gl_FragData[2] = vec4(0);
gl_FragData
[
3
]
=
gl_TexCoord
[
0
];
}
}
else
{
gl_FragData
[
2
]
=
vec4
(
0
,
0
,
0
,
1
);
gl_FragData
[
3
]
=
vec4
(
0
,
0
,
0
,
1
);
}
}
A3/scenevolume.cpp
View file @
4fe659ca
...
...
@@ -37,6 +37,16 @@ void SceneVolume::draw(QGLShaderProgram *shader){
shader
->
setUniformValue
(
"volume"
,
true
);
QMatrix4x4
mat
=
QMatrix4x4
();
mat
.
rotate
(
getGlobalRotation
().
conjugate
());
glMultMatrixf
(
mat
.
data
());
// shader->setUniformValue("volumeRot",mat);
glDisable
(
GL_DEPTH_TEST
);
glBlendFunc
(
GL_SRC_ALPHA
,
GL_ONE_MINUS_SRC_ALPHA
);
glEnable
(
GL_BLEND
);
float
x
=
lx
/
2
;
float
y
=
ly
/
2
;
float
z
=
lz
/
2
;
...
...
@@ -113,9 +123,48 @@ void SceneVolume::draw(QGLShaderProgram *shader){
glVertex3f
(
x
,
-
y
,
-
z
);
glEnd
();
shader
->
setUniformValue
(
"volume"
,
false
);
shader
->
setUniformValue
(
"shaded"
,
false
);
glLineWidth
(
2
);
if
(
true
){
glBegin
(
GL_LINES
);
glVertex3f
(
x
,
y
,
-
z
);
glVertex3f
(
x
,
y
,
z
);
glVertex3f
(
-
x
,
y
,
-
z
);
glVertex3f
(
-
x
,
y
,
z
);
glVertex3f
(
x
,
-
y
,
-
z
);
glVertex3f
(
x
,
-
y
,
z
);
glVertex3f
(
-
x
,
-
y
,
-
z
);
glVertex3f
(
-
x
,
-
y
,
z
);
glVertex3f
(
x
,
-
y
,
z
);
glVertex3f
(
x
,
y
,
z
);
glVertex3f
(
-
x
,
-
y
,
z
);
glVertex3f
(
-
x
,
y
,
z
);
glVertex3f
(
x
,
-
y
,
-
z
);
glVertex3f
(
x
,
y
,
-
z
);
glVertex3f
(
-
x
,
-
y
,
-
z
);
glVertex3f
(
-
x
,
y
,
-
z
);
glVertex3f
(
-
x
,
y
,
z
);
glVertex3f
(
x
,
y
,
z
);
glVertex3f
(
-
x
,
-
y
,
z
);
glVertex3f
(
x
,
-
y
,
z
);
glVertex3f
(
-
x
,
y
,
-
z
);
glVertex3f
(
x
,
y
,
-
z
);
glVertex3f
(
-
x
,
-
y
,
-
z
);
glVertex3f
(
x
,
-
y
,
-
z
);
glEnd
();
}
shader
->
setUniformValue
(
"shaded"
,
true
);
glEnable
(
GL_DEPTH_TEST
);
glDisable
(
GL_BLEND
);
glPopMatrix
();
shader
->
setUniformValue
(
"volume"
,
false
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment