Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Ignifex

Member Since 25 Jul 2004
Offline Last Active Jan 03 2014 04:10 PM

#5039951 Learning GLSL all over again

Posted by Ignifex on 06 March 2013 - 06:34 AM

It seems you are looking for glBindFragDataLocation, which tells glsl what output variable writes to which color target. By default, if only a single output is specified for the fragment shader, that variable is chosen as the output to the (first) bound color buffer.

 

Depth is a separate case, since only a single depth buffer can be bound at a time. No separate variable should be declared and it is not required to write to the depth manually. If you wish to do so anyway, you can use gl_FragDepth.




#4980059 Cylindrical texture coordinates

Posted by Ignifex on 14 September 2012 - 08:08 AM

The second form, the "open" cylinder, is the common solution used in almost every model exporter available. The reason is exactly as you have mentioned.
Texture coordinates are not the only attribute that can differ per vertex on the model. Multiple normals are also commonly available, forcing even more splitting into multiple "single attribute" vertices.


#4975543 Shadow mapping advice

Posted by Ignifex on 01 September 2012 - 03:07 PM

For OpenGL / GLSL, you need to set up your depth texture to do a comparison upon lookup using for instance:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);

Then, in your shader, you should give your shadowmap uniform the type sampler2DShadow. This will allow you to call the regular texture function, or one of its variants, with a 3 dimensional texture coordinate. The third coordinate is the depth value used for comparison.


#4970125 Multiple Render Target Rules

Posted by Ignifex on 16 August 2012 - 06:16 AM

Hmm, well, as I said, I am not sure about official support. The last time I experimented with the possibilities on a GL 3.3 system (pre-Fermi card), I wasn't able to create such an FBO, although that has been a while.

Currently reading through the opengl Wiki pages. The framebuffer completeness rules only provide one limitation:
- All images must have the same number of multisample samples
Also, on the Image Format page, a list of required formats for render buffers is provided.
This says that 1, 2 and 4 channels with some typical formats must be supported. 3 channel textures and some other formats are optional for implementations. This does not appear to mention anything on multiple render targets.

Number of channels used to be a limitation, but clearly isn't anymore. If anyone can find a good source, it would help to clear this up.


#4969941 Multiple Render Target Rules

Posted by Ignifex on 15 August 2012 - 02:46 PM

I believe the Op is talking about MRT, the use of multiple color attachments, render buffers, with a single FBO. Note that each render buffer is also considered an implementation of a Render Target, although this term is far more vague.

Yes, there are obvious restrictions to the types of the separate render buffers attached. All must have the same number of color channels. However, data types may differ. I have used 4 channel half-float and float buffers in MRT without problem.

Honestly, I am not sure about official support rules for MRT, nor do I know the current implementation details, but I thought it would be wise to clear up any confusion on the topic. That said, I would advise to keep using what layouts work for you, as it will likely work on other systems. If it ends up not working with a different driver or card, deal with it then.


#4967325 How to calculate the points of a triangle strip from a line?

Posted by Ignifex on 08 August 2012 - 04:01 AM

What I have described is all Linear Algebra and the use of rotation matrices. You can pick up any introduction level book on the topic, which should also include transformations as a part of matrix multiplication.
As for online sources, wikipedia might be a good place to start. Wolfram is good reference material, but it might not have the best introductions.

For real world applications such as this one, it usually helps to make a drawing of what you are trying to do. Draw the vehicle as it heads in a all 0 angle direction, then consider what rotations should be applied and in what order. Rotations in 3D is often a bit of a pain, but it gets better with some practice.
Also, using a math library will really help to clean up your code and you can avoid writing out rotations by hand like I showed.


#4967110 How to calculate the points of a triangle strip from a line?

Posted by Ignifex on 07 August 2012 - 01:23 PM

When approaching the rotation through angles, the yaw-pitch-roll system is probably the most intuitive. Once you know these angles, finding any vector is relatively easy.

As you mentioned, you already have a roll angle. The yaw and pitch can then be computed from your forward vector f, using it's x, y and z components. This is a little rough and you should be careful when the x and z components are both 0, but the computation is as follows:
yaw = atan2( -x, -z )
pitch = atan2( y, sqrt( x2 + z2 ) )

Given these angles, I believe it's fastest to compute s using some rotation matrices. For yaw-pitch-roll, the rotation is applied as YPR * vector, or ZYX * v. Given a simple vector (-1, 0, 0), it's components will be:
x = - (cos(yaw) *cos(roll) + sin(yaw) * sin(pitch) * sin(roll))
y = - (cos(pitch) * sin(roll))
z = - (cos(yaw) * sin(pitch) * sin(roll) - sin(yaw) * cos(roll))

Note that I assumed you use the OpenGL eye space coordinate system, since you mentioned y is pointing up. I follow the right hand rule for the rotations, also the roll. A (small) positive roll angle turns a plane left, a positive pitch goes up and a positive yaw is also left.


#4966713 How to calculate the points of a triangle strip from a line?

Posted by Ignifex on 06 August 2012 - 10:43 AM

I think the reason that you are struggling is mainly because you do not have sufficient information on the trajectory. Besides the direction of the line, there is a freedom of movement in the rotation around the line. For instance, you could imagine a plane doing a "barrel roll" while staying on the same trajectory line, resulting in a nice double helix like effect for what you want to achieve.
Seeing as how you want to follow a vehicle, I would advice storing the complete transformation per point, instead of just the position. If you only want to reproduce this effect, then adding a "side" vector would be sufficient.

Imagine adding a small XYZ axis system on each point pi in your trajectory, where one vector f points in the direction the vehicle is headed, one vector u points up from your vehicle and the third vector s points to the left (or right) side of the vehicle. Ideally, these vectors should be normalized. If you have trouble obtaining them, please let us know.
Given these vectors, finding the points along the sides of your trajectory is suddenly trivial: Li = pi + a s, and Ri = pi + a s, for Left and Right, where a is half the width of the trajectory.
The order for the triangle strip would then look something like: L 0 - R0 - L1 - R1 - L2 - R2 - etc...

Hope it's a little clear. Posted Image


#4799545 Find the distance between two isometric tiles

Posted by Ignifex on 17 April 2011 - 12:34 PM

With the size of a tile as 2200x1100, you might make the observation that the upper left corner of this rectangle around a tile at (x, y), is the exact center of the tile at position (x-1, y).
So, simply put, because of the shape of your tiles, the distance between the centers of two adjacent tiles, is exactly half of the size of the rectangle around your tile.
This should help you to convert between your two coordinates.


PARTNERS