Skip to content

Commit 4527237

Browse files
[p01] all settings on UI
1 parent 165a7ab commit 4527237

File tree

2 files changed

+61
-14
lines changed

2 files changed

+61
-14
lines changed

project01/scenecloth.cpp

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ SceneCloth::SceneCloth()
1919
: clothVao(0), numElements(0),
2020
nParticles(40, 40), clothSize(4.0f, 3.0f),
2121
time(0.0f), deltaT(0.0f), speed(200.0f), readBuf(0),
22-
wireframe(false), wind(false), windStrength(0.5), windDir(glm::vec3(0.2, 0, 0.6))
22+
lightDir(glm::vec3(0)), lightColor(glm::vec3(1)),
23+
specularity(0.2f), ambiant(0.2f), diffuse(0.8f), shininess(80),
24+
wireframe(false), gravity(glm::vec3(0, -10, 0)),
25+
particleMass(0.1), springK(2000), wind(false),
26+
windStrength(0.5), windDir(glm::vec3(0.2, 0, 0.6))
2327
{
2428
}
2529

@@ -32,14 +36,8 @@ void SceneCloth::initScene()
3236
initBuffers();
3337

3438
projection = glm::perspective(glm::radians(50.0f), (float)width / height, 1.0f, 100.0f);
35-
3639
renderProg.use();
37-
renderProg.setUniform("LightPosition", glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
38-
renderProg.setUniform("LightIntensity", glm::vec3(1.0f));
39-
renderProg.setUniform("Kd", glm::vec3(0.8f));
40-
renderProg.setUniform("Ka", glm::vec3(0.2f));
41-
renderProg.setUniform("Ks", glm::vec3(0.2f));
42-
renderProg.setUniform("Shininess", 80.0f);
40+
setLight();
4341

4442
computeProg.use();
4543
float dx = clothSize.x / (nParticles.x - 1);
@@ -174,10 +172,7 @@ void SceneCloth::render()
174172
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
175173

176174
computeProg.use();
177-
178-
computeProg.setUniform("HasWind", static_cast<float>(wind));
179-
computeProg.setUniform("WindStrength", windStrength);
180-
computeProg.setUniform("WindDir", windDir);
175+
setPhysics();
181176

182177
for (int i = 0; i < 1000; i++) {
183178
glDispatchCompute(nParticles.x / 10, nParticles.y / 10, 1);
@@ -199,6 +194,7 @@ void SceneCloth::render()
199194
// Now draw the scene
200195
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
201196
renderProg.use();
197+
setLight();
202198

203199
renderProg.setTexture("Tex", clothTexture, 0);
204200

@@ -214,7 +210,6 @@ void SceneCloth::render()
214210
}
215211

216212
void SceneCloth::setMatrices() {
217-
renderProg.use();
218213
glm::mat4 mv = view * model;
219214
glm::mat3 norm = glm::mat3(vec3(mv[0]), vec3(mv[1]), vec3(mv[2]));
220215

@@ -223,23 +218,62 @@ void SceneCloth::setMatrices() {
223218
renderProg.setUniform("MVP", projection * mv);
224219
}
225220

221+
void SceneCloth::setLight()
222+
{
223+
renderProg.setUniform("LightPosition", glm::vec4(lightDir, 1.0f));
224+
renderProg.setUniform("LightIntensity", lightColor);
225+
renderProg.setUniform("Kd", glm::vec3(diffuse));
226+
renderProg.setUniform("Ka", glm::vec3(ambiant));
227+
renderProg.setUniform("Ks", glm::vec3(specularity));
228+
renderProg.setUniform("Shininess", shininess);
229+
}
230+
231+
void SceneCloth::setPhysics()
232+
{
233+
computeProg.setUniform("Gravity", gravity);
234+
computeProg.setUniform("ParticleMass", particleMass);
235+
computeProg.setUniform("SpringK", springK);
236+
237+
computeProg.setUniform("HasWind", static_cast<float>(wind));
238+
computeProg.setUniform("WindStrength", windStrength);
239+
computeProg.setUniform("WindDir", windDir);
240+
}
241+
226242
void SceneCloth::resize(int w, int h)
227243
{
228244
glViewport(0, 0, w, h);
229245
width = w;
230246
height = h;
247+
projection = glm::perspective(glm::radians(50.0f), (float)width / height, 1.0f, 100.0f);
231248
}
232249

233250
void SceneCloth::uiUpdate()
234251
{
235252
ImGui::Begin("GUI");
236253
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
237254
ImGui::Checkbox("Wireframe", &wireframe);
255+
if (ImGui::CollapsingHeader("Particles", ImGuiTreeNodeFlags_DefaultOpen))
256+
{
257+
ImGui::SliderFloat3("Gravity", &gravity[0], -20.0f, 20.0f);
258+
ImGui::SliderFloat("ParticleMass", &particleMass, 0.1f, 0.5f);
259+
ImGui::SliderFloat("SpringK", &springK, 500.0f, 5000.0f);
260+
}
261+
238262
if (ImGui::CollapsingHeader("Wind", ImGuiTreeNodeFlags_DefaultOpen))
239263
{
240264
ImGui::Checkbox("Enable", &wind);
241265
ImGui::SliderFloat("Strength", &windStrength, 0.0f, 10.0f);
242-
ImGui::SliderFloat3("Direction", &windDir[0], 0.0f, 1.0f);
266+
ImGui::SliderFloat3("Wind Direction", &windDir[0], -1.0f, 1.0f);
267+
}
268+
269+
if (ImGui::CollapsingHeader("Light", ImGuiTreeNodeFlags_DefaultOpen))
270+
{
271+
ImGui::SliderFloat3("Light Direction", &lightDir[0], 0.0f, 1.0f);
272+
ImGui::ColorPicker3("Color", &lightColor[0]);
273+
ImGui::SliderFloat("Ambiant", &ambiant, 0.0f, 1.0f);
274+
ImGui::SliderFloat("Diffuse", &diffuse, 0.0f, 1.0f);
275+
ImGui::SliderFloat("Specular", &specularity, 0.0f, 1.0f);
276+
ImGui::SliderFloat("Shininess", &shininess, 0.0f, 200.0f);
243277
}
244278

245279
ImGui::End();

project01/scenecloth.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class SceneCloth : public Scene
2121
void compileAndLinkShader();
2222
void initBuffers();
2323
void setMatrices();
24+
void setLight();
25+
void setPhysics();
2426

2527
private:
2628
GLSLProgram renderProg, computeProg, computeProgNorm;
@@ -38,6 +40,17 @@ class SceneCloth : public Scene
3840
GLuint normBuf, elBuf, tcBuf;
3941

4042
bool wireframe;
43+
glm::vec3 lightDir;
44+
glm::vec3 lightColor;
45+
float ambiant;
46+
float diffuse;
47+
float specularity;
48+
float shininess;
49+
50+
glm::vec3 gravity;
51+
float particleMass;
52+
float springK;
53+
4154
bool wind;
4255
float windStrength;
4356
glm::vec3 windDir;

0 commit comments

Comments
 (0)