-
Notifications
You must be signed in to change notification settings - Fork 0
/
voxelInitShader.frag
74 lines (59 loc) · 2.11 KB
/
voxelInitShader.frag
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
#version 410
out vec4 FragColor;
in vec4 vertexColor; // the input variable from the vertex shader (same name and same type)
in vec3 outVoxelPos;
uniform float near;
uniform float far;
uniform sampler2D texFBOX;
uniform sampler2D texFBOY;
uniform sampler2D texFBOZ;
uniform sampler2D texFBOXGreater;
uniform sampler2D texFBOYGreater;
uniform sampler2D texFBOZGreater;
in vec2 outTexCoord;
//uniform int INIT;
void main()
{
// Extract depthbuffer data from texture
vec4 x_min = texture(texFBOX, outTexCoord);
vec4 x_max = texture(texFBOXGreater, outTexCoord);
vec4 y_min = texture(texFBOY, outTexCoord);
vec4 y_max = texture(texFBOYGreater, outTexCoord);
vec4 z_min = texture(texFBOZ, outTexCoord);
vec4 z_max = texture(texFBOZGreater, outTexCoord);
// Transform voxPos to depthbuffer coordinates.
vec3 voxPosDepth = outVoxelPos / (far - near);
voxPosDepth = outVoxelPos * 0.1;
// Check if voxPos is inside limits from depth buffer data.
if (voxPosDepth.x > x_min.x && voxPosDepth.x < x_max.x)
{
FragColor = vec4(voxPosDepth.x ,voxPosDepth.y ,voxPosDepth.z,1);
if(voxPosDepth.y > y_min.x && voxPosDepth.y < y_max.x)
{
if(voxPosDepth.z > z_min.x && voxPosDepth.z < z_max.x)
{
// This should be for final or something similar
FragColor = vec4(voxPosDepth.x ,voxPosDepth.y ,voxPosDepth.z,1);
}
else
{
FragColor = vec4(voxPosDepth,0);
}
}
else
{
FragColor = vec4(voxPosDepth,0);
}
}
else
{
FragColor = vec4(voxPosDepth,0);
}
// This colors all and makes it so we can view voxelcube
FragColor = vec4(voxPosDepth.x ,voxPosDepth.y ,voxPosDepth.z,1);
// Uncomment to test texture loading, also uncomment in vertex shader
//FragColor = texture(texFBOX, outTexCoord);
// old stuff
//FragColor = vec4(outVoxelPos.x ,outVoxelPos.y ,outVoxelPos.z,0.5);//vertexColor;//texture(texFBOY, outTexCoord);
// -------------------------------------------------
}