Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to have a lot of static lights you can turn on off in a 3d scene?

Author
Message
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 28th Nov 2015 08:04 Edited at: 28th Nov 2015 08:05
Hi

I´m doing a test project for stage light setup for a friend and I´m going to make a virtual - "Live" version of the setup with the possibility to turn on and of light spots on a stage. This task is not very suitable for a game because of the huge amount of light spots, but since there are no dynamic objects in the 3d scene - only a blank big stage - I wondered if it was possible to trick this by baking each light spot separately and adding or removing the baked alpha for each light when needed...

I´m trying to get into shaders and thought maybe shaders is the way to go.

Anyone know any links or tutorials on the subject?
AJCodes
9
Years of Service
User Offline
Joined: 6th Jan 2015
Location:
Posted: 28th Nov 2015 08:37
So quick thought,

Use Blender to create your stage...i'd start with a long rectangular block and carve out the stage portion leaving the back and floor of the stage. I'd then put a really big texture on it, half the texture for the floor, the other half for the back of the stage. Make it as real as you like.

Load that object and the texture, set em up, set up the camera, etc.

At this point, you can take full control of the render pipeline and set up a point light to fake your spot lights...small size.

Set up a for loop thru your light array, something like (pcode)

for i = 0 to numLights-1
if lights[i].on = 1
Move pointlight to where the spot would hit the stage
Set the pointlight parameters (color, size, etc) = lights[i]
Render it
endif
next

As the stage is empty and you don't have to worry about shadows or ambient occul you don't have to worry about much...iterate thru as many lights as you like. When you're done, flip the backbuffer to the front and you're good.

I'd start with reading up on Render3D and such...how to break up Sync() into it's parts so you can call it in pieces as needed.
Born. Currently living.
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 28th Nov 2015 08:50
AjCodes: That´s a good idea. I´ll test this out and check out the speed of this. I have already made the stage and the light rig in blender. There is 72 different spots so I have to test the performance hit...

thanks
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 28th Nov 2015 20:24
AjCodes - I have tried your suggestion but it seems that update3d() and render3d() only updates objects and not lights...?



AJCodes
9
Years of Service
User Offline
Joined: 6th Jan 2015
Location:
Posted: 29th Nov 2015 02:56
Been awhile since I used the technique...but I think I had to disable the z buffer also...going through old code now.
Born. Currently living.
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 30th Nov 2015 17:10
Quote: "it seems that update3d() and render3d() only updates objects and not lights"

Lights are updated at the same time. It is most likely as AJCodes suggests and the Z buffer is preventing the additional copies from drawing. You would also have to use additive blending with SetObjectTransparency(ID,2) for this kind of multipass lighting to work, however there is currently a bug preventing additive blending from working which is fixed in the next version.

To have the most control over the process then your first thought of using a shader would be the best approach, although I'm not sure if OpenGL 2.0 would support so many lights in a single shader due to instruction count limits, but it might be worth a test. Here is a shader I wrote for 1 texture, 1 directional light, and 1 point light, it should still work in the latest version if you supply the uniform variables agk_PLightPos, agk_PLightColor, agk_DLightDir, and agk_DLightColor with values from AppGameKit with SetShaderConstantByName(), colors are in the range 0.0 to 1.0.

Vertex Shader


Pixel Shader
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 1st Dec 2015 07:21 Edited at: 1st Dec 2015 07:54
Hi Paul

I can't change the direction and the color of the Directionnal Light, how to change it ?
I have tried (in my main loop test) :



But it doesn"t work, the light is always at the same color (white) and the direction is always the same.

EDIT:
in the code (vertex shader + pixel shader) I have replace agk_DLightDir by DLightDir and agk_DLightColor by DLightColor and use

and now, it work.
Perhap's there is a bug with agk_DLightDir and agk_DLightColor ?
http://www.dracaena-studio.com
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 1st Dec 2015 15:25 Edited at: 1st Dec 2015 15:26
Blendman, is it possible for you to post the whole test code you did? (That is - if it´s not part of larger scenario..) I really need to learn the whole setup....

The community shader thread is so great. But they lack the main program, so it´s a little difficult to learn how to setup the shaders and communicate with them....

Tim
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 1st Dec 2015 17:02
@TimShark : in fact, it's not too complex

- you need to create 2 files : shader.ps, shader.vs, place it in your media folder. These files are your shader.

Shader.ps :


Shader.vs :



The AppGameKit code :




I hope it help .







http://www.dracaena-studio.com
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 1st Dec 2015 19:22
Blendman, Thank you for your help and sharing.

