Jump to content

csg shape to mimic light


Rick
 Share

Recommended Posts

Someone posted about a Thief like game and I recall I tried messing around with being detected in light before and found it sort of a pain to try and match up csg cone with a spotlight so was thinking for those types of games it might be handy to have a way to easily have something in the editor where if you have csg as a child to a light and check a button it could exactly become the shape of the light cone or sphere in the case of point light. Just remember I forgot to make a request like this. I had a hard time manually shaping the csg to the point light and it wasn't matched up perfectly.

  • Upvote 2
Link to comment
Share on other sites

Actually such a collision wouldn't necessarily mean that the player is really exposed to the light source, as there might be walls or anything else between the player and the light.

Also I assume pointlights should have some kind of falloff (the nearer the brighter), so it would be hard to determine which size the sphere should be.

Instead you should iterate through all the lights and

1. perform a raytrace to determine if you are exposed to the lightsource.

2. for lights that have a falloff (pointlights and spotlights?) check the distance

3. for lights with an angle (directional lights and spotlights) calculate the angle.

 

The only part of that you could make easier by these proposed csg-shapes would be the third one, but that is also easily achievable by using the acos of the dot product of the normalized light's viewing vector and the normalized vector from the player towards the light.

Link to comment
Share on other sites

I wouldn't think you'd need to iterate over all the lights. You should be able to do the raycast from inside the csg light collision function the player is colliding with. The csg matching should handle the falloff then too with good enough precision so nothing to do there as the shape itself is the falloff distance I would think. I haven't played much of thief so don't recall the different light intensities it had.

 

But yes, a raycast then is needed once the player collides with the light csg shape.

 

Either this OR just give lights a Collision function! Easier for us smile.png

Link to comment
Share on other sites

In a modeler it would be a matter of minutes and scaling it you could resuse it on other spot lights.

 

This is what I'm saying. I found it painful (for pointlights anyway as there was different sizes and you'd have to scale it manually for all various sizes) to get it just right in LE myself. Maybe I'm just an idiot but would be nice to have a collision function called for spot and point lights.

Link to comment
Share on other sites

I wouldn't think you'd need to iterate over all the lights. You should be able to do the raycast from inside the csg light collision function the player is colliding with.

OK, you're right with that one.

 

The csg matching should handle the falloff then too with good enough precision so nothing to do there as the shape itself is the falloff distance I would think.

Not really sure, how to interprete that one. Do you only want to distinguish two states ("dark enough to be considered outside the light" and "bright enough to be considered inside the light")?

Link to comment
Share on other sites

OK, you're right with that one.

 

 

Not really sure, how to interprete that one. Do you only want to distinguish two states ("dark enough to be considered outside the light" and "bright enough to be considered inside the light")?

 

I personally don't want anything with this smile.png. I just did a test some months ago and now there is this new person who made a post about trying to do this same thing and it made me think about my test. For my test I just did a simple (in the dark or in the light). I can see if you wanted to do shades of gray in there how you'd have to think of another approach, but for something simple it would be cool to make this csg matching easier to lights, specifically spot.

Link to comment
Share on other sites

If you have directionnal lights also, it won't work and you'll need a method using render ot texture and checking player luminosity.

 

I guess I left off directional light as I don't think thief type games generally use that kind of light.

 

 

@shadmar, Yeah, I would think a shader would be ideal but we all rely on you for that :).

Link to comment
Share on other sites

@shadmar, Yeah, I would think a shader would be ideal but we all rely on you for that smile.png.

 

..and now I had to try.

It works, sample 8 points from 2 spheres where one is inverted to get eventual backlight in a pp-shader.

The spheres have to be visible to sample them, but I think you can have some gui element drawn over them with no problem.

 

You can even have degrees of visibilty. Like 50% visible if half dark or in shadows etc..

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

this is certainly a interesting subject rick.

 

..and now I had to try.

It works, sample 8 points from 2 spheres where one is inverted to get eventual backlight in a pp-shader.

The spheres have to be visible to sample them, but I think you can have some gui element drawn over them with no problem.

 

You can even have degrees of visibilty. Like 50% visible if half dark or in shadows etc..

 

 

neat

OS: Windows 10 Pro

CPU:  i3-10100 CPU @ 3.60GHz
GPU: NVIDIA 2060 Super - 8 GB

RAM: 32 GB

Link to comment
Share on other sites

..and now I had to try.

It works, sample 8 points from 2 spheres where one is inverted to get eventual backlight in a pp-shader.

The spheres have to be visible to sample them, but I think you can have some gui element drawn over them with no problem.

 

You can even have degrees of visibilty. Like 50% visible if half dark or in shadows etc..

 

Yeah, I don't understand what any of this means :)

Link to comment
Share on other sites

If you have std edition you can add this hack for a lua project to read a pixel-value from a texture.

So yes it works now but very hacky stuff. (don't yell I know the static cast will make nightmares in the cpp-camp smile.png )

 

So here is my shadow detector:

 

1. pp effect which reads player lumnosity (lua+.shader)

2. Modified lua exe, added this to support GetPixles()

 

//GetPixels lua port (for 1 pixel)
static int GetPix(lua_State *L){
   int argc = Interpreter::GetStackSize();
   Texture* t;
   t = static_cast<Leadwerks::Texture*>(Interpreter::ToObject(1));  //texture sent from lua
   int datasize = t->GetMipmapSize(0);
   char* pixels = (char*)malloc(datasize);
   t->GetPixels(pixels);
   char r;
   memcpy(&r, pixels+0, 1);
   delete(pixels);
   Interpreter::PushFloat(r); //value pushed to lua
   return 1;
}

 

And now we can sneak in the shadows smile.png

  • Upvote 2

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Ok here is my test project:

 

LUM.png

 

How to use :

 

1. Make a lua project.

2. unzip this into your root

3. delete the original <project>.exe

4. rename the rename_to_projectname.exe to <project>.exe (buildt in VS2013 using LE beta)

5. load sneak.map and run it from the editor, F6

 

If you have Std ed, App.cpp with the lua bind for GetPixles() is added so you can update whenever you want or build for linux yourself.

 

Player's lumnosity you can fetch from anywhere using

camera:GetKeyValue("playerlight")

 

https://dl.dropboxusercontent.com/u/11319604/lumdetector.zip

  • Upvote 3

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

its not working for me. it gives the error:

Failed to load shader "G:/Projekte/Games/Leadwerks/sneakTest//Shaders/PostEffects/00_shaders/_passthrough.shader"

 

when i run it and it is indeed not included in the zip

 

I would assume, that one is one from shadmars PostProcessing shaders from the workshop:

http://steamcommunity.com/workshop/browse?appid=251810

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...