Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.
You tell the shader what texture UNIT you're using and you still bind that texture in your C code. That's why passing 0 seemed to work for you. You don't give it the texture ID.

Adbot
ADBOT LOVES YOU

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

HolaMundo posted:

Doh!
Thanks :downs:

But why does it work if I change the variable name (of the sampler2D) in the vertex shader? Does it defaults to whatever texure is binded in unit 0 or something like that?

I'm guessing for bump mapping you could bind the normal map to a different unit than the actual texture and pass both to the shader.

It's probably defaulting the value of that variable to 0, which is the first texture unit. And yes, for bump mapping, you would have multiple texture units and thus multiple sampler2D variables.

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

HauntedRobot posted:

I have a world defined as a bunch of polygon meshes and I'm using VBOs at the moment to render them. Currently the setup is
code:
        glBindBufferARB  ( GL_ARRAY_BUFFER_ARB, (*mi).vbo );
        glVertexPointer  ( 3, GL_FLOAT, 32, (char *)NULL + 0 );
        glTexCoordPointer( 2, GL_FLOAT, 32, (char *)NULL + 12 );
        glColorPointer   ( 3, GL_FLOAT, 32, (char *)NULL + 20 );
and then I go through with DrawArrays... this gives me 3d textured geometry with really basic vertex lighting. (I know this is way behind the curve but I've been out of the loop so I'm relearning from the naive glBegin, glEnd stuff forward here, and diving right in to shaders was too much to take in at once)

The thing with that is that the lighting is baked in and static, and I want to move on to dynamic lighting. Is there a way to accomplish that through loading the vbo -> *doing something where dynamic light values get added* -> DrawArrays? Or have I hit the limitation of rendering that way there?

If so, where would I go next from there? Is the next thing to do it all in shaders or is there some kind of intermediate step? Something with a deferred lighting pass maybe? I've learnt a ton of stuff doing things this way that I'd sort of handwaved over before.

If you want to still use VBOs with dynamic lighting instead of shaders, you could put the color values into another VBO and modify them each frame:

code:
// Prepare the color VBO each frame:
glBindBufferARB(GL_ARRAY_BUFFER_ARB, (*mi).colorVbo);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, vertexCount * sizeof(GLfloat) * 3, NULL, GL_DYNAMIC_DRAW_ARB);
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, vertexCount * sizeof(GLfloat) * 3, (GLvoid*)colorData);

// Ready the color VBO for drawing:
glBindBufferARB(GL_ARRAY_BUFFER_ARB, (*mi).colorVbo);
glColorPointer(3, GL_FLOAT, 12, NULL);
You'll have to remove the color data from your interleaved vertex information of course.

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

FlyingDodo posted:

I know that binding things in opengl is fairly expensive thing to do and you should try to minimise the amount of times it is called per frame. If something such as a buffer, texture, shader etc is already bound then how much is the performance hit if it is bound again? Is there a way to check what is currently bound, and if so how expensive is that compared to blindly rebinding something?

You can use the glGet* functions to get the currently bound object for a particular type, for example:

code:
// Get the buffer ID currently bound using glBindBuffer(GL_ARRAY_BUFFER, id);
GLint id;
glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &id);
But that can be an expensive operation in itself. The best way to deal with the bindings (and other OpenGL states) is to create an array of states of your own and keep track of bindings there. That way, you have a function that first checks what your array thinks is the currently bound ID, and if the ID you're trying to bind isn't the same, call the GL function and set your state array accordingly. If the ID matches, then leave it alone. Make sure for textures that you keep track of the binding per texture unit.

Edit: Make sure you do an initial "OpenGL state reset" to get the GL state machine to match up to your initial state array values.

HiriseSoftware fucked around with this message at 16:57 on Apr 6, 2012

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

Boz0r posted:

I'm trying to add the color from a texture with the colors of another texture (containing my lights). I have the following code: http://ideone.com/mb9380 and shader: http://ideone.com/AWCisI. However it only draws stuff from the tex texture. Can anyone spot my error?

Maybe use glEnable(GL_TEXTURE_2D) for the texture unit 1 if it's not done somewhere else? Or maybe call glClientActiveTexture() as well as glActiveTexture()?

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

unixbeard posted:

How can I set a vertex to an arbitrary location in a vertex shader?

I want something like:
code:
void main(void)
{
    vec4 vpos = vec4(200.0, 300.0, 0.0, 1.0);
    gl_Position = gl_ModelViewProjectionMatrix * vpos;
}
Which i tried but doesn't work. It's using ARB so I believe the coords are ok, but its GLSL 1.2.

