nanogui GLShader C++ render cloth but looks thin — how to increase thickness? The 2019 Stack Overflow Developer Survey Results Are InHow do you render primitives as wireframes in OpenGL?How do you declare an interface in C++?How can I profile C++ code running on Linux?How to use the PI constant in C++C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?OpenGL draw (color) things oddly, fragment shader messes things up?glVertexAttribPointer: normals being drawn instead of verticesSelf lit diffuse shading - interpolating normals per fragmentWider and smoother lines in Metal shaderNormalmapping only “working” in negative axis
Worn-tile Scrabble
One word riddle: Vowel in the middle
Why is the maximum length of OpenWrt’s root password 8 characters?
Is an up-to-date browser secure on an out-of-date OS?
Is flight data recorder erased after every flight?
Why do we hear so much about the Trump administration deciding to impose and then remove tariffs?
Feature engineering suggestion required
Right tool to dig six foot holes?
Is there a symbol for a right arrow with a square in the middle?
What to do when moving next to a bird sanctuary with a loosely-domesticated cat?
Aging parents with no investments
Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?
Have you ever entered Singapore using a different passport or name?
How to deal with fear of taking dependencies
Geography at the pixel level
The difference between dialogue marks
Why can Shazam fly?
What is the accessibility of a package's `Private` context variables?
Falsification in Math vs Science
Did Section 31 appear in Star Trek: The Next Generation?
How to notate time signature switching consistently every measure
FPGA - DIY Programming
"as much details as you can remember"
A poker game description that does not feel gimmicky
nanogui GLShader C++ render cloth but looks thin — how to increase thickness?
The 2019 Stack Overflow Developer Survey Results Are InHow do you render primitives as wireframes in OpenGL?How do you declare an interface in C++?How can I profile C++ code running on Linux?How to use the PI constant in C++C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?OpenGL draw (color) things oddly, fragment shader messes things up?glVertexAttribPointer: normals being drawn instead of verticesSelf lit diffuse shading - interpolating normals per fragmentWider and smoother lines in Metal shaderNormalmapping only “working” in negative axis
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am working on a cloth simulator. It models cloth as a grid of points with spring mass constraints between them. For example, it has similar concepts as described in this tutorial.
For rendering, I am using someone else's code which uses nanogui GLShader objects. It has the option to render a cloth in wireframe, and "smoother" options via two options (the latter is what we're interested in, 'phong' shaders. Here are some relevant code snippets from clothSimulator.h
and clothSimulator.cpp
:
#ifndef CGL_CLOTH_SIMULATOR_H
#define CGL_CLOTH_SIMULATOR_H
#include <nanogui/nanogui.h>
#include <zmq.hpp>
#include "camera.h"
#include "cloth.h"
#include "collision/collisionObject.h"
using namespace nanogui;
class ClothSimulator {
private:
virtual void initGUI(Screen *screen);
void drawWireframe(GLShader &shader);
void drawNormals(GLShader &shader);
void drawPhong(GLShader &shader);
// OpenGL attributes
enum e_shader WIREFRAME = 0, NORMALS = 1, PHONG = 2 ;
e_shader activeShader = WIREFRAME;
vector<GLShader> shaders;
GLShader wireframeShader;
GLShader normalShader;
GLShader phongShader;
// a bunch of other stuff here ...
And in the cpp file:
// a bunch of other stuff above ...
void ClothSimulator::drawPhong(GLShader &shader)
int num_tris = cloth->clothMesh->triangles.size();
MatrixXf positions(3, num_tris * 3);
MatrixXf normals(3, num_tris * 3);
for (int i = 0; i < num_tris; i++)
Triangle *tri = cloth->clothMesh->triangles[i];
Vector3D p1 = tri->pm1->position;
Vector3D p2 = tri->pm2->position;
Vector3D p3 = tri->pm3->position;
Vector3D n1 = tri->pm1->normal();
Vector3D n2 = tri->pm2->normal();
Vector3D n3 = tri->pm3->normal();
positions.col(i * 3) << p1.x, p1.y, p1.z;
positions.col(i * 3 + 1) << p2.x, p2.y, p2.z;
positions.col(i * 3 + 2) << p3.x, p3.y, p3.z;
normals.col(i * 3) << n1.x, n1.y, n1.z;
normals.col(i * 3 + 1) << n2.x, n2.y, n2.z;
normals.col(i * 3 + 2) << n3.x, n3.y, n3.z;
Vector3D cp = camera.position();
shader.setUniform("in_color", color);
shader.setUniform("eye", Vector3f(cp.x, cp.y, cp.z));
shader.setUniform("light", Vector3f(0.5, 2, 2));
shader.uploadAttrib("in_position", positions);
shader.uploadAttrib("in_normal", normals);
shader.drawArray(GL_TRIANGLES, 0, num_tris * 3);
// a bunch of other stuff below
The general idea appears to be to take all the points, and render them as triangles using the shader methods. It seems like the shader.drawArray
method appears to be important. Unfortunately I don't know what options I can supply to it. The documentation for the method appears to be limited, if I am using the right link.
The way I have it now, the cloth renders like this (an example):
However, this renders a very "thin" piece of cloth. I am hoping to increase the thickness of the cloth in the renderer. Should I be adjusting the arguments that I pass to drawArray
? Or adjust how I initialize the shader objects themselves? The tutorial I linked to earlier above actually has a part on "quilting" the cloth -- would that be the most straightforward (or only?) solution?
I hope this conveys the basics of what I'm hoping to ask. Please let me know if I can do something to make it easier to understand.
c++ opengl shader
add a comment |
I am working on a cloth simulator. It models cloth as a grid of points with spring mass constraints between them. For example, it has similar concepts as described in this tutorial.
For rendering, I am using someone else's code which uses nanogui GLShader objects. It has the option to render a cloth in wireframe, and "smoother" options via two options (the latter is what we're interested in, 'phong' shaders. Here are some relevant code snippets from clothSimulator.h
and clothSimulator.cpp
:
#ifndef CGL_CLOTH_SIMULATOR_H
#define CGL_CLOTH_SIMULATOR_H
#include <nanogui/nanogui.h>
#include <zmq.hpp>
#include "camera.h"
#include "cloth.h"
#include "collision/collisionObject.h"
using namespace nanogui;
class ClothSimulator {
private:
virtual void initGUI(Screen *screen);
void drawWireframe(GLShader &shader);
void drawNormals(GLShader &shader);
void drawPhong(GLShader &shader);
// OpenGL attributes
enum e_shader WIREFRAME = 0, NORMALS = 1, PHONG = 2 ;
e_shader activeShader = WIREFRAME;
vector<GLShader> shaders;
GLShader wireframeShader;
GLShader normalShader;
GLShader phongShader;
// a bunch of other stuff here ...
And in the cpp file:
// a bunch of other stuff above ...
void ClothSimulator::drawPhong(GLShader &shader)
int num_tris = cloth->clothMesh->triangles.size();
MatrixXf positions(3, num_tris * 3);
MatrixXf normals(3, num_tris * 3);
for (int i = 0; i < num_tris; i++)
Triangle *tri = cloth->clothMesh->triangles[i];
Vector3D p1 = tri->pm1->position;
Vector3D p2 = tri->pm2->position;
Vector3D p3 = tri->pm3->position;
Vector3D n1 = tri->pm1->normal();
Vector3D n2 = tri->pm2->normal();
Vector3D n3 = tri->pm3->normal();
positions.col(i * 3) << p1.x, p1.y, p1.z;
positions.col(i * 3 + 1) << p2.x, p2.y, p2.z;
positions.col(i * 3 + 2) << p3.x, p3.y, p3.z;
normals.col(i * 3) << n1.x, n1.y, n1.z;
normals.col(i * 3 + 1) << n2.x, n2.y, n2.z;
normals.col(i * 3 + 2) << n3.x, n3.y, n3.z;
Vector3D cp = camera.position();
shader.setUniform("in_color", color);
shader.setUniform("eye", Vector3f(cp.x, cp.y, cp.z));
shader.setUniform("light", Vector3f(0.5, 2, 2));
shader.uploadAttrib("in_position", positions);
shader.uploadAttrib("in_normal", normals);
shader.drawArray(GL_TRIANGLES, 0, num_tris * 3);
// a bunch of other stuff below
The general idea appears to be to take all the points, and render them as triangles using the shader methods. It seems like the shader.drawArray
method appears to be important. Unfortunately I don't know what options I can supply to it. The documentation for the method appears to be limited, if I am using the right link.
The way I have it now, the cloth renders like this (an example):
However, this renders a very "thin" piece of cloth. I am hoping to increase the thickness of the cloth in the renderer. Should I be adjusting the arguments that I pass to drawArray
? Or adjust how I initialize the shader objects themselves? The tutorial I linked to earlier above actually has a part on "quilting" the cloth -- would that be the most straightforward (or only?) solution?
I hope this conveys the basics of what I'm hoping to ask. Please let me know if I can do something to make it easier to understand.
c++ opengl shader
I may have misundertood your question, but it seems to me that you are drawing a surface, a triangular mesh representing a piece of cloth, and you are ysking how to draw a solid object, adding a thickness (extruding a little bit?) that surface. Is it right?
– Bob__
Mar 22 at 9:43
@Bob__ Yes, you are right.
– ComputerScientist
Mar 22 at 16:22
add a comment |
I am working on a cloth simulator. It models cloth as a grid of points with spring mass constraints between them. For example, it has similar concepts as described in this tutorial.
For rendering, I am using someone else's code which uses nanogui GLShader objects. It has the option to render a cloth in wireframe, and "smoother" options via two options (the latter is what we're interested in, 'phong' shaders. Here are some relevant code snippets from clothSimulator.h
and clothSimulator.cpp
:
#ifndef CGL_CLOTH_SIMULATOR_H
#define CGL_CLOTH_SIMULATOR_H
#include <nanogui/nanogui.h>
#include <zmq.hpp>
#include "camera.h"
#include "cloth.h"
#include "collision/collisionObject.h"
using namespace nanogui;
class ClothSimulator {
private:
virtual void initGUI(Screen *screen);
void drawWireframe(GLShader &shader);
void drawNormals(GLShader &shader);
void drawPhong(GLShader &shader);
// OpenGL attributes
enum e_shader WIREFRAME = 0, NORMALS = 1, PHONG = 2 ;
e_shader activeShader = WIREFRAME;
vector<GLShader> shaders;
GLShader wireframeShader;
GLShader normalShader;
GLShader phongShader;
// a bunch of other stuff here ...
And in the cpp file:
// a bunch of other stuff above ...
void ClothSimulator::drawPhong(GLShader &shader)
int num_tris = cloth->clothMesh->triangles.size();
MatrixXf positions(3, num_tris * 3);
MatrixXf normals(3, num_tris * 3);
for (int i = 0; i < num_tris; i++)
Triangle *tri = cloth->clothMesh->triangles[i];
Vector3D p1 = tri->pm1->position;
Vector3D p2 = tri->pm2->position;
Vector3D p3 = tri->pm3->position;
Vector3D n1 = tri->pm1->normal();
Vector3D n2 = tri->pm2->normal();
Vector3D n3 = tri->pm3->normal();
positions.col(i * 3) << p1.x, p1.y, p1.z;
positions.col(i * 3 + 1) << p2.x, p2.y, p2.z;
positions.col(i * 3 + 2) << p3.x, p3.y, p3.z;
normals.col(i * 3) << n1.x, n1.y, n1.z;
normals.col(i * 3 + 1) << n2.x, n2.y, n2.z;
normals.col(i * 3 + 2) << n3.x, n3.y, n3.z;
Vector3D cp = camera.position();
shader.setUniform("in_color", color);
shader.setUniform("eye", Vector3f(cp.x, cp.y, cp.z));
shader.setUniform("light", Vector3f(0.5, 2, 2));
shader.uploadAttrib("in_position", positions);
shader.uploadAttrib("in_normal", normals);
shader.drawArray(GL_TRIANGLES, 0, num_tris * 3);
// a bunch of other stuff below
The general idea appears to be to take all the points, and render them as triangles using the shader methods. It seems like the shader.drawArray
method appears to be important. Unfortunately I don't know what options I can supply to it. The documentation for the method appears to be limited, if I am using the right link.
The way I have it now, the cloth renders like this (an example):
However, this renders a very "thin" piece of cloth. I am hoping to increase the thickness of the cloth in the renderer. Should I be adjusting the arguments that I pass to drawArray
? Or adjust how I initialize the shader objects themselves? The tutorial I linked to earlier above actually has a part on "quilting" the cloth -- would that be the most straightforward (or only?) solution?
I hope this conveys the basics of what I'm hoping to ask. Please let me know if I can do something to make it easier to understand.
c++ opengl shader
I am working on a cloth simulator. It models cloth as a grid of points with spring mass constraints between them. For example, it has similar concepts as described in this tutorial.
For rendering, I am using someone else's code which uses nanogui GLShader objects. It has the option to render a cloth in wireframe, and "smoother" options via two options (the latter is what we're interested in, 'phong' shaders. Here are some relevant code snippets from clothSimulator.h
and clothSimulator.cpp
:
#ifndef CGL_CLOTH_SIMULATOR_H
#define CGL_CLOTH_SIMULATOR_H
#include <nanogui/nanogui.h>
#include <zmq.hpp>
#include "camera.h"
#include "cloth.h"
#include "collision/collisionObject.h"
using namespace nanogui;
class ClothSimulator {
private:
virtual void initGUI(Screen *screen);
void drawWireframe(GLShader &shader);
void drawNormals(GLShader &shader);
void drawPhong(GLShader &shader);
// OpenGL attributes
enum e_shader WIREFRAME = 0, NORMALS = 1, PHONG = 2 ;
e_shader activeShader = WIREFRAME;
vector<GLShader> shaders;
GLShader wireframeShader;
GLShader normalShader;
GLShader phongShader;
// a bunch of other stuff here ...
And in the cpp file:
// a bunch of other stuff above ...
void ClothSimulator::drawPhong(GLShader &shader)
int num_tris = cloth->clothMesh->triangles.size();
MatrixXf positions(3, num_tris * 3);
MatrixXf normals(3, num_tris * 3);
for (int i = 0; i < num_tris; i++)
Triangle *tri = cloth->clothMesh->triangles[i];
Vector3D p1 = tri->pm1->position;
Vector3D p2 = tri->pm2->position;
Vector3D p3 = tri->pm3->position;
Vector3D n1 = tri->pm1->normal();
Vector3D n2 = tri->pm2->normal();
Vector3D n3 = tri->pm3->normal();
positions.col(i * 3) << p1.x, p1.y, p1.z;
positions.col(i * 3 + 1) << p2.x, p2.y, p2.z;
positions.col(i * 3 + 2) << p3.x, p3.y, p3.z;
normals.col(i * 3) << n1.x, n1.y, n1.z;
normals.col(i * 3 + 1) << n2.x, n2.y, n2.z;
normals.col(i * 3 + 2) << n3.x, n3.y, n3.z;
Vector3D cp = camera.position();
shader.setUniform("in_color", color);
shader.setUniform("eye", Vector3f(cp.x, cp.y, cp.z));
shader.setUniform("light", Vector3f(0.5, 2, 2));
shader.uploadAttrib("in_position", positions);
shader.uploadAttrib("in_normal", normals);
shader.drawArray(GL_TRIANGLES, 0, num_tris * 3);
// a bunch of other stuff below
The general idea appears to be to take all the points, and render them as triangles using the shader methods. It seems like the shader.drawArray
method appears to be important. Unfortunately I don't know what options I can supply to it. The documentation for the method appears to be limited, if I am using the right link.
The way I have it now, the cloth renders like this (an example):
However, this renders a very "thin" piece of cloth. I am hoping to increase the thickness of the cloth in the renderer. Should I be adjusting the arguments that I pass to drawArray
? Or adjust how I initialize the shader objects themselves? The tutorial I linked to earlier above actually has a part on "quilting" the cloth -- would that be the most straightforward (or only?) solution?
I hope this conveys the basics of what I'm hoping to ask. Please let me know if I can do something to make it easier to understand.
c++ opengl shader
c++ opengl shader
asked Mar 22 at 3:58
ComputerScientistComputerScientist
5031716
5031716
I may have misundertood your question, but it seems to me that you are drawing a surface, a triangular mesh representing a piece of cloth, and you are ysking how to draw a solid object, adding a thickness (extruding a little bit?) that surface. Is it right?
– Bob__
Mar 22 at 9:43
@Bob__ Yes, you are right.
– ComputerScientist
Mar 22 at 16:22
add a comment |
I may have misundertood your question, but it seems to me that you are drawing a surface, a triangular mesh representing a piece of cloth, and you are ysking how to draw a solid object, adding a thickness (extruding a little bit?) that surface. Is it right?
– Bob__
Mar 22 at 9:43
@Bob__ Yes, you are right.
– ComputerScientist
Mar 22 at 16:22
I may have misundertood your question, but it seems to me that you are drawing a surface, a triangular mesh representing a piece of cloth, and you are ysking how to draw a solid object, adding a thickness (extruding a little bit?) that surface. Is it right?
– Bob__
Mar 22 at 9:43
I may have misundertood your question, but it seems to me that you are drawing a surface, a triangular mesh representing a piece of cloth, and you are ysking how to draw a solid object, adding a thickness (extruding a little bit?) that surface. Is it right?
– Bob__
Mar 22 at 9:43
@Bob__ Yes, you are right.
– ComputerScientist
Mar 22 at 16:22
@Bob__ Yes, you are right.
– ComputerScientist
Mar 22 at 16:22
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292702%2fnanogui-glshader-c-render-cloth-but-looks-thin-how-to-increase-thickness%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55292702%2fnanogui-glshader-c-render-cloth-but-looks-thin-how-to-increase-thickness%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I may have misundertood your question, but it seems to me that you are drawing a surface, a triangular mesh representing a piece of cloth, and you are ysking how to draw a solid object, adding a thickness (extruding a little bit?) that surface. Is it right?
– Bob__
Mar 22 at 9:43
@Bob__ Yes, you are right.
– ComputerScientist
Mar 22 at 16:22