Author Topic: Shader Problem  (Read 18011 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Shader Problem
« Reply #30 on: January 27, 2014, 11:27:18 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.

I 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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Shader Problem
« Reply #31 on: January 27, 2014, 11:32:09 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Shader Problem
« Reply #32 on: January 27, 2014, 11:41:11 pm »
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...

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Shader Problem
« Reply #33 on: January 27, 2014, 11:45:01 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Shader Problem
« Reply #34 on: January 28, 2014, 07:19:20 am »
does using a shader cancel the parent's transformations?
No, why should it?

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Shader Problem
« Reply #35 on: January 28, 2014, 07:49:38 am »
All I know are the facts: with the shader, the ocean is floating in the sky. Without it, it's where it should be.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Shader Problem
« Reply #36 on: January 28, 2014, 07:58:59 am »
Then that's because the shader modifies the position (which it does). As mentioned, "gl_Position" defines the position.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Shader Problem
« Reply #37 on: January 28, 2014, 08:07:13 am »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Shader Problem
« Reply #38 on: January 28, 2014, 10:40:39 am »
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

Code: [Select]
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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Shader Problem
« Reply #39 on: January 28, 2014, 04:08:00 pm »
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).

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Shader Problem
« Reply #40 on: January 28, 2014, 05:09:14 pm »
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)?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Shader Problem
« Reply #41 on: January 28, 2014, 05:49:42 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Shader Problem
« Reply #42 on: January 28, 2014, 05:56:33 pm »
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? :- )

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Shader Problem
« Reply #43 on: January 28, 2014, 06:02:47 pm »
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...

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Shader Problem
« Reply #44 on: January 28, 2014, 06:27:01 pm »
I see now that you effectively skipped the waveHeight line.