Skip to content

Commit fe732a0

Browse files
authored
Merge pull request #1948 from Haydelj/clippingPlanes
Closes #1368
2 parents acafeba + 0f47d9a commit fe732a0

File tree

18 files changed

+554
-87
lines changed

18 files changed

+554
-87
lines changed

src/Externals/spire/es-render/IBOMan.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,19 @@ const IBOMan::IBOData& IBOMan::getIBOData(const std::string& assetName) const
8282
// GARBAGE COLLECTION
8383
//------------------------------------------------------------------------------
8484

85+
#define PRINT_IBO_GC 0
8586
void IBOMan::runGCAgainstVaidIDs(const std::set<GLuint>& validKeys)
8687
{
88+
#if PRINT_IBO_GC
89+
for(auto& key: validKeys)
90+
std::cout << " \e[33mValid Keys\e[00m: " << key << "\n";
91+
std::cout << "\n";
92+
93+
for(auto& key: mIBOData)
94+
std::cout<< " \e[31mCurrent Keys Pre-GC\e[00m: " << key.first << "\n";
95+
std::cout << "\n";
96+
#endif
97+
8798
// Every GLuint in validKeys should be in our map. If there is not, then
8899
// there is an error in the system, and it should be reported.
89100
// The reverse is not expected to be true, and is what we are attempting to
@@ -129,6 +140,12 @@ void IBOMan::runGCAgainstVaidIDs(const std::set<GLuint>& validKeys)
129140
mIBOData.erase(it++);
130141
GL(glDeleteBuffers(1, &idToErase));
131142
}
143+
144+
#if PRINT_IBO_GC
145+
for(auto& key: mIBOData)
146+
std::cout<< " \e[34mCurrent Keys Post-GC\e[00m: " << key.first << "\n";
147+
std::cout << "\n";
148+
#endif
132149
}
133150

134151
class IBOGarbageCollector :

