Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG REPORT and SOLUTION: Wind calculation #47

Open
KondeU opened this issue Apr 30, 2022 · 0 comments
Open

BUG REPORT and SOLUTION: Wind calculation #47

KondeU opened this issue Apr 30, 2022 · 0 comments

Comments

@KondeU
Copy link

KondeU commented Apr 30, 2022

Hi there,

In the v4.1.0, there is a serious bug in the wind calculation. In fact, the wind does not work currently. The bug and its fix method are as follows.

1: In the sample, where the wind magnitude is not set at all, m_windMagnitude is only be set to 0.0f during initialization, however m_clampPositionDelta is not used at all, but it can be configured in the ImGUI.

// wind
float m_windMagnitude;
float m_windDirection[3];
float m_windAngleRadians;
float m_clampPositionDelta;

m_windMagnitude(0),

ImGui::SliderFloat("Clamp Position Delta", &simulationSettings->m_clampPositionDelta, 0.0f, 20.0f);

So we can modify the above code to these.

image

2: When calculating the displacement caused by wind, the effect is a vector with magnitude. The shader directly calculates the cross product of the unnormalized v and w, where v is the hair strand vector (with magnitude and direction), and w is wind vector (with magnitude and direction).

float a = ((float)(globalStrandIndex % 20))/20.0f;
float3 w = a*g_Wind.xyz + (1.0f-a)*g_Wind1.xyz + a*g_Wind2.xyz + (1.0f-a)*g_Wind3.xyz;
uint sharedIndex = localVertexIndex * numOfStrandsPerThreadGroup + localStrandIndex;
float3 v = sharedPos[sharedIndex].xyz - sharedPos[sharedIndex+numOfStrandsPerThreadGroup].xyz;
float3 force = -cross(cross(v, w), v);
sharedPos[sharedIndex].xyz += force*g_TimeStep*g_TimeStep;

The vector cross product result is the displacement direction, but the value of each component in the vector has no practical significance. So we need to split into two parts to calculate separately in here, as shown below.

image

After modifying the code as shown above, the wind calculation will be correct and affect the hair strands.

3: The wind calculation and length constraints use the same pass, the length constraints will be iteratively calculated(dispatch multiple times), but the wind calculation does not need iterate, so we need to separate this pass to the wind calculation pass and the length constraints pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant