Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Axis drawing is working #346

Merged
merged 2 commits into from
Nov 2, 2016
Merged

Axis drawing is working #346

merged 2 commits into from
Nov 2, 2016

Conversation

chevtche
Copy link
Contributor

No description provided.

@eile
Copy link
Contributor

eile commented Oct 18, 2016

Better PR and commit message would be: Implement axis and legend for full volume box

'is working' is assumed at this point :P

@@ -80,6 +80,11 @@ class Frustum : public Frustumf
LIVRECORE_API Matrix4f getMVPMatrix() const;

/**
* @return The normal matrix.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't state the obvious. What's the normal matrix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normal matrix is for normals what modelview matrix is for vertices. I don't know a better name.
Everyone call that normal matrix. In old OpenGL it was called gl_NormalMatrix for example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name is fine, but repeating it in doxygen is not. What about @return the inverse transposed model-view matrix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Done.

@@ -294,6 +294,11 @@ bool EventHandler< C >::handleEvent( const eq::EventType type,
frameSettings.toggleStatistics();
return true;

case 'a':
case 'A':
_impl->config.getFrameData().getRenderSettings().toogleDrawAxis();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo toggle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

_axis.draw();

glUseProgram( 0 );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor if scope into method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -156,6 +168,7 @@ struct RayCastRenderer::Impl
_nSamplesPerRay = frameData.getVRParameters().getSamplesPerRay();
_computedSamplesPerRay = _nSamplesPerRay;
_nSamplesPerPixel = frameData.getVRParameters().getSamplesPerPixel();
_drawAxis = frameData.getRenderSettings().getDrawAxis( );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment, i.e., don't change: This is useless dynamic state. Better design would be to pass the frameData state to the method in need of it, instead of duplicating it here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the motivation for this duplication was to isolate the renderer from the Equalizer related classes.

{
for( int32_t i = 0; i < 3; ++i )
{
for( int32_t j = 0; j < 4; ++j )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k-i-j loop nesting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it really matter ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
}

for( uint32_t i = 0; i < vertices.size(); ++i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size_t

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

eile
eile previously approved these changes Oct 19, 2016
@eile
Copy link
Contributor

eile commented Oct 19, 2016

Erm, I just wanted to unblock PR, not approve. Still learning the new UI here... Somebody else please approve.

Copy link
Contributor

@hernando hernando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will continue tomorrow

@@ -156,6 +168,7 @@ struct RayCastRenderer::Impl
_nSamplesPerRay = frameData.getVRParameters().getSamplesPerRay();
_computedSamplesPerRay = _nSamplesPerRay;
_nSamplesPerPixel = frameData.getVRParameters().getSamplesPerPixel();
_drawAxis = frameData.getRenderSettings().getDrawAxis( );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the motivation for this duplication was to isolate the renderer from the Equalizer related classes.

LBASSERT( program );
glUseProgram( program );

GLint tParamNameGL = glGetUniformLocation( program, "renderTexture" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tParamNameGL -> location?
Unless it's inconsistent with the style all around.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's everywhere like that... Unless I change it everywhere in Livre I will keep it like that

flat in uint type;

// http://www.opengl.org/wiki/Compute_eye_space_from_window_space.
vec4 calcPositionInEyeSpaceFromWindowSpace( vec4 windowSpace )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you pass the eye position from the vertex shader? I know that increasing the number of variables passed between shader limits the scalability, but that's not an issue for the axis rendering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the fragment position in eye coordinate, not the camera position.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understood that, my point is that in the vertex shader you can multiply the vertex coordinate by the modelview and pass that to the fragment shader. Then you don't need to unproject here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't get it... I need to multiply vertex coordinate by modelViewProjectionMatrix otherwise my fragments positions will be wrong.


vec4 dst = imageLoad( renderTexture, ivec2( gl_FragCoord.xy ));

if( type == 1 )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is type 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I put a #define in the shader AXIS = 1 so it's like the enum in c++ code.

if( type == 1 )
{
if(!((( dot( pixelEyeSpacePos, normal ) <= 0.0 ) && ( dot( pixelEyeSpacePos, normal2 ) <= 0.0 )) ||
(( dot( pixelEyeSpacePos, normal ) >= 0.0 ) && ( dot( pixelEyeSpacePos, normal2 ) >= 0.0 ))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment that explains what all these operations are checking would be helpful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the dot products out of the if and assign them to a const variable. You have the same operation 3 times. This is not about efficiency as much as about readability.

Also I prefer avoiding expressions like !(.....) if they can be rewritten without the !.
In this example you have:

!(( A <= 0 && B <= 0 ) || ( A >=0 && B >= 0))
!( A <= 0 && B <= 0 ) && !( A >= 0 && B >= 0)
( A >= 0 || B >= 0) && ( A <= 0 || B <= 0)

As you can see, there are also unnecessary parenthesis around the comparison operations, which I think don't help making the expression clearer.

A <= 0 and A >= 0 are one the negation of the other, do you need both comparisons to test for equality to 0? Could you replace both with a single variable a A >= 0 (normalPointsForward, or something similar) and use A and !A instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get the "Could you replace both with a single variable a A >= 0 (normalPointsForward, or something similar)"

The code looks like that now:
if(( dotNormal > 0.0 ) && ( dotNormal2 < 0.0 ) ||
( dotNormal < 0.0 ) && ( dotNormal2 > 0.0 ))

float tickSize = 0;

const float rangeLenght = range.y() - range.x();
const float rawTickLenght = rangeLenght / maxTickNumber;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit lost with these names. This is the distance between tickets in volume coordinates, why do you call it rawTickLength?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. This is the distance between ticks if you don't do the 1 2 5 fitting magic... it's why I called it "raw". It's an abstract intermediate mathematical result... I am not sure a better name can be found.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tickDistanceHint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const float z = volInfo.worldSize.z() * 0.5f;

_createLocalTicks( volInfo, { -x, -y, z }, { x, -y, z }, { 0, 1, 0 }, { 0, 0, -1 },
false, tickSize, factor, vertices, normals, normals2, colors, types );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a struct for all the parameters that do not change (including volInfo).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why ? Maybe I don't undestand the comment because for me if I add a struct it will only increase the size of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Vector3f posOnAxis = start + axisDir * ( worldSpaceOffset + worldSpaceTickSize * i );
vertices.push_back( posOnAxis.x( ));
vertices.push_back( posOnAxis.y( ));
vertices.push_back( posOnAxis.z( ));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write a helper funtion to write: append(vertices, posOnAxis)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

false, tickSize, factor, vertices, normals, normals2, colors, types );
_createLocalTicks( volInfo, { -x, -y, z }, { x, -y, z }, { 0, 0, -1 }, { 0, 1, 0 },
true, tickSize, factor, vertices, normals, normals2, colors, types );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write a comment before each block to know which face are you adding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

glGenBuffers( 1, &_typeBufferId );
glBindBuffer( GL_ARRAY_BUFFER, _typeBufferId );
glBufferData( GL_ARRAY_BUFFER, sizeof(GLubyte) * types.size(),
&types[0], GL_STATIC_DRAW );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally, a single VBO is used for all the data so you don't have to rebind a new buffer to set each vertex attrib pointer. You can use glBufferSubData to upload the pieces one by one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@hernando hernando dismissed eile’s stale review October 20, 2016 13:08

Approved by mistake

@hernando
Copy link
Contributor

Strange, I thought that dismissing the review would put the PR in a non-mergeable state, but that's not the case (at least I can merge it, I don't know if @chevtche can)

@chevtche
Copy link
Contributor Author

Retest this please

glUniformMatrix4fv( tParamNameGL, 1, false, frustum.getNormalMatrix( ).array );

tParamNameGL = glGetUniformLocation( program, "invProjectionMatrix" );
glUniformMatrix4fv( tParamNameGL, 1, false, frustum.getInvProjMatrix( ).array );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After removing calcPositionInEyeSpaceFromWindowSpace you don't need this, do you?

Copy link
Contributor Author

@chevtche chevtche Nov 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I need it in the shader.
"vec3 pixelWorldSpacePos = vec3(( invModelViewMatrix * pixelEyeSpacePos ).xyz );"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But not for the axis, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, done.

}

// There is a possible optimization here, it is possible to append directly
// in the code lines [ 50 - 89 ].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't you doing it? It seems trivial and you reduce the verbosity of the code. You can do it simply by:

std::vector< Vector3f >& vertices = bbAxisData.vertices;
....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This technique will not work for bbAxisData.normals, bbAxisData.normals2, bbAxisData.color, bbAxisData.types. There is a way to do it for everything in the loop but it will take more time and the code will be even more complicated. Here you are only copying 48 vertexes...

I just put a comment for future work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comment then, the optimization is quite negligible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Done.

@hernando
Copy link
Contributor

hernando commented Nov 1, 2016

You should have done a new commit for the CR changes, now it's difficult to keep track of what you changed.

currentAxis = Vector3f( end - start ).find_min_index();

const Vector2f range = _computeRange( bbAxisData.volInfo, currentAxis );
const float rangeLenght = range.y() - range.x();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still same typo: Lenght -> Length

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

const Vector2f range = _computeRange( bbAxisData.volInfo, currentAxis );
const float rangeLenght = range.y() - range.x();

const float worldSpaceLenght = start.distance( end );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And also here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if( flipTick )
sign = -(( 0.0f < cross[ tickAxis ]) - ( cross[ tickAxis ] < 0.0f ));
else
sign = ( 0.0f < cross[ tickAxis ]) - ( cross[ tickAxis ] < 0.0f );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace lines 312-325 by:

int sign = ( 0.0f < cross[ tickAxis ]) - ( cross[ tickAxis ] < 0.0f );
if( flipTick )
    sign = -sign;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

container.push_back( vector.x( ));
container.push_back( vector.y( ));
container.push_back( vector.z( ));
container.push_back( vector.w( ));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the _appendXdVector functions free functions inside an anonymous namespace, it doesn't make sense to make them member functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why cannot it be a member function ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that it can't.
When a "member" function doesn't need any state of the object to which it belongs it's better to make it a free function to keep the class interface clean. In this case the member function is even private, so making it a free function contained in the .cpp allows you to change it in the future without touching the .h file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok Done

const Vector2f range = _computeRange( bbAxisData.volInfo, longestBBAxis );

const uint32_t maxTickNumber = 50;
const float tickSizes[4] = { 1, 2, 5, 10 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called tickDistances for consistency, shouldn't it? And the same goes for bbAxisData.tickSize.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed everything to distance.

chevtche added a commit to chevtche/Livre that referenced this pull request Nov 2, 2016
chevtche added a commit to chevtche/Livre that referenced this pull request Nov 2, 2016
chevtche added a commit to chevtche/Livre that referenced this pull request Nov 2, 2016
@hernando
Copy link
Contributor

hernando commented Nov 2, 2016

Retest this please

@chevtche
Copy link
Contributor Author

chevtche commented Nov 2, 2016

Merge or not merge ?

hernando pushed a commit to hernando/Livre that referenced this pull request Nov 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants