Hello all,
I just using a SkinnedMeshRenderer and a computeShader and a bakeMesh() and creating a RenderTexture from this. But when I save the texture in exr format I get a striped picture. So how can yi save the vertices into a texture and use it in the Shadergraph?
Thanks
Here is some more details:
The computeShader
#pragma kernel RunThis
StructuredBuffer<float3> computeInVertexPositions;
RWTexture2D<float4> computeOutTexture;
[numthreads(8, 8, 1)]
void RunThis (uint3 id : SV_DispatchThreadID)
{
if (id.x < computeInVertexPositions.Length)
{
float3 v = computeInVertexPositions[id.x];
computeOutTexture[id.xy] = float4(v, 1.0);
}
}
C# side:
vertexToTexture2DComputeShader.SetBuffer(_kernelHandle, ComputeInVertexPositions, cb);
vertexToTexture2DComputeShader.SetTexture(_kernelHandle, ComputeOutTexture, _renderTextures[i]);
vertexToTexture2DComputeShader.Dispatch(_kernelHandle,
Mathf.CeilToInt(RenderTextureSize / (float)ThreadGroupX),
Mathf.CeilToInt(RenderTextureSize / (float)ThreadGroupY),
ThreadGroupZ);
and the ShaderGraph:
the generated renderTexture
Somebody please help!
I believe it’s because you always write the first x vertex position into each row. You access computeInVertexPositions using id.x which runs from 0 to RenderTextureSize no matter the row. You need to compute an index into computeInVertexPositions.
uint vertexIdx = id.y * RenderTextureSize + id.x;
if (vertexIdx < computeInVertexPositions.Length)
{
float3 v = computeInVertexPositions[vertexIdx];
computeOutTexture[id.xy] = float4(v, 1.0);
}
1 Like
with your code I get this:
RenderTextureSize size is 256
when zoomIn in Gimp:
it is 8638 pixel, so 8638 vertex, like the modell. This is ok. But why this is Stripe?
And how I get back the vertices and the mesh from this texture in ShaderGraph?
Can you help me why the clipping only works on the simple MeshRenderer and not on the SkinnedMeshRenderer one?
Is it because the skinned vertices not bypassing to the ShaderGraph or why?