Little help with GLSL shaders

Started by Jakes, October 13, 2019, 06:45:43 PM

Previous topic - Next topic

Jakes

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

EgonOlsen


Jakes


EgonOlsen

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.

Jakes

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.

Jakes

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.

EgonOlsen

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?

Jakes

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.

EgonOlsen