Fix turbulence module in GPU particles far away from world origin
#1944
This commit is contained in:
@@ -66,12 +66,14 @@ bool GPUParticles::Init(ParticleEmitter* owner, MemoryReadStream& shaderCacheStr
|
||||
LOG(Warning, "Missing valid GPU particles constant buffer.");
|
||||
return true;
|
||||
}
|
||||
if (cb0->GetSize() < sizeof(GPUParticlesData))
|
||||
const int32 cbSize = cb0->GetSize();
|
||||
if (cbSize < sizeof(GPUParticlesData))
|
||||
{
|
||||
LOG(Warning, "Invalid size GPU particles constant buffer. required {0} bytes but got {1}", sizeof(GPUParticlesData), cb0->GetSize());
|
||||
LOG(Warning, "Invalid size GPU particles constant buffer. required {0} bytes but got {1}", sizeof(GPUParticlesData), cbSize);
|
||||
return true;
|
||||
}
|
||||
_cbData.Resize(cb0->GetSize());
|
||||
_cbData.Resize(cbSize);
|
||||
Platform::MemoryClear(_cbData.Get(), cbSize);
|
||||
|
||||
// Load material parameters
|
||||
if (_params.Load(materialParamsStream))
|
||||
|
||||
@@ -321,23 +321,25 @@ float3 CustomNoise3D(float3 p)
|
||||
float c = CustomNoise(p + float3(0.0f, 0.0f, 0.0001f));
|
||||
|
||||
float3 grad = float3(o - a, o - b, o - c);
|
||||
float3 other = abs(grad.zxy);
|
||||
return normalize(cross(grad,other));
|
||||
float3 ret = cross(grad, abs(grad.zxy));
|
||||
if (length(ret) <= 0.0001f) return float3(0.0f, 0.0f, 0.0f);
|
||||
return normalize(ret);
|
||||
}
|
||||
|
||||
float3 CustomNoise3D(float3 position, int octaves, float roughness)
|
||||
{
|
||||
float weight = 0.0f;
|
||||
float3 noise = float3(0.0, 0.0, 0.0);
|
||||
float3 noise = float3(0.0f, 0.0f, 0.0f);
|
||||
float scale = 1.0f;
|
||||
roughness = lerp(2.0f, 0.2f, roughness);
|
||||
for (int i = 0; i < octaves; i++)
|
||||
{
|
||||
float curWeight = pow((1.0 - ((float)i / octaves)), lerp(2.0, 0.2, roughness));
|
||||
float curWeight = pow((1.0f - ((float)i / (float)octaves)), roughness);
|
||||
noise += CustomNoise3D(position * scale) * curWeight;
|
||||
weight += curWeight;
|
||||
scale *= 1.72531;
|
||||
scale *= 1.72531f;
|
||||
}
|
||||
return noise / weight;
|
||||
return noise / max(weight, 0.0001f);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user