src/Externals/spire/es-render/TextureMan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ namespace ren {
649649
// Find the asset name in mNameToGL and erase.
650650
mNameToGL.erase(mNameToGL.find(it->second));
651651

652-
std::cout << "Texture GC: " << it->second << std::endl;
652+
//std::cout << "Texture GC: " << it->second << std::endl;
653653

654654
// Erase our iterator and move on. Ensure we delete the program.
655655
GLuint idToErase = it->first;
@@ -681,7 +681,7 @@ namespace ren {
681681
// Find the asset name in mNameToGL and erase.
682682
mNameToGL.erase(mNameToGL.find(it->second));
683683

684-
std::cout << "Texture GC: " << it->second << std::endl;
684+
//std::cout << "Texture GC: " << it->second << std::endl;
685685

686686
// Erase our iterator and move on. Ensure we delete the program.
687687
GLuint idToErase = it->first;

src/Graphics/Glyphs/GlyphGeom.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique
151151
for (auto a : indices_)
152152
iboBuffer->write(a);
153153

154-
BBox newBBox;
154+
BBox newBBox;
155155

156156
const bool writeNormals = normals_.size() == points_.size();
157157
for (size_t i = 0; i < points_.size(); i++)
@@ -179,6 +179,9 @@ void GlyphGeom::buildObject(GeometryObjectSpire& geom, const std::string& unique
179179
} // no color writing otherwise
180180
}
181181

182+
if(!bbox.valid())
183+
newBBox.reset();
184+
182185
// If true, then the VBO will be placed on the GPU. We don't want to place
183186
// VBOs on the GPU when we are generating rendering lists.
184187
SpireVBO geomVBO(vboName, attribs, vboBufferSPtr, numVBOElements_, newBBox, true);

src/Interface/Modules/Render/ES/AssetBootstrap.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ class AssetBootstrap : public spire::EmptySystem
5858
if (std::shared_ptr<ren::ShaderMan> shaderMan = sm.lock()) {
5959
// Load shader we will use with the coordinate axes.
6060
shaderMan->loadVertexAndFragmentShader(core, cachedEntity, "Shaders/DirPhong");
61-
shaderMan->loadVertexAndFragmentShader(core, cachedEntity, "Shaders/DirPhongNoClipping");
62-
shaderMan->loadVertexAndFragmentShader(core, cachedEntity, "Shaders/UniformColor");
61+
shaderMan->loadVertexAndFragmentShader(core, cachedEntity, "Shaders/OrientationGlyph");
6362
}
6463

6564
// Note: We don't need to strictly store the coordinate axes entity.

src/Interface/Modules/Render/ES/SRCamera.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ namespace SCIRun {
141141
//----------------------------------------------------------------------------------------------
142142
void SRCamera::setClippingPlanes()
143143
{
144-
mRadius = (mSceneBBox.get_max() - mSceneBBox.get_min()).length() / 2.0f;
144+
//we could divide by 2.0 for tightest bound but here we divide by 1.0 to accomidate
145+
//for the clipping plane visualization
146+
mRadius = (mSceneBBox.get_max() - mSceneBBox.get_min()).length();
145147

146148
if(mRadius > 0.0)
147149
{

src/Interface/Modules/Render/ES/SRInterface.cc

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ namespace SCIRun {
854854
if (vbo.onGPU)
855855
{
856856
RENDERER_LOG("Generate vector of attributes to pass into the entity system: {}, {}", nameIndex, vbo.name);
857-
std::vector<std::tuple<std::string, size_t, bool>> attributeData;
857+
std::vector<std::tuple<std::string, size_t, bool >> attributeData;
858858
for (const auto& attribData : vbo.attributes)
859859
{
860860
attributeData.push_back(std::make_tuple(attribData.name, attribData.sizeInBytes, attribData.normalize));
@@ -1221,6 +1221,16 @@ namespace SCIRun {
12211221
mCore.renormalize(true);
12221222
}
12231223

1224+
//----------------------------------------------------------------------------------------------
1225+
bool SRInterface::hasObject(const std::string& object)
1226+
{
1227+
for (auto it = mSRObjects.begin(); it != mSRObjects.end(); ++it)
1228+
if (it->mName == object)
1229+
return true;
1230+
1231+
return false;
1232+
}
1233+
12241234
//----------------------------------------------------------------------------------------------
12251235
void SRInterface::addVBOToEntity(uint64_t entityID, const std::string& vboName)
12261236
{
@@ -1400,8 +1410,7 @@ namespace SCIRun {
14001410
{
14011411
GLuint arrowVBO = vboMan->hasVBO("Assets/arrow.geom");
14021412
GLuint arrowIBO = iboMan->hasIBO("Assets/arrow.geom");
1403-
//GLuint shader = shaderMan->getIDForAsset("Shaders/DirPhongNoClipping");
1404-
GLuint shader = shaderMan->getIDForAsset("Shaders/UniformColor");
1413+
GLuint shader = shaderMan->getIDForAsset("Shaders/OrientationGlyph");
14051414

14061415
// Bail if assets have not been loaded yet (asynchronous loading may take a
14071416
// few frames).
@@ -1481,13 +1490,7 @@ namespace SCIRun {
14811490

14821491
GLint locCamViewVec = glGetUniformLocation(shader, "uCamViewVec");
14831492
GLint locLightDirWorld = glGetUniformLocation(shader, "uLightDirWorld");
1484-
1485-
//GLint locAmbientColor = glGetUniformLocation(shader, "uAmbientColor");
1486-
//GLint locDiffuseColor = glGetUniformLocation(shader, "uDiffuseColor");
14871493
GLint locDiffuseColor = glGetUniformLocation(shader, "uColor");
1488-
//GLint locSpecularColor = glGetUniformLocation(shader, "uSpecularColor");
1489-
//GLint locSpecularPower = glGetUniformLocation(shader, "uSpecularPower");
1490-
14911494
GLint locProjIVObject = glGetUniformLocation(shader, "uProjIVObject");
14921495
GLint locObject = glGetUniformLocation(shader, "uObject");
14931496

@@ -1499,10 +1502,6 @@ namespace SCIRun {
14991502

15001503
mArrowAttribs.bind();
15011504

1502-
//GL(glUniform4f(locSpecularColor, 0.0f, 0.0f, 0.0f, 1.0f));
1503-
//GL(glUniform4f(locAmbientColor, 0.2f, 0.2f, 0.2f, 1.0f));
1504-
//GL(glUniform1f(locSpecularPower, 16.0f));
1505-
15061505
// X Axis (dark)
15071506
{
15081507
glm::mat4 xform = glm::rotate(glm::mat4(1.0f), glm::pi<float>() / 2.0f, glm::vec3(0.0, 1.0, 0.0));

src/Interface/Modules/Render/ES/SRInterface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ namespace SCIRun {
157157
void handleGeomObject(Graphics::Datatypes::GeometryHandle object, int port);
158158
// Remove all SCIRun 5 objects.
159159
void removeAllGeomObjects();
160+
bool hasObject(const std::string& object);
160161
// Garbage collect all invalid objects not given in the valid objects vector.
161162
void gcInvalidObjects(const std::vector<std::string>& validObjects);
162163
// Simple hash function. Modify if hash collisions occur due to string

src/Interface/Modules/Render/ES/shaders/DirPhong.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ uniform vec3 uLightDirWorld1; // Directional light (world space).
4444
uniform vec3 uLightDirWorld2; // Directional light (world space).
4545
uniform vec3 uLightDirWorld3; // Directional light (world space).
4646
uniform vec3 uLightColor0; // color of light 0
47-
uniform vec3 uLightColor1; // color of light 0
48-
uniform vec3 uLightColor2; // color of light 0
49-
uniform vec3 uLightColor3; // color of light 0
47+
uniform vec3 uLightColor1; // color of light 1
48+
uniform vec3 uLightColor2; // color of light 2
49+
uniform vec3 uLightColor3; // color of light 3
5050
uniform float uTransparency;
5151

5252
//clipping planes
@@ -77,7 +77,7 @@ varying vec4 vFogCoord; // for fog calculation
7777

7878
vec4 calculate_lighting(vec3 lightDirWorld, vec3 lightColor)
7979
{
80-
vec3 invLightDir = -lightDirWorld;
80+
vec3 invLightDir = -normalize(lightDirWorld);
8181
vec3 normal = normalize(vNormal);
8282

8383
if (gl_FrontFacing)

src/Interface/Modules/Render/ES/shaders/DirPhongCMap.fs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
uniform vec3 uCamViewVec; // Camera 'at' vector in world space
3838
uniform vec4 uAmbientColor; // Ambient color
39-
uniform vec4 uDiffuseColor; // Diffuse color
4039
uniform vec4 uSpecularColor; // Specular color
4140
uniform float uSpecularPower; // Specular power
4241
uniform vec3 uLightDirWorld0; // Directional light (world space).
@@ -89,9 +88,7 @@ vec4 calculate_lighting(vec3 lightDirWorld, vec3 lightColor)
8988
float specular = max(0.0, dot(reflection, uCamViewVec));
9089
specular = pow(specular, uSpecularPower);
9190

92-
vec4 diffuseColor = vColor;
93-
94-
return vec4(lightColor * (diffuse * diffuseColor.rgb + specular * uSpecularColor.rgb), 0.0);
91+
return vec4(lightColor * (diffuse * vColor.rgb + specular * uSpecularColor.rgb), 0.0);
9592
}
9693

9794
void main()
@@ -140,7 +137,7 @@ void main()
140137
discard;
141138
}
142139

143-
gl_FragColor = vec4(uAmbientColor.rgb * uDiffuseColor.rgb, uTransparency);
140+
gl_FragColor = vec4(uAmbientColor.rgb * vColor.rgb, uTransparency);
144141
if (length(uLightDirWorld0) > 0.0)
145142
gl_FragColor += calculate_lighting(uLightDirWorld0, uLightColor0);
146143
if (length(uLightDirWorld1) > 0.0)

src/Interface/Modules/Render/ES/shaders/DirPhongInSitu.fs

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ uniform vec4 uAmbientColor; // Ambient color
3939
uniform vec4 uDiffuseColor; // Diffuse color
4040
uniform vec4 uSpecularColor; // Specular color
4141
uniform float uSpecularPower; // Specular power
42-
uniform vec3 uLightDirWorld; // Directional light (world space).
42+
uniform vec3 uLightDirWorld0; // Directional light (world space).
43+
uniform vec3 uLightDirWorld1; // Directional light (world space).
44+
uniform vec3 uLightDirWorld2; // Directional light (world space).
45+
uniform vec3 uLightDirWorld3; // Directional light (world space).
46+
uniform vec3 uLightColor0; // color of light 0
47+
uniform vec3 uLightColor1; // color of light 1
48+
uniform vec3 uLightColor2; // color of light 2
49+
uniform vec3 uLightColor3; // color of light 3
4350
uniform float uTransparency;
4451

52+
4553
//clipping planes
4654
uniform vec4 uClippingPlane0; // clipping plane 0
4755
uniform vec4 uClippingPlane1; // clipping plane 1
@@ -66,8 +74,24 @@ uniform vec4 uFogColor; // fog color
6674
// lights we light in world space.
6775
varying vec3 vNormal;
6876
varying vec4 vColor;
69-
varying vec4 vPos;//for clipping plane calc
70-
varying vec4 vFogCoord;// for fog calculation
77+
varying vec4 vPos;//for clipping plane calc
78+
varying vec4 vFogCoord;// for fog calculation
79+
80+
vec4 calculate_lighting(vec3 lightDirWorld, vec3 lightColor)
81+
{
82+
vec3 invLightDir = -normalize(lightDirWorld);
83+
vec3 normal = normalize(vNormal);
84+
85+
if (gl_FrontFacing)
86+
normal = -normal;
87+
88+
float diffuse = max(0.0, dot(normal, invLightDir));
89+
vec3 reflection = reflect(invLightDir, normal);
90+
float specular = max(0.0, dot(reflection, uCamViewVec));
91+
specular = pow(specular, uSpecularPower);
92+
93+
return vec4(lightColor * (diffuse * vColor.rgb + specular * uSpecularColor.rgb), 0.0);
94+
}
7195

7296
void main()
7397
{
@@ -115,20 +139,15 @@ void main()
115139
discard;
116140
}
117141

118-
vec3 invLightDir = -uLightDirWorld;
119-
vec3 normal = normalize(vNormal);
120-
121-
if (gl_FrontFacing)
122-
normal = -normal;
123-
124-
float diffuse = max(0.0, dot(normal, invLightDir));
125-
vec3 reflection = reflect(invLightDir, normal);
126-
float specular = max(0.0, dot(reflection, uCamViewVec));
127-
specular = pow(specular, uSpecularPower);
128-
129-
vec4 diffuseColor = vColor;
130-
131-
gl_FragColor = vec4((specular * uSpecularColor + diffuse * diffuseColor + uAmbientColor * diffuseColor).rgb, uTransparency);
142+
gl_FragColor = vec4(uAmbientColor.rgb * vColor.rgb, uTransparency);
143+
if (length(uLightDirWorld0) > 0.0)
144+
gl_FragColor += calculate_lighting(uLightDirWorld0, uLightColor0);
145+
if (length(uLightDirWorld1) > 0.0)
146+
gl_FragColor += calculate_lighting(uLightDirWorld1, uLightColor1);
147+
if (length(uLightDirWorld2) > 0.0)
148+
gl_FragColor += calculate_lighting(uLightDirWorld2, uLightColor2);
149+
if (length(uLightDirWorld3) > 0.0)
150+
gl_FragColor += calculate_lighting(uLightDirWorld3, uLightColor3);
132151

133152
//calculate fog
134153
if (uFogSettings.x > 0.0)

0 commit comments

Comments
 (0)