DrawProcedural draws nothing although buffers are assigned properly
Hi, it's the first time I acually need help from you guys. I have a compute shader that calculates the mesh for a tube along a spline. The resulting mesh looks like this:
This was drawn with Debug.Drawline and the data retrieved from the ComputeBuffer.
The Computebuffer stores 3 structs for each triangle to render. Each struct contains a position and a normal:
struct1{posX, poxY, posZ,pad0, normX....}, struct2{...}, struct3{...},...
|-------------------------------One Triangle-----------------------------------------|--next Triangle----...
When I try to draw the mesh on the graphics card nothing appears on the screen, even though I should see some white stuff floating around, right? This is the simple shader I use to draw the buffer:
Shader "Custom/CurveRenderShader" {
SubShader{
Tags{ "RenderType" = "Transparent" }
LOD 200
Pass{
Blend SrcAlpha OneMinusSrcAlpha
ZWrite On ZTest LEqual
Cull Off
CGPROGRAM
#pragma target 5.0
#pragma vertex vert
#pragma fragment frag
struct VertexOutput {
float4 position : SV_POSITION;
float3 normal: NORMAL;
};
struct computeOutLayout {
float posX;
float posY;
float posZ;
float pad0;
float normX;
float normY;
float normZ;
float pad1;
};
StructuredBuffer<computeOutLayout> computeOutBuffer;
VertexOutput vert(uint id : SV_VertexID) {
VertexOutput OUT;
OUT.position = mul(UNITY_MATRIX_MVP, float4(computeOutBuffer[id].posX, computeOutBuffer[id].posY, computeOutBuffer[id].posZ, 1.0));
OUT.normal = float3(computeOutBuffer[id].normX, computeOutBuffer[id].normY, computeOutBuffer[id].normZ);
return OUT;
}
//____ Fragment Shader ____//
fixed4 frag(VertexOutput IN) : SV_TARGET{
return fixed4(1.0,1.0,1.0,1.0); // <--- I guess I should see my mesh rendered purely white
}
ENDCG
}
}
}
Can some genius around here shine some light on this? :D
The mesh is not yet closed and the Mesh drawn with Debug.DrawLine jitters quite a lot in the viewport but I think that should not matter when it comes to drawing the mesh with a shader.
/---EDIT:
These are the lines where I dispatch the compute shader and try to and draw the thing:
computeShader.Dispatch(kernels[(int)settings.mode], amountOfAdjacencies, 1, 1);
renderMaterial.SetPass(0);
renderMaterial.SetBuffer("computeOutBuffer", computeOutBuffer);
Graphics.DrawProcedural(MeshTopology.Points, 6 * settings.segments * settings.sectors);
The Settings class just stores some properties of the Mesh. I already tried drawing with MeshTopology.Triangles but it didn't work either.
Answer by DarkVerse · Dec 12, 2018 at 03:56 AM
Hi, Did you ever get this figured out @Lukas-Brunner ? I have a similar problem with DrawProcedural drawing nothing. If I use Vulkan it works but OpenGLES3 doesn't (there are some reasons I want to use OpenGLES3 if possible).
Mark.
Unfortunately not. This was part of a students project, so I just decided to use a geometry shader and go with a simpler shape with less vertices to circumvent the problem.