Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

102 Neutral

About arthurw

  • Rank
  1. In short: calculate the plane of the quad. Solve the plane equation for Y. An attempt at a few more details... Solving for y: a plane equation is in the form Ax + By + Cz + D = 0, so y = -(Ax + Cz + D) / B. Plane for the quad: the cross product of two adjacent edges in the quad gives the normal of the plane (A, B, C) and then any point in the quad can be used to solve for D. [indent=1]N = (Q2 - Q1) x (Q1 - Q0) [indent=1]A = Nx [indent=1]B = Ny [indent=1]C = Nz [indent=1]D = -(N dot Q0) (where Q0 through Q3 are the points of the quad. D could be rewritten as D = -(A*x + B*y + C*z) where x,y,z are the components of Q0, if that makes more sense to you.) so expanding it out a bit: [indent=1]Py = -(Nx * Px + Nz * Pz - (N dot Q0)) / Ny I'm sure a google search or two could explain the details better than I have, but hopefully this is enough info to get you going.
  2. arthurw

    Models for exercises

    Another option is to write a simple parser for the . blend format used by Blender. I did this so I could easily experiment with more data in my engine and it was surprisingly easy. I'm very glad I did it as it makes it simple to try my code on all sorts of models (for example, see the site Blend Swap for a large collection of openly licensed content). The basic .blend format structure (I believe it's called "SDNA") actually doesn't require much code to parse. If you're only pulling in a few properties it's pretty basic. In fact, the format tends to favor an "opt-in" parser that can grab only the properties you want without it being much work to simply ignore the unrecognized attributes (i.e. new versions of Blender likely won't break your parser!). That also makes it easy to write a trivial parser (e.g. only parsers vertex position and normals) and then add in new attributes as you go (e.g. animation data). As I said, I've found using Blender's native editor format to be very convenient. For one thing, Blender can import a ton of different formats, so it's easy to re-save other formats as .blend. Also, if you want to edit the model - you can just edit it directly - no need to import/export (in fact, you might even have your program check the timestamp on the file and reload the model on changes - thus letting you try out the model changes without even restarting your program). Of course, .blend files are large and not that efficient to load, so I wouldn't recommend it for production code; but it sounds like you're just looking for test models, like I was. The simple .blend loader I wrote is available on GitHub here. It's not very polished , but it gets the job done on my system (I'm the only user at this point). I'd be glad to help you fork it / adapt it to your project. It'd probably be a good opportunity to make my own code a bit more robust and less of a it-works-so-leave-it-alone hack. (I also wrote a brief blog post about it when I first wrote it almost a year ago). Apologies that it's code of the quick and dirty variety, but it should be enough to get you started if you're interested!
  3. I've been using GLM for a while and have been very happy with it. It's not perfect, but it certainly beats writing the world's billionth version of matrix multiplication functions. (And as for getting a float pointer to a vec3, you can use simple C++: "vec3 v; float* p = &v.x;" ). I agree that it's sometimes hard to know if GLM supports what you need or not. A GLM quick reference / cheat sheet would be very helpful for the library. On the other hand, I've found the author of the library be responsive in maintaining a library: I logged two defects and they were both fixed rather quickly. For what it's worth, I've found GLM to be a pretty solid library once you spend enough time to know your way around it.
  4. arthurw

    Best openGL resource

    Nothing like suggesting something you yourself aren't willing to do, but I'll go ahead and do it anyway... It'd be great if someone went and rewrote the NeHe tutorials using only the OpenGL 3+ core profile only. I'm sure it'd immediately become a very popular site. (By the way, I completely agree with the last couple posts. It understand why it happens, but it's frustrating when tutorials, books, lessions, etc. develop a framework or toolkit when they claim to be about learning the core API. Sure, to get to some advanced features you'll need to reuse some code, but limit it to functions, not frameworks - and write out the API calls full in when possible!)
  5. Following up on my own post... V-man, thanks - I appreciate the reply. However, I was looking to do something a bit different. I didn’t want to control the interpolation level (the smooth/flat shading example for a poor one on my part, sorry); I wanted to figure out how to pass down arbitrary data on a per-face basis to the geometry shader. Some effects could be done via per-vertex attributes and the “flat” keyword, but would require figuring out a unique provoking vertex for each face to know where to assign those face attributes - a complication which I wanted to avoid. The solution for what I wanted I realized was quite easy: Create a 1D texture of width = number of facesFill the texture so that each texel represents the data for one faceIndex the texture in the geometry shader by (gl_PrimitiveIDIn + .5) / textureSize(sampler, 0) That got me exactly what I was looking for. Again, thanks for the initial reply - just wanted to follow up in case others were interested.
  6. GLSL newbie question: how do pass per-face data to a GLSL geometry shader? I'm targeting GLSL 1.5. What I'm trying to do specifically is decide whether to use the vertex normals or generate a face normal (via the cross product) for each face in the object. I have this working across the entire object via a uniform variable (i.e. toggle between smooth and flat shading); however, I'd like to pass a per-face flag to allow finer grain control. Is there some way I should be using gl_PrimitiveIDIn to accomplish this? I'm fairly confident in how to pass down per-vertex arrays of data and using uniforms, but I'm not sure of the middle ground of per-face data works. I realize I could duplicate vertices between faces and simply pass per-face data as redundant per-vertex data, but I'd prefer not use that approach if there are other options. For reference, below is a simplified version of the geometry shader I currently have that uses a uniform for the whole object rather than per-face basis. In other words, what I'm trying to do if replace that "unifFlatNormals" variable with a per-face variable. [source lang="cpp] uniform int unifFlatNormals; in vec3 geomVertexEc[]; // Vertex position in eye coordinates from the vertex shader in vec3 geomNormalEc[]; // Vertex normal in eye coordinates from the vertex shader varying out vec3 fragNormalEc; vec3 computeNormal (vec3 v0, vec3 v1, vec3 v2) { vec3 a = v2 - v1; vec3 b = v1 - v0; return normalize( cross (b, a) ); } void main() { vec3 n = computeNormal(geomVertexEc[0], geomVertexEc[1], geomVertexEc[2]); for (int i = 0; i < gl_VerticesIn; i++) { gl_Position = gl_PositionIn; if (unifFlatNormals == 1) fragNormalEc = n; // Replace the per-vertex data with a uniform normal across the entire primitive else fragNormalEc = normalize(geomNormalEc); // Pass the per-vertex data directly EmitVertex(); } EndPrimitive(); } [/source]
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!