-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleFragmentShader.fp
127 lines (102 loc) · 3.49 KB
/
SimpleFragmentShader.fp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#version 330 core
// Interpolated values from the vertex shaders
in vec2 fragmentUV;
// Values that stay constant
uniform sampler2D myTextureSamplerVolume;
// Ouput data
out vec3 color;
// Input: z coordinate of the point in the volume, between 0 and 1
// Output: grid coordinates (i,j) of the slice where the point lies, between (0,0) and (9,9)
// Warning: use the fonction "floor" to make sure that the coordinates of the slice are integer. For instance, for z = 0.823, the function should return (i=2,j=8) because the closest slice is the 82nd one.
vec2 slice_coordinate(float z)
{
//rescale z
float z2 = z*100.;
//coordinate of the slice
float j = floor(z2/10.);
float i = floor(z2 - 10.*j);
return vec2(i,j);
}
// Input: (x,y,z) coordinates of the point in the volume, between (0,0,0) and (1,1,1)
// Output: (u,v) coordinates of the pixel in the texture
vec2 pixel_coordinate(float x, float y, float z)
{
vec2 sliceCoord = slice_coordinate(z);
//coordinate of the pixel in the slice
float u = x/10.;
float v = y/10.;
return vec2(u,v)+slice_coordinate(z)/10.;
}
void main()
{
vec2 pixCoord;
float x,y,z;
/*
//extract one horizontal slice (x and y vary with fragment coordinates, z is fixed)
x = fragmentUV.x;
y = fragmentUV.y;
z = 82./100.; //extract 82nd slice
pixCoord = pixel_coordinate(x,y,z);
color = texture(myTextureSamplerVolume, pixCoord).rgb;
*/
/*
//Accumulate all horizontal slices
x = fragmentUV.x;
y = fragmentUV.y;
color = vec3(0.0,0.0,0.0);
for (int i=0; i<100; i++) {
z = float((i+1)/100.); // extract the i th slice
pixCoord = pixel_coordinate(x,y,z);
color += texture(myTextureSamplerVolume, pixCoord).rgb/100.;
}
*/
/*
//extract one vertical slice (x and z vary with fragment coordinates, y is fixed)
x = fragmentUV.x;
z = fragmentUV.y;
color = vec3(0.0,0.0,0.0);
y = 50./100.; // extract the middle vertical slice
pixCoord = pixel_coordinate(x,y,z);
color += texture(myTextureSamplerVolume, pixCoord).rgb;
*/
//Accumulate all vertical slices
x = fragmentUV.x;
z = fragmentUV.y;
color = vec3(0.0,0.0,0.0);
for (int i=0; i<100; i++) {
y = float((i+1)/100.); // extract the i th vertical slice
pixCoord = pixel_coordinate(x,y,z);
color += texture(myTextureSamplerVolume, pixCoord).rgb/100.;
}
/*
//Accumulate all vertical slices after rotation by rotationAngle around the z axis
float rotationAngle = 0;
float HypTot = 1.0/cos(rotationAngle);
x = fragmentUV.x;
x = x - 0.5*tan(rotationAngle);
if (x<0) {
x=0;
}
y = 0.0;
z = fragmentUV.y;
color = vec3(0.0,0.0,0.0);
for (int i=0; i<100; i++) {
x = x + cos(math.PI/2.0 -rotationAngle)*float(i*HypTot/100);
y = y + sin(math.PI/2.0 -rotationAngle)*float(i*HypTot/100); // extract the i th vertical slice
pixCoord = pixel_coordinate(x,y,z);
color += texture(myTextureSamplerVolume, pixCoord).rgb/100.;
}
*/
/*
//Ray marching until density above a threshold (i.e., extract an iso-surface)
//...
*/
/*
//Ray marching until density above a threshold, display iso-surface normals
//...
*/
/*
//Ray marching until density above a threshold, display shaded iso-surface
//...
*/
}