So you don't see a single point being drawn? What kind of primitives are you trying to render?

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.
1. Use the translate, rotate, and scale functions to "fill in" your matrix, then you can multiply those matrices together. Read up on 3D matrix math.
2. He's trying to show that the math (i.e. the matrix multiplication) used by GLM is similar to GLSL, but suggests that you build the matrix first in GLM/C++ and then send the final matrix to GLSL via glUniformMatrix4fv().
3. The "??" is the X, Y, Z coordinates of the rotation axis. So if you want to rotate a vector around the Z axis, specify (0, 0, 1).
4. You're correct about using MVP and glUniformMatrix4fv() - build your matrix with GLM and then send that to GLSL where the shader will multiply it by the vertex.
5. "g_element_buffer_data" looks like the indexes used to draw the triangle - it must be used (or something similar) inside blDrawTriangle()

VVV Sure, but I was too lazy to quote his post!

HiriseSoftware fucked around with this message at 04:38 on Jan 27, 2014

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.
Based on your code you're not multiplying your model matrix that you create in bInitMatrix2 with a view and a projection matrix, like what bInitMatrix is doing. The way you have it now, the "eye" at the origin is actually inside the cube, so you're not gonna see it with backface culling. You'll need a view matrix (like with glm::lookAt) to push out the cube a little bit so that you can see it.

Plus you shouldn't have to use the identity matrix in your multiplication.

code:
// EDIT: Remove myIdentityMatrix here because you don't need it.
// mat4 myModelMatrix = myTranslationMatrix * myRotationMatrix * myScalingMatrix * myIdentityMatrix;
mat4 myModelMatrix = myTranslationMatrix * myRotationMatrix * myScalingMatrix;
code:
// Model matrix : an identity matrix (model will be at the origin)
glm::mat4 Model = glm::mat4(1.0f);
// Our ModelViewProjection : multiplication of our 3 matrices
// EDIT: Even though "Model" is the identity, this is fine to leave in since it's easier to understand what's going on.
glm::mat4 MVP = Projection * View * Model; // Remember, matrix multiplication is the other way around

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

Raenir Salazar posted:

But I mean, with that code I can see a single triangle that I draw with the three vertices, shouldn't it still be possible to see a cube without a projection matrix?

Is the triangle facing towards the screen? At what Z is the triangle at? With a cube you're not going to see the faces of the cube while you're inside it (the eye is at 0, 0, 0) because of backface culling. Turn off culling and see if the cube shows up.

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.
Did you try drawing each of the triangles individually (i.e. without drawing the other) to see if it's actually doing the wireframe? Also, I saw this StackOverflow post that offsets the wireframe triangles instead of the filled:

http://stackoverflow.com/questions/13438450/glpolygonmodegl-back-gl-line-isnt-working

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

Colonel J posted:

I am getting into programming with Three.js and I hope some of you can help me here.
http://jsfiddle.net/fL33x/4/

The big yellow cube behind is a screen and the small yellow sphere is a camera pointing towards the origin. I'm trying to render what this camera sees on the cube but if just gives error glDrawElements: attempt to access out of range vertices in attribute 1 .

The goal of this is making my own shadow map shader; I will render what the second camera sees as a depth map and then shade accordingly in the second pass depending on what the camera positioned at the "light source" sees. Any thoughts on this are welcome, but first I need to get the rendering to texture to work. Line 274 is where it breaks.

thanks so much to anyone who could help me out with this. I could get it working in a previous test case but now I'm rewriting it cleaner and it just won't work and is driving me nuts.
If it helps I am basing myself off this example: http://stemkoski.github.io/Three.js/Camera-Texture.html

Does "cubeGeometry" have texture coordinates? When you're giving the mesh a texture material, it must be expecting some texture coordinates as part of the geometry, and it's getting none, which would cause the error. glDrawElements renders vertices by an array of indexes - it probably found the XYZ, but not the UV.

Edit: I'll admit I don't have any experience with THREE.js but I was fiddling around with your, uh, fiddle, based on some info I found online, but I couldn't get anything to work.

I did see this though: http://stackoverflow.com/questions/16531759/three-js-map-material-causes-webgl-warning

HiriseSoftware fucked around with this message at 05:50 on Feb 6, 2014

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.
I don't have any experience with shadow mapping, but I found this which has a part about calculating the shadow map coordinates:

http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/

