is it possible add 3d light and 3dshadow tec to c3

0 favourites
  • 7 posts
From the Asset Store
Kids Game
$49 USD
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • can we get point list (camera can see) for 3d model.and render point poly with black color to make 3d shadow ....

    use p black caculate p red

  • Construct 3 isn't a 3d engine. Easiest would be to just fake as much as you can. But here are some thoughts on various ways to do shadows such as "shadow mapping", "shadow volumes" and "ray casting". In construct there are limits but we do have math, distort meshes, canvas and shaders that can be used in creative ways.

    Shadow mapping

    This is a common way to do shadows where you first render the scene from the point of view of light to a depth texture and then use a shader when drawing from the camera's view to tell what is in shadow.

    Construct can only render one view at a time and the canvas has no depth. However you probably could make an effect that takes the depth and draws a color. Then you could change the view from the light, use the effect to draw the depth as colors, snapshot the screen, then use that texture with another effect to draw the shadows.

    - you need to have the camera and view matrices. It's not readily accessible but you can calculate them manually.

    - you have to write shaders. You are also limited number parameters in C3 shaders so you will have to adapt any online guide about shadow mapping.

    - not suitable for Realtime since you have to dedicate a frame to draw the depth.

    - on top of that capturing the screen can take a bit.

    - Lastly and most importantly It can't work because we can't access multiple textures in shaders in C3. I can't think of a workaround for this.

    Shadow volumes

    Uses polygon clipping to find what area of each polygons are in shadow. Often done along with BSP trees to be more efficient.

    - you need a list of the vertices and faces. C3 does not provide access to those so we'll need to calculate and provide them ourselves.

    - BSP trees are needlessly complex to implement in events, but even with them this shadow method doesn't scale as well with higher polygon counts.

    - will give perfectly crisp shadow edges, and will be 100% black without further trickery.

    - will have to draw the shadows over the mesh with distort meshes. Probably will have to move slightly toward the camera to avoid z fighting.

    - This is the closest to being feasible in vanilla C3 solution, but it may not fit in 25 events.

    - may only be fast enough for Realtime with low poly counts, but it would have to be made first to find out.

    Ray casting

    This is an alternate idea to make the 3d objects from canvas' wrapped with distort meshes. The idea is to shoot a bunch of rays from the camera and when the mesh is hit you'd calculate where on the canvas object was hit and color that.

    - it would be pretty slow so you'd only be able to shoot a few hundred rays per frame. But over time it would be better shaded.

    - It would also not scale well with higher poly counts.

    - as with the other approaches it would take a fair amount of 3d math with matrices and vectors.

    Overall even without the limits of the 3d in construct those are all fairly involved to do. The second way seems almost doable but likely just as a novel demonstration.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So I managed to to make a demo of realtime shadows between two cubes an a ground plane with a point light. It's using the shadow volume method using polygon clipping.

    dropbox.com/s/f9x1ov9fy7y7bpr/3d_shadow_volume.c3p

    You can drag the cubes if you click on the the middle of them. The fireflies in the shadows are from Z-buffer precision limits. The edges show sometimes as well since the shadows are offset slightly to reduce z-fighting.

    To fit it into 25 events it's currently limited to just the two cubes and ground plane. However I think I can see at least one more event I can squeeze out of it so we could have any number of cubes after some refactoring, but that's for another day. Overall it was an interesting test, but to make it simple to use in general would require a lot more work.

    Anyways, cheers!

    EDIT:

    made it so you can add as many blocks as you want and added block color.

  • Love it, nice work! Any thoughts on doing this for more complicated objects (e.g. my 3DObject add-on :) )

  • Currently it takes all the polygons facing the light, loops over each pair and casts shadows on each one. Kind of brute force but I should work on any mesh.

    The meat of it is clipping a polygon by a plane. Then a shadow is cast on one polygon (A) onto another polygon (B) by taking all the edges of A and making plane with the light position, then clipping B by all those planes.

    An improvement would be to use a a binary space partition in conjunction with that to do that more efficiently so higher speeds with more polygons is possible. Google SVBSP (shadow volume binary space partition) for the algorithm.

  • Thanks for the explanation R0J0, good details.

  • So I managed to to make a demo of realtime shadows between two cubes an a ground plane with a point light. It's using the shadow volume method using polygon clipping.

    https://www.dropbox.com/s/f9x1ov9fy7y7bpr/3d_shadow_volume.c3p?dl=1

    You can drag the cubes if you click on the the middle of them. The fireflies in the shadows are from Z-buffer precision limits. The edges show sometimes as well since the shadows are offset slightly to reduce z-fighting.

    To fit it into 25 events it's currently limited to just the two cubes and ground plane. However I think I can see at least one more event I can squeeze out of it so we could have any number of cubes after some refactoring, but that's for another day. Overall it was an interesting test, but to make it simple to use in general would require a lot more work.

    Anyways, cheers!

    EDIT:

    made it so you can add as many blocks as you want and added block color.

    nice jop!you use mesh creat everyting! real usefull!You're a math genius。

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)