I have put everything up with my own texture.jpg image but the program throws this error:
"Vertex shader shader.vs failed to compile: ERROR: 0:5: '<' : syntax error: syntax error"

Whats happening?

Tim
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 1st Dec 2015 20:14
Do you use the 2.015d ?

It works on m pc, I don't know why it doesn't work for you.
http://www.dracaena-studio.com
linuxluvuback
8
Years of Service
User Offline
Joined: 17th Oct 2015
Location:
Posted: 2nd Dec 2015 01:21
Thanks, Blendman that was my first time(shader)...

Tim it's you - it works fine for me (mint 17.1 64bit with quadro +nvidia driver) :

//LoadImage(1,"texture.jpg")
LoadImage(1,"Knight.png") // This image is from http://opengameart.org/content/animated-knight-walk-edit
// ^^^ with this texture you can easily see color change on top of sphere

LoadShader(1, "shader.vs", "shader.ps")
SetObjectShader(1,1)
SetObjectImage(1,1,0)
SetShaderConstantByName(1,"DLightDir",-0.3,-0.3,0.7,0.0) // direction
SetShaderConstantByName(1,"DLightColor",1,0.5,0,0.0) // rgb : 0 to 1.0
SetShaderConstantByName(1,"agk_PLightPos",10,10,10,50) // position of the point light (x,y,z)+ range
SetShaderConstantByName(1,"agk_PLightColor",0,0,1,0.0) // blue color
SetShaderConstantByName(1,"ambient",0.2,0.2,0.2,0.0) // ambient color

x# = 0.0
do
Print( ScreenFPS() )
sync()

SetShaderConstantByName(1,"DLightColor",1,x#,0,0.0) // rgb : 0 to 1.0
x# = x# + 0.01
if x# > 1.0 then x# = 0.0
loop


Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 2nd Dec 2015 02:49 Edited at: 2nd Dec 2015 03:40
Blendman, Yes, Im using 2.015d. I´m on a mac.

I also tried to change DLightColor and DLightDir back to agk_DlightColor and agk_Dlightdir. with no luck. Same error...

EDIT:
I tried to run this in my windows 10 machine. But It throws me a different error:
"Vertex shader shader.vs failed to compile FLEX: Unknown char Á ERROR: 0:2: ´Á´: syntax error syntax error"

I´m starting to suspect some encoding problems....I use Textedit.app on mac to make the scripts and always make sure they are in pure text. The shaders I´ve tried in the community shader thread also throws me errors. But the bloom example from agk works....
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 2nd Dec 2015 04:10 Edited at: 2nd Dec 2015 04:13
Ok. I changed my text editor to textwrangler. It saves my script in unicode and everything works now.

so beware MAC users: textedit on mac is fishy. Notepad in windows is ok.

Again, thanks for sharing, Blendman. Now I can dig into your other shaders in the generous community shaders thread !!

such a joy...
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 2nd Dec 2015 07:09
@TimShark :
great ! I'm happy it works for you ^^.
If you make some cool shaders, you can post it in the usefull thread for shaders, if you want .
http://www.dracaena-studio.com
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 2nd Dec 2015 15:10 Edited at: 2nd Dec 2015 18:54
Paul, I forgot to thank you for the initial code. Always helpful.

I learned how to communicate with the shader now.

If I could ask anyone to add another point light to this shader - It would be a real lesson.

Is the point light in this shader the same as a point light in agk? Or is it outside the limits of agk lights?
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 3rd Dec 2015 16:45
I forgot I'm still using agk_DLightDir and agk_DLightColor internally so they get overwritten by AppGameKit, so you are correct that they need renaming.

These lights are outside the AppGameKit lighting system, you define the position and color of each light manually using SetShaderConstantByName.

To add a new point light you'd do something like this (untested)



Unfortunately you may run into a shader instruction limit after a few lights, at that point you'd have to start using additive blending with multiple passes.
AJCodes
9
Years of Service
User Offline
Joined: 6th Jan 2015
Location:
Posted: 4th Dec 2015 05:07
Not sure what the timeline is for an update that will fix blending vs. the timeframe you need for your app, but another approach might be:

1. Split your stage into multiple objects. Let the background and stage be one object with a single texture stretched over both objects. Walls, other stuff as other objects that wouldn't be impacted by the lights.
2. Copy the stage texture to a memblock. Based on where each spotlight would hit, manually index into the memblock and change/blend the light in
3. Repeat for each light.
4. Reapply the texture to the object.

You'd only need to do that when each light moves/turns on/turns off rather than each frame.
Born. Currently living.

Login to post a reply

Server time is: 2024-04-20 05:54:08
Your offset time is: 2024-04-20 05:54:08