It's something about multiplying a "bias matrix" against the MVP matrix used from the viewpoint of the light. Multiply that result by your model coordinates and you have the coordinate you pass to the texture - XY is for the texture lookup, and Z is used to determine if an object is in shadow or not.

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

Colonel J posted:

Thanks for your help, I finally got it working. I couldn't really get the bias matrix to work as it would distort my geometry in strange ways. I just multiplied the vertice positions by 0.5 and translated by 0.5 and they're good now.

As for sending the shadow map to the shaders as a uniform, I'll leave the answer here for posterity: you can send a WebGLRenderTarget to a shader as a regular texture and it'll work just fine.

Here's the updated fiddle: http://jsfiddle.net/7b9G8/1/
The yellow sphere is just to represent the directional light vector, It's not the actual light source.

Is the shadowing working correctly as you're intending? At certain points the shadow of the vertical stick should pass over the horizontal ones, but I can see that it's not. Maybe it's an artifact of my older video card, but it doesn't look right to me.

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.
Can you change

code:
glUniformMatrix4fv(BlNormalMatrix,1,GL_FALSE, &MyNormalMatrix[0][0]);
to

code:
glUniformMatrix3fv(BlNormalMatrix,1,GL_FALSE, &MyNormalMatrix[0][0]);
?

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

Raenir Salazar posted:

Why yes indeed! So by trying to use 4fv it wasn't working/undefined or some such?

e: Right now its not entirely dark anymore, but the side faces are still dark.

When using 4fv it thinks that the matrix is arranged 4x4 when you're passing in a 3x3 so you were getting the matrix elements in the wrong places. It could have also caused a strange crash at some point since it was trying to access 16 floats and there were only 9 - it might have been accessing those last 7 floats (28 bytes) from some other variable (or unallocated memory)

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

Raenir Salazar posted:

I finally did it!




Holy poo poo this was surprisingly difficult.

It seems there isn't a way to pull the materials from the mesh without there being textures. You know how in blender you can set a face to have a diffuse color? Yeah I can't seem to have that handled 'alone' and ignore textures. Has to have a texture for it to have diffuse.

ninja edit: Just to double check but the obviously terrible looking planes there making up there sphere are mostly noticeable because I'm doing everything in the vertex shader right?

You can have a vertex array of color attributes (like texture coordinates or normals) but to allow each face to have its own color you'd have to "unshare" the vertices so that one vertex is only used by one face. That increases the data processed by the video card by up to 3x, but it's what you'd need to do.

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

Raenir Salazar posted:

To populate that vertex array though do you know if that can be done automatically with assimp to extract it from the mtl and obj files?

I have no experience with that library, but I would hope that it does. The unsharing would have to work for texture coordinates as well - if two faces sharing the same vertex had different UVs, then you'd have to split that vertex into two unique ones.

And it says it supports loading color channels.

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.
Try the solution here?

https://bugs.launchpad.net/ubuntu/+source/nvidia-graphics-drivers-319/+bug/1248642

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.

AntiPseudonym posted:

This is probably a bit of a weird question, but does anyone know how to disable perspective correction on textures in OpenGL, or at least emulate it via shaders? I'm trying to go for an authentic PS1 retro look and I think removing perspective correction would help add to the feel.

Reading this:

http://www.glprogramming.com/red/chapter09.html#name17 posted:

When the four texture coordinates (s, t, r, q) are multiplied by the texture matrix, the resulting vector (s' t' r' q') is interpreted as homogeneous texture coordinates. In other words, the texture map is indexed by s'/q' and t'/q' .

It seems that if you can specify Q=1 in your texture coordinates, you can get the effect you want.

Edit: Hmm I think the default of Q is 1, so perhaps there's another operation going on afterwards to do the perspective correction.

Edit: Or how about this?

quote:

If you use a vertex shader, multiply the texture coordinate by the W of the vertex position after you''ve applied the projection transform to it.

HiriseSoftware fucked around with this message at 04:47 on Oct 10, 2014

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.
Did you try putting glGetError() after EVERY GL command and see where it first fails?

Adbot
ADBOT LOVES YOU

HiriseSoftware
Dec 3, 2004

Two tips for the wise:
1. Buy an AK-97 assault rifle.
2. If there's someone hanging around your neighborhood you don't know, shoot him.
I want to apply a repeatable normal map texture to an arbitrary triangle mesh, like say a 3D model of a papercraft and give it a paper-y texture. I've got the model UV unwrapped for things like ambient occlusion baking, but I want the "paper" texture to be nice and uniform with no distortion. Can I use GLSL and texture matrices to do something like that? What math would be involved?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply