Shader Problem

Started by AGP, January 22, 2014, 04:58:53 PM

Previous topic - Next topic

EgonOlsen

Quote from: AGP on January 27, 2014, 09:48:40 PM
Even though the first line of the vertex shader is attribute vec4 tangent, jpct tells me

Tangent handle not found (tangents needed: true)!
No, of course not. That's because you aren't using them in the shader. The engine detects that you actually want them (that's the "tangents needed: true" part of the message), but if you don't use them, the shader compiler will simply remove the attribute. So after compilation, the engine can't access the attribute, which is the other part of the message. The same is true for uniforms: If you don't use them in the shader's code, you usually can't access their handles.

Quote from: AGP on January 27, 2014, 09:48:40 PMI don't suppose it's just the cameraPosition because of that pesky fourth value).
I would estimate that it is. The forth component is the w coordinate (http://en.wikipedia.org/wiki/Homogeneous_coordinates...if you are masochistic... ;)). For a vector, you can simply put 1 into it.

AGP

So do I convert the SimpleVector (from camera.getPosition()) into OpenGL's coordinate system (then put it into an array of floats with 1 at the end)? If so, how do I convert it? Do you also suppose that the ocean is appearing in mid-air because I didn't fill vViewPosition?

EgonOlsen

Negate z and y of the position and add 1 as the forth component. However, i don't see a relation to the position of the ocean. The ocean's position is calculated at the line with the "gl_Position". It doesn't seem to take vViewPosition into account but some calculated position based on the normal vertex position with some height stuff added...

AGP

That is bizarre, then, because my ocean is not where it should be. Hey, it just occurred to me: does using a shader cancel the parent's transformations?

EgonOlsen

Quote from: AGP on January 27, 2014, 11:45:01 PM
does using a shader cancel the parent's transformations?
No, why should it?

AGP

All I know are the facts: with the shader, the ocean is floating in the sky. Without it, it's where it should be.

EgonOlsen

Then that's because the shader modifies the position (which it does). As mentioned, "gl_Position" defines the position.

AGP

I often find you resistant to pointing out things that you think are obvious (and that aren't always). What I don't understand is that once removed from its regular place, the ocean stays still (only the waves move). Also, who set the gl_ModelViewProjectionMatrix (or otherwise, how is it calculated)? Isn't that likely the problem?

EgonOlsen

Sorry...but the thing is that i always stated that i'm not giving full support for writing shaders. Simply because i'm not the best person to do this and there should be plenty of information out there that's better than what i can contribute. I also said, that i find it almost impossible to adapt a shader without knowing some basics about shaders and how they work. And i'm not the person to teach this. I try to help, but i can't be bothered to rewrite some random shader from the internet to make it work.

Anyway, gl_ModelViewProjectionMatrix is a build-in uniform of desktop OpenGL (it's absent in OpenGL ES). It will be populated automatically, so there's no room for it to be wrong (as long as you've compiled the Object3D). The same applies to gl_Vertex. So if you do a


gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;


You'll get the same position in space that you'll get if you weren't using any shader at all.

AGP

All I can say is that I've been looking, man. I've shown you some of the crap that's online. Nearly no one explains their work, and it's almost as if the community purposely wants to confuse us (if you can show your shader working on a video, it works, and it shouldn't have float = vec3 errors). Besides, this isn't a random shader. It's like the 20th one I experimented with and the first one to actually work, despite this weird displacement. It's also short and fairly easy to understand (once I can see it working perfectly).

AGP

In my tests, I can rotate it to my heart's content, but I can't translate it. This is obviously a product of the way in which jpct stores the child/parent's translation: ModelViewProjectionMatrix doesn't see that the child was translated at all. Would you be willing to make me that method now (detachFromParentButKeepTransformations() or so)?

EgonOlsen

The matrix is injected into the shader by OpenGL. It's the exact same matrix that OpenGL uses when no shader has been assigned. Make sure that you've compiled the object and try to transform the object without any shader assigned. If that works, replace the gl_Position line of the shader with the one that i've posted above and try again. If that doesn't work anymore...then you have created a miracle.

AGP

Translating without setting render hook works.

I hadn't realized that you changed it. Your line works, thank you very much. So how exactly aren't you the best person to help with this? :- )

EgonOlsen

OK, but my line disables a part of the actual shader. I'll look at the shader again later to see why this is the case. Has to be something really simple...

AGP

I see now that you effectively skipped the waveHeight line.