mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-10 20:11:49 +00:00
Kind of stuck, now. Rendering red and blue point clouds
- Color information from second camera only gets through if first camera is disabled. - How do I print BOTH point clouds from uniform data?
This commit is contained in:
1 parent
6141c453fd
commit
0a70b326e7
1 file changed
+108
-80
@@ -62,7 +62,7 @@ pub static POINT_CLOUD_VERTEX_SHADER : &'static str = "\
|
||||
|
||||
// NB: It appears that locations need to be wide enough apart, or the colors bleed across locations.
|
||||
layout(location = 0) in vec4 inColor0;
|
||||
layout(location = 4) in vec4 inColor1;
|
||||
layout(location = 10) in vec4 inColor1;
|
||||
|
||||
out vec4 vertexColor;
|
||||
|
||||
@@ -74,63 +74,90 @@ layout(rgba32f, binding=1) readonly uniform image2D pointCloudTexture1;
|
||||
|
||||
uniform bool enableShading;
|
||||
|
||||
bool GetPoint3d(in vec2 pointCloudSize, in ivec2 point2d, out vec3 point3d)
|
||||
{
|
||||
if (point2d.x < 0 || point2d.x >= pointCloudSize.x ||
|
||||
point2d.y < 0 || point3d.y >= pointCloudSize.y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
point3d = imageLoad(pointCloudTexture0, point2d).xyz;
|
||||
if (point3d.z <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
// bool GetPoint3d(in vec2 pointCloudSize, in ivec2 point2d, out vec3 point3d)
|
||||
// {
|
||||
// if (point2d.x < 0 || point2d.x >= pointCloudSize.x ||
|
||||
// point2d.y < 0 || point3d.y >= pointCloudSize.y)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// point3d = imageLoad(pointCloudTexture0, point2d).xyz;
|
||||
// if (point3d.z <= 0)
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 pointCloudSize = imageSize(pointCloudTexture0);
|
||||
ivec2 currentDepthPixelCoordinates = ivec2(gl_VertexID % pointCloudSize.x, gl_VertexID / pointCloudSize.x);
|
||||
//vec3 vertexPosition = imageLoad(pointCloudTexture0, currentDepthPixelCoordinates).xyz;
|
||||
//int pointCloudVertexLength = pointCloudSize.x * pointCloudSize.y;
|
||||
ivec2 pointCloudSize0 = imageSize(pointCloudTexture0);
|
||||
ivec2 pointCloudSize1 = imageSize(pointCloudTexture1);
|
||||
|
||||
int pointCloudLength0 = pointCloudSize0.x * pointCloudSize0.y;
|
||||
int pointCloudLength1 = pointCloudSize1.x * pointCloudSize1.y;
|
||||
|
||||
vec3 vertexPosition;
|
||||
vec4 colorOut;
|
||||
|
||||
if (gl_VertexID % 2 == 0) {
|
||||
// Camera #0
|
||||
ivec2 currentDepthPixelCoordinates = ivec2(gl_VertexID % pointCloudSize0.x, gl_VertexID / pointCloudSize0.x);
|
||||
|
||||
vertexPosition = imageLoad(pointCloudTexture0, currentDepthPixelCoordinates).xyz;
|
||||
colorOut = inColor0;
|
||||
|
||||
//colorOut = inColor0;
|
||||
|
||||
colorOut = vec4(
|
||||
100,
|
||||
inColor0.g,
|
||||
inColor0.b,
|
||||
255
|
||||
);
|
||||
} else {
|
||||
// Camera #1
|
||||
ivec2 currentDepthPixelCoordinates = ivec2(gl_VertexID % pointCloudSize1.x, gl_VertexID / pointCloudSize1.x);
|
||||
|
||||
vec3 originalPosition = imageLoad(pointCloudTexture1, currentDepthPixelCoordinates).xyz;
|
||||
|
||||
//vertexPosition = originalPosition;
|
||||
|
||||
vertexPosition = vec3(
|
||||
originalPosition.x - 1.5,
|
||||
originalPosition.y,
|
||||
originalPosition.z
|
||||
);
|
||||
|
||||
//colorOut = inColor1; // NOT WORKING FULLY
|
||||
colorOut = vec4(
|
||||
inColor1.r + 255,
|
||||
inColor1.r,
|
||||
inColor1.g,
|
||||
100,
|
||||
255
|
||||
);
|
||||
|
||||
//colorOut = inColor1;
|
||||
/*colorOut = vec4(
|
||||
inColor1.r + 0,
|
||||
inColor1.g + 0,
|
||||
inColor1.b + 0,
|
||||
inColor1.a + 255
|
||||
);
|
||||
inColor1.a + 0
|
||||
);*/
|
||||
}
|
||||
|
||||
//vec3 vertexPosition = imageLoad(pointCloudTexture0, currentDepthPixelCoordinates).xyz;
|
||||
//int pointCloudVertexLength = pointCloudSize.x * pointCloudSize.y;
|
||||
|
||||
//if (gl_VertexID % 2 == 0) {
|
||||
//} else {
|
||||
//}
|
||||
|
||||
// Scale up while model view matrices not implemented.
|
||||
//vertexPosition.x *= 2.0 + 10.0;
|
||||
//vertexPosition.y *= 2.0 + 10.0;
|
||||
//vertexPosition.z *= 2.0;
|
||||
|
||||
|
||||
if (view[0][0] > 0.5) {
|
||||
vertexPosition.x -= 2.0;
|
||||
vertexPosition.y -= 2.0;
|
||||
@@ -146,59 +173,60 @@ void main()
|
||||
vertexColor.a = 0.0f;
|
||||
}
|
||||
|
||||
if (enableShading)
|
||||
{
|
||||
// Compute the location of the closest neighbor pixel to compute lighting
|
||||
//
|
||||
vec3 closestNeighbor = vertexPosition;
|
||||
|
||||
// If no neighbors have data, default to 1 meter behind point.
|
||||
//
|
||||
closestNeighbor.z += 1.0f;
|
||||
|
||||
vec3 outPoint;
|
||||
if (GetPoint3d(pointCloudSize, currentDepthPixelCoordinates - ivec2(1, 0), outPoint))
|
||||
{
|
||||
if (closestNeighbor.z > outPoint.z)
|
||||
{
|
||||
closestNeighbor = outPoint;
|
||||
}
|
||||
}
|
||||
if (GetPoint3d(pointCloudSize, currentDepthPixelCoordinates + ivec2(1, 0), outPoint))
|
||||
{
|
||||
if (closestNeighbor.z > outPoint.z)
|
||||
{
|
||||
closestNeighbor = outPoint;
|
||||
}
|
||||
}
|
||||
if (GetPoint3d(pointCloudSize, currentDepthPixelCoordinates - ivec2(0, 1), outPoint))
|
||||
{
|
||||
if (closestNeighbor.z > outPoint.z)
|
||||
{
|
||||
closestNeighbor = outPoint;
|
||||
}
|
||||
}
|
||||
if (GetPoint3d(pointCloudSize, currentDepthPixelCoordinates + ivec2(0, 1), outPoint))
|
||||
{
|
||||
if (closestNeighbor.z > outPoint.z)
|
||||
{
|
||||
closestNeighbor = outPoint;
|
||||
}
|
||||
}
|
||||
|
||||
vec3 lightPosition = vec3(0, 0, 0);
|
||||
float occlusion = length(vertexPosition - closestNeighbor) * 20.0f;
|
||||
float diffuse = 1.0f - clamp(occlusion, 0.0f, 0.6f);
|
||||
|
||||
float distance = length(lightPosition - vertexPosition);
|
||||
|
||||
// Attenuation term for light source that covers distance up to 50 meters
|
||||
// http://wiki.ogre3d.org/tiki-index.php?page=-Point+Light+Attenuation
|
||||
//
|
||||
float attenuation = 1.0 / (1.0 + 0.09 * distance + 0.032 * distance * distance);
|
||||
|
||||
vertexColor = vec4(attenuation * diffuse * vertexColor.rgb, vertexColor.a);
|
||||
}
|
||||
// NB: This is affecting the second camera. Disabling for now.
|
||||
// if (enableShading)
|
||||
// {
|
||||
// // Compute the location of the closest neighbor pixel to compute lighting
|
||||
// //
|
||||
// vec3 closestNeighbor = vertexPosition;
|
||||
//
|
||||
// // If no neighbors have data, default to 1 meter behind point.
|
||||
// //
|
||||
// closestNeighbor.z += 1.0f;
|
||||
//
|
||||
// vec3 outPoint;
|
||||
// if (GetPoint3d(pointCloudSize, currentDepthPixelCoordinates - ivec2(1, 0), outPoint))
|
||||
// {
|
||||
// if (closestNeighbor.z > outPoint.z)
|
||||
// {
|
||||
// closestNeighbor = outPoint;
|
||||
// }
|
||||
// }
|
||||
// if (GetPoint3d(pointCloudSize, currentDepthPixelCoordinates + ivec2(1, 0), outPoint))
|
||||
// {
|
||||
// if (closestNeighbor.z > outPoint.z)
|
||||
// {
|
||||
// closestNeighbor = outPoint;
|
||||
// }
|
||||
// }
|
||||
// if (GetPoint3d(pointCloudSize, currentDepthPixelCoordinates - ivec2(0, 1), outPoint))
|
||||
// {
|
||||
// if (closestNeighbor.z > outPoint.z)
|
||||
// {
|
||||
// closestNeighbor = outPoint;
|
||||
// }
|
||||
// }
|
||||
// if (GetPoint3d(pointCloudSize, currentDepthPixelCoordinates + ivec2(0, 1), outPoint))
|
||||
// {
|
||||
// if (closestNeighbor.z > outPoint.z)
|
||||
// {
|
||||
// closestNeighbor = outPoint;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// vec3 lightPosition = vec3(0, 0, 0);
|
||||
// float occlusion = length(vertexPosition - closestNeighbor) * 20.0f;
|
||||
// float diffuse = 1.0f - clamp(occlusion, 0.0f, 0.6f);
|
||||
//
|
||||
// float distance = length(lightPosition - vertexPosition);
|
||||
//
|
||||
// // Attenuation term for light source that covers distance up to 50 meters
|
||||
// // http://wiki.ogre3d.org/tiki-index.php?page=-Point+Light+Attenuation
|
||||
// //
|
||||
// float attenuation = 1.0 / (1.0 + 0.09 * distance + 0.032 * distance * distance);
|
||||
//
|
||||
// vertexColor = vec4(attenuation * diffuse * vertexColor.rgb, vertexColor.a);
|
||||
// }
|
||||
}
|
||||
";
|
||||
|
||||
|
||||
Reference in new issue
Block a user