Compute Shader compile error from Texture3D.Sample()
I'm trying to sample a 3D noise texture that I generate elsewhere and pass to my ComputeShader. However, when compiling the following, all I get is "Shader error in 'DensityGenerator.compute': cannot map expression to cs_5_0 instruction set at DensityGenerator.compute(14) (on d3d11)".
I really haven't got a clue where to start with this. It looks right and the only way to get it to compile is to comment out line 14 (noiseVol.Sample(), specifically).
What obvious bug have I missed?
#pragma kernel Density
Texture3D<float4> noiseVol;
SamplerState samplerNoiseVol;
RWStructuredBuffer<float> voxels;
[numthreads(32,32,1)]
void Density (uint3 threadId : SV_DispatchThreadID, uint3 groupId : SV_GroupID)
{
int size = 32;
int3 voxPos = threadId; // Just rename this for the sake of clarity
float density = 0;//-voxPos.y;
density += noiseVol.Sample(samplerNoiseVol, voxPos, 0).z;
voxels[voxPos.x + voxPos.y*size + voxPos.z*size*size] = density;
}
Answer by navot · Nov 08, 2017 at 07:12 PM
Just ran into the same problem, so for anyone coming across this problem in the future, replacing
Texture.Sample(sampler, pos);
with
Texture.SampleLevel(sampler, pos, 0); //The 0 at the end is the mip level
fixed it for me
This helped me a lot with a similar problem (sampling a texture with a hardcoded SamplerState in a ComputeShader), thanks.
Your answer
Follow this Question
Related Questions
Code works in editor, but not on Android device(audio mixer) 1 Answer
Lift, gamma, gain Android colours completely wrong. 1 Answer
How do I generate and compile a compute shader in the editor? 0 Answers
How to control Music vs SFX vol using Master Mixer 0 Answers
How can i save random-generated maps during gameplay ? 1 Answer