Permalink
Browse files

now it looks like a fluid

  • Loading branch information...
1 parent ca7facb commit 170114b849d25e87d70add3235325c981c9b2897 @hrvthzs committed Nov 22, 2011
View
@@ -46,6 +46,7 @@ CUFILES := \
# CUDA dependency files
CU_DEPS := \
+ src/colors.cu \
src/boundary.cu \
src/boundary_walls.cu \
src/grid_utils.cu \
View
@@ -1,26 +1,12 @@
#version 150
-in vec4 color;
-in vec2 vTextCoord;
+in vec4 col;
+
out vec4 fragColor;
void main()
{
vec4 c = vec4(0.09, 0.31, 0.98, 1.0);
- const vec3 lightDir = vec3(0.577, 0.577, 0.577);
-
- // calculate normal from texture coordinates
- //vec3 N;
- //N.xy = vTextCoord.xy*vec2(2.0, -2.0) + vec2(-1.0, 1.0);
- //float mag = dot(N.xy, N.xy);
- //if (mag > 1.0) discard; // kill pixels outside circle
- //N.z = sqrt(1.0-mag);
-
- // calculate lighting
- //float diffuse = max(1.0, dot(lightDir, N));
-
-
- //fragColor = c * diffuse;
- fragColor = c;
+ fragColor = abs(col);
}
View
@@ -1,18 +1,20 @@
#version 130
in vec4 position;
+in vec4 color;
uniform mat4 mvp;
uniform mat4 mv;
uniform float pointRadius;
uniform float pointScale;
-out vec2 vTexCoord;
+out vec4 col;
void main()
{
vec3 posEye = vec3(mv * position);
float dist = length(posEye);
- //vTexCoord = gl_MultiTexCoord0.xy;
+
gl_PointSize = pointScale / (pointRadius * dist);
gl_Position = mvp * vec4(position);
+ col = color;
}
@@ -12,7 +12,7 @@ namespace Particles {
Renderer::Renderer(Simulator* simulator) {
this->_simulator = simulator;
- this->_numParticles = 16300;
+ this->_numParticles = 27*27*27;
this->_animate = false;
this->_deltaTime = 0.0;
@@ -237,6 +237,8 @@ namespace Particles {
this->_positionAttribute =
this->_shaderProgram->getAttributeLocation("position");
+ this->_colorAttribute =
+ this->_shaderProgram->getAttributeLocation("color");
this->_pointScale =
this->_shaderProgram->getUniformLocation("pointScale");
@@ -256,6 +258,8 @@ namespace Particles {
*/
this->_vbo = this->_simulator->getPositionsVBO();
+ this->_colorsVBO = this->_simulator->getColorsVBO();
+
}
////////////////////////////////////////////////////////////////////////////
@@ -322,16 +326,18 @@ namespace Particles {
glUniformMatrix4fv(this->_mvUniform, 1, GL_FALSE, glm::value_ptr(mv));
glUniformMatrix4fv(this->_mvpUniform, 1, GL_FALSE, glm::value_ptr(mvp));
glEnableVertexAttribArray(this->_positionAttribute);
+ glEnableVertexAttribArray(this->_colorAttribute);
glUniform1f(
this->_pointScale,
this->_windowWidth / tanf(45.0f*0.5f*(float)M_PI/180.0f)
);
//cout << (this->_windowWidth / tanf(45.0f*(float)M_PI/180.0f)) << endl;
- glUniform1f(this->_pointRadius, 150.f);
+ glUniform1f(this->_pointRadius, 200.f);
+
+ //TODO create VAO for VBOs and attributes
// Draw data
- //glBindBuffer(GL_ARRAY_BUFFER, this->_vbo);
glBindBuffer(GL_ARRAY_BUFFER, this->_vbo);
glVertexAttribPointer(
this->_positionAttribute,
@@ -342,6 +348,17 @@ namespace Particles {
(void*) 0
);
+ glBindBuffer(GL_ARRAY_BUFFER, this->_colorsVBO);
+ glVertexAttribPointer(
+ this->_colorAttribute,
+ 4,
+ GL_FLOAT,
+ GL_FALSE,
+ 0,
+ (void*) 0
+ );
+
+
glDrawArrays(GL_POINTS, 0, this->_numParticles);
glDisable(GL_POINT_SPRITE_ARB);
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);
@@ -71,6 +71,7 @@ namespace Particles {
SDL_Surface* _SDLSurface;
GLuint _positionAttribute;
+ GLuint _colorAttribute;
GLuint _mvpUniform;
GLuint _mvUniform;
GLuint _pointScale;
@@ -94,6 +95,7 @@ namespace Particles {
unsigned int _numParticles;
GLuint _vbo;
+ GLuint _colorsVBO;
bool _animate;
float _deltaTime;
@@ -36,4 +36,10 @@ namespace Particles {
////////////////////////////////////////////////////////////////////////////
+ GLuint Simulator::getColorsVBO() {
+ return this->_colorsVBO;
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+
};
@@ -18,7 +18,9 @@ namespace Particles{
virtual void stop() = 0;
virtual void update() = 0;
virtual float* getPositions() = 0;
+ virtual float* getColors() = 0;
virtual GLuint getPositionsVBO();
+ virtual GLuint getColorsVBO();
virtual void bindBuffers() = 0;
virtual void unbindBuffers() = 0;
unsigned int getNumParticles();
@@ -31,6 +33,7 @@ namespace Particles{
unsigned int _numParticles;
GLuint _positionsVBO;
+ GLuint _colorsVBO;
};
};
View
@@ -53,7 +53,7 @@ namespace SPH {
cudaPrecalcParams.poly6Coeff *
data.density;
- density = max(1.0, density);
+ density = max(1.0f, density);
data.sorted.density[index] = density;
data.sorted.pressure[index] =
View
@@ -37,13 +37,13 @@ namespace SPH {
float3 veleval = make_float3(sortedData.veleval[index]);
float3 force = make_float3(sortedData.force[index]);
- float3 pressure = make_float3(sortedData.pressure[index]);
+ //float pressure = sortedData.pressure[index];
float3 externalForce = make_float3(0.0f, 0.0f, 0.0f);
externalForce.y -= 9.8f;
// add no-penetration force due to "walls"
- /*externalForce += Boundary::Walls::calculateWallsNoPenetrationForce(
+ externalForce += Boundary::Walls::calculateWallsNoPenetrationForce(
position, veleval,
cudaGridParams.min,
cudaGridParams.max,
@@ -61,9 +61,6 @@ namespace SPH {
cudaFluidParams.frictionKinetic/deltaTime,
cudaFluidParams.frictionStaticLimit,
cudaFluidParams.scaleToSimulation);
- */
-
-
float3 f = force + externalForce;
@@ -74,42 +71,43 @@ namespace SPH {
}
float3 vnext = velocity + f * deltaTime;
- veleval = (velocity + vnext) * 0.5;
+ veleval = (velocity + vnext) * 0.5f;
velocity = veleval;
position += vnext * (deltaTime / cudaFluidParams.scaleToSimulation);
uint sortedIndex = gridData.index[index];
- if (position.x < cudaGridParams.min.x) {
+ /*if (position.x < cudaGridParams.min.x) {
position.x = cudaGridParams.min.x;
- //velocity *= -cudaFluidParams.boundaryDampening;
+ velocity *= -cudaFluidParams.boundaryDampening;
}
if (position.x > cudaGridParams.max.x) {
position.x = cudaGridParams.max.x;
- //velocity *= -cudaFluidParams.boundaryDampening;
+ velocity *= -cudaFluidParams.boundaryDampening;
}
if (position.y < cudaGridParams.min.y) {
position.y = cudaGridParams.min.y;
- //velocity *= -cudaFluidParams.boundaryDampening;
+ velocity *= -cudaFluidParams.boundaryDampening;
}
if (position.y > cudaGridParams.max.y) {
position.y = cudaGridParams.max.y;
- //velocity *= -cudaFluidParams.boundaryDampening;
+ velocity *= -cudaFluidParams.boundaryDampening;
}
if (position.z < cudaGridParams.min.z) {
position.z = cudaGridParams.min.z;
- //velocity *= -cudaFluidParams.boundaryDampening;
+ velocity *= -cudaFluidParams.boundaryDampening;
}
if (position.z > cudaGridParams.max.z) {
position.z = cudaGridParams.max.z;
- //velocity *= -cudaFluidParams.boundaryDampening;
- }
+ velocity *= -cudaFluidParams.boundaryDampening;
+ }*/
- data.position[sortedIndex] = make_float4(position, 1.0);
- data.velocity[sortedIndex] = make_float4(velocity, 1.0);
- data.veleval[sortedIndex] = make_float4(veleval, 1.0);
+ data.position[sortedIndex] = make_float4(position, 1.0f);
+ data.velocity[sortedIndex] = make_float4(velocity, 1.0f);
+ data.veleval[sortedIndex] = make_float4(veleval, 1.0f);
+ data.color[sortedIndex] = make_float4(0.09f, 0.31f, 0.98f, 1.0f);
}
////////////////////////////////////////////////////////////////////////
@@ -44,7 +44,7 @@ class Viscosity {
static __device__ __host__
float getLaplacianVariable(float smoothLen, float3 r, float rLen) {
- return 1.0 - (rLen / smoothLen);
+ return 1.0f - (rLen / smoothLen);
}
};
Oops, something went wrong.

0 comments on commit 170114b

Please sign in to comment.