Question

I'm working with the Qualcomm augmented reality FrameMarkers demo for iOS & have switched in a model that our 3D guy gave to me (really he's more of a 2d guy that dabbles in 3d - which is why I'm trying to solve this on the code end; rather than the 3D end). The problem is with regards to the texturing - the demo assumes a 2d image texture is bound to the 3d model. However our 3D guy has built the texturing into the object itself (e.g. procedural texturing).

Initially the object appeared completely filled with black & couldn't really see any of the details. I managed to make this a little better by removing these lines from the demo:

glActiveTexture(GL_TEXTURE0);

glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);

Which turns everything kind of a slivery colour & I can now see some of the detail & some reflection off of some of the surfaces (its supposed to be translucent in places actually rather than purely reflective - so that's also a problem..).

I read in a few places that in order to acheive translucency these commands are required;

glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

However, for me - they just turn the whole screen black..

Correct: Correct rendering

In-app: In-app rendering

Was it helpful?

Solution

With the benefit of screenshots, I would dare guess that your designer has assigned appropriate materials to faces — you'll probably have a .MTL file that goes with the OBJ file and contains a lot of lines starting with things like Ka, Kd and Ns — but not applied any texturing whatsoever. From what I can make out of obj2opengl, the script assumes more of the video game style of presentation where, in some implementations, the colour properties given for surfaces are discarded and only texturing is applied.

So, technically, you're right to disable texturing but what what you'd probably want to add if you're using ES 1.x is a bunch of glMaterial calls somewhere, using data that the script doesn't seem to be retaining. Or, for ES 2.x, you'll want shaders that emulate the classic ambient + diffuse + specular lighting model, which under iOS you can get strait from GLKit by attaching a suitably specified GLKEffectPropertyMaterial to a relevant GLKBaseEffect.

For transparency, my best guess is simply that your augmented reality library doesn't correctly set the state it wants for compositing the 3d and 2d, instead assuming you'll preserve it. So you'll have to look into that.

What sort of solution are you looking for? Do you want something you can adapt for arbitrary models from now on, or is it just a matter of getting this model into the app and then getting on with other stuff?

If the former then you'll probably need to find some other toolchain; I'm afraid I can't advise as I was more of a write-an-OBJ-parser, parse at runtime sort of person and I've never updated my stuff for GLKit so it's now superannuated.

If the latter then the easiest thing might be to split the model by material and export each component separately (hopefully your 3d editor can do that), then hand type the relevant coefficients (there aren't that many) and draw in a suitable order (transparency last, probably, otherwise it doesn't much matter).

EDIT: for the record, when people say procedural textures then what they generally mean is something like I give you a formula f(texture position) that, for example, when evaluated across the surface of a polygon produces something that looks like marble. Hopefully I find some way to parameterise it further and/or define it so that you can zoom in and in, getting ever more detail. So it's a function that produces a 2d image that I would otherwise have put into a bitmap with the advantage of flexibility and, hopefully, of detail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top