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;








0















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):



enter image description here



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.










share|improve this question






















  • 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

















0















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):



enter image description here



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.










share|improve this question






















  • 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













0












0








0


0






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):



enter image description here



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.










share|improve this question














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):



enter image description here



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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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












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
);



);













draft saved

draft discarded


















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















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현