Here are the examples of the csharp api FluidSim2DProject.FluidSim.ApplyBuoyancy(UnityEngine.RenderTexture, UnityEngine.RenderTexture, UnityEngine.RenderTexture, UnityEngine.RenderTexture, float) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
19
View Source File : FluidSim.cs
License : MIT License
Project Creator : Scrawk
License : MIT License
Project Creator : Scrawk
void FixedUpdate()
{
//Obstacles only need to be added once unless changed.
AddObstacles();
//Set the density field and obstacle color.
m_guiMat.SetColor("_FluidColor", m_fluidColor);
m_guiMat.SetColor("_ObstacleColor", m_obstacleColor);
int READ = 0;
int WRITE = 1;
float dt = 0.125f;
//Advect velocity against its self
Advect(m_velocityTex[READ], m_velocityTex[READ], m_velocityTex[WRITE], m_velocityDissipation, dt);
//Advect temperature against velocity
Advect(m_velocityTex[READ], m_temperatureTex[READ], m_temperatureTex[WRITE], m_temperatureDissipation, dt);
//Advect density against velocity
Advect(m_velocityTex[READ], m_densityTex[READ], m_densityTex[WRITE], m_densityDissipation, dt);
Swap(m_velocityTex);
Swap(m_temperatureTex);
Swap(m_densityTex);
//Determine how the flow of the fluid changes the velocity
ApplyBuoyancy(m_velocityTex[READ], m_temperatureTex[READ], m_densityTex[READ], m_velocityTex[WRITE], dt);
Swap(m_velocityTex);
//Refresh the impluse of density and temperature
ApplyImpulse(m_temperatureTex[READ], m_temperatureTex[WRITE], m_implusePos, m_impluseRadius, m_impulseTemperature);
ApplyImpulse(m_densityTex[READ], m_densityTex[WRITE], m_implusePos, m_impluseRadius, m_impulseDensity);
Swap(m_temperatureTex);
Swap(m_densityTex);
//If left click down add impluse, if right click down remove impulse from mouse pos.
if(Input.GetMouseButton(0) || Input.GetMouseButton(1))
{
Vector2 pos = Input.mousePosition;
pos.x -= m_rect.xMin;
pos.y -= m_rect.yMin;
pos.x /= m_rect.width;
pos.y /= m_rect.height;
float sign = (Input.GetMouseButton(0)) ? 1.0f : -1.0f;
ApplyImpulse(m_temperatureTex[READ], m_temperatureTex[WRITE], pos, m_mouseImpluseRadius, m_impulseTemperature);
ApplyImpulse(m_densityTex[READ], m_densityTex[WRITE], pos, m_mouseImpluseRadius, m_impulseDensity * sign);
Swap(m_temperatureTex);
Swap(m_densityTex);
}
//Calculates how divergent the velocity is
ComputeDivergence(m_velocityTex[READ], m_divergenceTex);
ClearSurface(m_pressureTex[READ]);
int i = 0;
for (i = 0; i < m_numJacobiIterations; ++i)
{
Jacobi(m_pressureTex[READ], m_divergenceTex, m_pressureTex[WRITE]);
Swap(m_pressureTex);
}
//Use the pressure tex that was last rendered into. This computes divergence free velocity
SubtractGradient(m_velocityTex[READ], m_pressureTex[READ], m_velocityTex[WRITE]);
Swap(m_velocityTex);
//Render the tex you want to see into gui tex. Will only use the red channel
m_guiMat.SetTexture("_Obstacles", m_obstaclesTex);
Graphics.Blit(m_densityTex[READ], m_guiTex, m_guiMat);
}