Author Topic: Little help with GLSL shaders  (Read 4529 times)

Offline Jakes

  • int
  • **
  • Posts: 63
    • View Profile
Little help with GLSL shaders
« on: October 13, 2019, 06:45:43 pm »
Hello,

I dunno if this is the correct forum for it, but if its not, can someone please point me out a good place?
I'm trying to write a shader that could simply render a scene, with multiple lights, texture, and fog.

I only want to override the factory shader that comes by default, because it only supports 8 lights, and I need a bit more, so while trying to write a shader I came across a lot of issues such as problems while using multiples light sources, fragment program with texture coord.

Can anyone help me out?

Many thanks,
Jakes

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Little help with GLSL shaders
« Reply #1 on: October 13, 2019, 06:52:24 pm »
Is this jPCT or jPCT-AE related?

Offline Jakes

  • int
  • **
  • Posts: 63
    • View Profile
Re: Little help with GLSL shaders
« Reply #2 on: October 13, 2019, 07:21:45 pm »
Hello,

its jPCT (Desktop).

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Little help with GLSL shaders
« Reply #3 on: October 13, 2019, 07:30:29 pm »
In that case, I'm not sure what you mean by factory shaders. The desktop version uses the fixed function pipeline by default. You can of course write your own shader to replace it, but unlike the Android version, it doesn't provide a set of default shaders.
That said, I'm not sure what you exact question is!? You can look at the wiki for jPCT, which has some basic shader examples for desktop jPCT as well. Regarding light sources, the fixed function pipeline is limited to 8 and so is GLSL when using the magic attributes that OpenGL injects into a shader (depending on the GLSL version). If you need more, you can inject them into a GLSLShader by using the method that the class provides for adding a float array uniform. What you store in there and how you access it within your shader is up to you in that case.

Offline Jakes

  • int
  • **
  • Posts: 63
    • View Profile
Re: Little help with GLSL shaders
« Reply #4 on: October 13, 2019, 08:56:26 pm »
Well, yes, I've already implemented the GLSLShader class into my scene, and hooked it up to the renderhook, it works, the thing is that I want to replace the fixed on by a custom one, in order to "emulate" more lights using per-pixel lighting. I was only trying to ask for some examples or guidance on C code for shaders as I've been searching a lot in the web lately for any and many failed.

But thanks for the tip.

Offline Jakes

  • int
  • **
  • Posts: 63
    • View Profile
Re: Little help with GLSL shaders
« Reply #5 on: October 13, 2019, 09:00:01 pm »
And yes by "Factory" I meant the fixed function the is given by default to render in the pipeline. What I wanted to do is use more than 8 lightsources as the same way you can have when using non compiled objects, whereas when using compiled ones you only get 8 by default.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Little help with GLSL shaders
« Reply #6 on: October 14, 2019, 12:56:24 pm »
I see. Yes, that's because for uncompiled objects, the light calculation is done in software, which is limitless. But for compiled ones, it happens in the pipeline, which is limited to 8. However, it will use the 8 nearest lights per objects for that. Isn't that sufficient in your case?

Offline Jakes

  • int
  • **
  • Posts: 63
    • View Profile
Re: Little help with GLSL shaders
« Reply #7 on: October 15, 2019, 10:49:29 pm »
Aha, ok, so that's the difference... so my 2 posts might be correlated then, couldnt it be the reason that while lights are software calculated they will have to cache something thus giving me some initial hickups?

well 8 lights kinda works badly when trying to use some light points for entities around the scene, 10 or 20 lights is an easily target to reach. Although I only need around 10/12 at the same time for 1 scene, but it only takes one light to not work to ruin everything because sometimes the GPU picks the most important one like the sun for instance, so I end up with half dark world.

So I wanted to write my own GL Shader using pixel-light for each object, where I can "use" as many lights as I want, but I tried many articles and such to no luck at all.

I don't even wanna lose time on writing one, I thought I could just use some examples of one that basically helps me using more than 8 lights (the same as uncompiled objects) with multiples textures and fog, thats it! but I can only find examples that doesn't apply one of these.

and for what I can tell, learning GLSL and writing one program, will take me like a decade, this is like Latin, a hard and lost art that we still need.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Little help with GLSL shaders
« Reply #8 on: October 16, 2019, 12:34:36 pm »
How can prioritize lights by using http://www.jpct.net/doc/com/threed/jpct/util/Light.html#setDistanceOverride(float)...maybe that helps?