Hello, i am trying to save each pixel render position (raycast) in image generation time, instead of doing 2d to 3d since its too slow for multiple pick at once. my approach so far is to add position data with a shader. and then generate a float 3 channel image holding the x.y.z coordinate .
The shader seem to work fine. but i cant read the returned data.
1.is there a betteer way of doing this?
2. how can i read float3 data from the image?
fragmentShaderText:
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
{
// Compute the distance from the camera to the fragment
float distanceFromCamera = length(fsInput.attributes.positionEC);
// Normalize the distance for color mapping
float normalizedDistance = distanceFromCamera; // Adjust the divisor for scaling
// Apply a color gradient:
// Near (1m) → Green, Mid (2000m) → Yellow, Far (4000m) → Red
vec3 nearColor = vec3(1.0, 0.0, 0.0); // Green
vec3 midColor = vec3(1.0, 1.0, 0.0); // Yellow
vec3 farColor = vec3(0.0, 1.0, 0.0); // Red
// Blend colors smoothly
vec3 color = mix(nearColor, midColor, smoothstep(0.0, 0.5, normalizedDistance));
color = mix(color, farColor, smoothstep(0.5, 1.0, normalizedDistance));
material.normalEC = vec3(normalizedDistance);
// Apply the color to the material
material.diffuse = vec3(normalizedDistance);
}
});