Skip to content

Commit

Permalink
refactored fragment shader names
Browse files Browse the repository at this point in the history
  • Loading branch information
palasjir committed Dec 28, 2017
1 parent bbca70e commit 8f3dbea
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
20 changes: 10 additions & 10 deletions src/main/kotlin/palasjir/viewer/ui/VisualizationPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ constructor(
private var backFaceLoc: Int = 0
private var volumeLoc: Int = 0
private var gradientsLoc: Int = 0
private var VLoc: Int = 0
private var normalMatrixLoc: Int = 0
private var viewMatLoc: Int = 0
private var normalMatLoc: Int = 0

init {
preferredSize = dimension
Expand Down Expand Up @@ -140,19 +140,19 @@ constructor(
rayProgram.init(gl)
st.attachShaderProgram(gl, rayProgram.program, true)
screenSizeLoc = st.getUniformLocation(gl, "screenSize")
transferFuncLoc = st.getUniformLocation(gl, "TransferFunc")
transferFuncLoc = st.getUniformLocation(gl, "transferFn")
backFaceLoc = st.getUniformLocation(gl, "exitPoints")
volumeLoc = st.getUniformLocation(gl, "VolumeTex")
volumeLoc = st.getUniformLocation(gl, "volume")
gradientsLoc = st.getUniformLocation(gl, "gradients")
VLoc = st.getUniformLocation(gl, "V")
normalMatrixLoc = st.getUniformLocation(gl, "normalMatrix")
rayMvpLoc = st.getUniformLocation(gl, "MVP")
viewMatLoc = st.getUniformLocation(gl, "viewMat")
normalMatLoc = st.getUniformLocation(gl, "normalMat")
rayMvpLoc = st.getUniformLocation(gl, "mvp")
}

private fun initCubeProgram(gl: GL4) {
cubeProgram.init(gl)
st.attachShaderProgram(gl, cubeProgram.program, true)
cubeMvpLoc = st.getUniformLocation(gl, "MVP")
cubeMvpLoc = st.getUniformLocation(gl, "mvp")
}

/**
Expand Down Expand Up @@ -253,15 +253,15 @@ constructor(
viewPortHeight.toFloat()
)
gl.glUniformMatrix4fv(
VLoc,
viewMatLoc,
1,
false,
camera.viewMatrix.buffer
)

val normalMatrix = Matrices.invert(camera.viewMatrix.multiply(model)).transpose()
gl.glUniformMatrix4fv(
normalMatrixLoc,
normalMatLoc,
1,
false,
normalMatrix.buffer
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/shaders/cube_shader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

layout(location = 0) in vec3 vVertex;

//combined modelview projection matrix
uniform mat4 MVP;
// combined modelview projection matrix
uniform mat4 mvp;

out vec3 vColor;

void main()
{
//get clipspace position
vColor = vVertex;
gl_Position = MVP*vec4(vVertex.xyz,1);
gl_Position = mvp*vec4(vVertex.xyz,1);
}
24 changes: 12 additions & 12 deletions src/main/resources/shaders/raycasting.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

precision highp float;

in vec3 EntryPoint;
in vec3 entryPoint;

uniform vec2 screenSize;
uniform sampler2D exitPoints;
uniform sampler3D VolumeTex;
uniform sampler1D TransferFunc;
uniform sampler3D volume;
uniform sampler1D transferFn;
uniform sampler3D gradients;
uniform mat4 V;
uniform mat4 normalMatrix;
uniform mat4 viewMat;
uniform mat4 normalMat;

out vec4 fragColor;

Expand Down Expand Up @@ -70,16 +70,16 @@ void main()
vec3 exitPoint = texture(exitPoints, gl_FragCoord.st / screenSize).xyz;

// empty space skipping
if (EntryPoint == exitPoint)
if (entryPoint == exitPoint)
discard;

vec3 dir = (exitPoint - EntryPoint);
vec3 dir = (exitPoint - entryPoint);
float len = length(dir);
vec3 dirN = normalize(dir);
vec3 deltaDir = dirN * stepSize;
float deltaDirLen = length(deltaDir);

vec3 voxelCoord = calcVoxel(EntryPoint, gl_FragCoord.xy, deltaDir);
vec3 voxelCoord = calcVoxel(entryPoint, gl_FragCoord.xy, deltaDir);

float alphaAcum = 0.0;
float lengthAcum = 0.0;
Expand All @@ -91,16 +91,16 @@ void main()

vec3 viewSpacePosition;
vec3 viewSpaceNormal;
vec3 viewSpaceLightPosition = vec3(V * vec4(lightPositionWorld, 1.0));
vec3 viewSpaceLightPosition = vec3(viewMat * vec4(lightPositionWorld, 1.0));

for(int i = 0; i < MAX_ITERATIONS; i++)
{
intensity = texture(VolumeTex, voxelCoord).x;
intensity = texture(volume, voxelCoord).x;
gradient = normalize(texture(gradients, voxelCoord).xyz);
sampleColor = texture(TransferFunc, intensity);
sampleColor = texture(transferFn, intensity);

viewSpacePosition = voxelCoord;
viewSpaceNormal = normalize((normalMatrix * vec4(gradient, 0.0)).xyz);
viewSpaceNormal = normalize((normalMat * vec4(gradient, 0.0)).xyz);

if (sampleColor.a > 0.0) {
// correction
Expand Down
9 changes: 5 additions & 4 deletions src/main/resources/shaders/raycasting.vert
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

layout (location = 0) in vec3 vVertex;

uniform mat4 MVP;
// combined modelview projection matrix
uniform mat4 mvp;

out vec3 EntryPoint;
out vec3 entryPoint;

void main()
{
gl_Position = MVP * vec4(vVertex,1);
EntryPoint = vVertex;
gl_Position = mvp * vec4(vVertex,1);
entryPoint = vVertex;
}

0 comments on commit 8f3dbea

Please sign in to comment.