Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Four dimensional lighting.

Discussion in 'General Discussion' started by neginfinity, Jun 17, 2018.

  1. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    I've spent my morning tinkering with this, so I decided to share it:

    https://www.shadertoy.com/view/4dGBRy



    Basically, it is a relatively simple raytracing shader with ligthing and interreflection support that works in 4d space.

    I wanted to try it for some time, never really got around doing it... till today.
     
    Mauri, WillNode, Jamster and 2 others like this.
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    By the way, this is something that could be interesting to try in a VR headset (which shadertoy doesn't support, afaik).

    Basically, in this case the viewer is defined as a set of four-dimensional vectors - front, right, up, position. The usual stuff. Those are used to shoot the rays.

    Now, In a VR environment, eyes will be shifted left/right using "right" vector relative to position.

    The thing is, as long as they're not using 4th component, it'll be the same as 3d. However, when viewer is rotated in such way that one of the vectors start poking into 4th dimension, eyes will have different fourth coordinate, and that is likely to result in visuals that will be different for each eye in an unusual way people normally don't experience.

    I kinda wonder what it would feel like. (-_-)
     
    ippdev likes this.
  3. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    789
    That sounds really interesting.
    Maybe it would be a whole new feeling of experiencing the 4th dimension?

    There are a few games out that make use of 4D, but in the end it has to be projected into a 3D scene, which then has to be projected onto a 2D screen.

    It stands to reason that with VR you can get one whole dimension closer to 4D!
    Definitely keep us updated :)
     
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    There's a risk that it'll be much more efficient at making player vomit, though. (-_-)

    I'm not sure if I'll pursue this further. I kinda WANT to see what it looks like, but that is not a very strong "want".

    The only "VR" hardware I have is a cardboard compatible phone, and performing an unproject for a VR is more difficult.

    Then again I made raymarchers for my mobile phone before, so I suppose I could give this one a whirl too, using similar methods.

    Hmm.... maybe in a few days? I'll post an update if I make something.

    At the very list this thing needs to be translated into either CG or unity hlsl first.

    --edit--

    Yeah, I think I'll give it a whirl after all. In the end it should make a decent/fun demo.
     
  5. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,956
    What is 4d?
     
    Billy4184 and angrypenguin like this.
  6. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    ?
    4 dimensional. instead of 3 dimensional. XYZW instead of XYZ coordinates. For everything, pretty much.
     
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,504
    Sure, but... what are you using the extra dimension for?
     
  8. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    (-_-)
    Did you watch the video? Have you checked the shadertoy page? Or the code?

    It is kinda self-explanatory.

    That's 4 spatial dimensions, by the way.
    In the shader, you have 4 spheres. One sitting at zero (gray), two (green and blue) orbiting it in XY and XZ planes, and the last one red is orbiting the red sphere in XW plane.

    Over course of animation the viewer position frist moves between two points with W=0 coordinate, but later shifts to location with non-zero W.

    The viewer is looking at (0.0, 0.0, 0.0, 0.0) coordinate at all times.

    All objects are processed in 4d space. If you wanted, you could modify the shader parameters and change sun to orbit around different vectors, so instead of XY axis it would spin around XW, or something. It would still cast shadows.
     
    Last edited: Jun 18, 2018
  9. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    It seems I misunderstood the question.

    Everything is 4d, including the viewer. However, red, blue and green spheres are moving in W=0 coordinates, while ground plane spans all dimensions (obviously) and only red sphere and the camera are moving along fourth coordinate. When the scene starts to "deform" it is camera moving to negative W, while looking at (0.0, 0.0, 0.0, 0.0).
     
  10. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,383
    Where is W?
     
    Joe-Censored likes this.
  11. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    What do you mean "where"? It is fourth axis that is perpendicular to the first three.

    When you start seeing red sphere all the time, the camera is sitting at negative W coordinate while looking at (0;0;0;0)
     
  12. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,982
    Interesting.

    Reminds me a lot of 4d toys

     
    Jamster and MD_Reptile like this.
  13. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,383
    What is the use of this?
     
  14. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    It is a toy.
     
    AcidArrow likes this.
  15. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    5,983
    Interesting. If one considers how something seen as a circle in 2D can actually be a sphere, cylinder, cone or all sorts of other things in 3D, then the way that a 4D shape (seen in a 3D perspective) changes as it moves through the 4th dimension (or rotates about x, y or z on the w-plane) can be impossible to predict without being able to see along that extra dimension.

    Now, where is the Blender support for 4D models?
     
  16. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    8,956
    Sorry, was being snarky / pedantic. Feel free to disregard.
     
  17. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    And here I thought the 4th dimension was Time.time :)
     
    EternalAmbiguity likes this.
  18. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,383
    I think people need to actually decide what 4D means.
     
    EternalAmbiguity likes this.
  19. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,982
    4D is (in this context) a 4th dimension, there isn't anything to decide.
     
  20. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,383
    In application isn't that too vague to be useful?
     
  21. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    Lol this is not the first time I've seen 4D stuff and thought (seriously thought) "what in the world is that fourth dimension doing?".

    I'm glad I'm not the only one who doesn't get it :D

    EDIT: To clarify - I don't understand how 4 dimensions changes things. In 3 dimensions my mind seems to understand that up and down, left and right, and forward and backwards are the possible directions for a thing to move. I can't wrap my head around "where" that fourth dimension is taking an object....
     
  22. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,982
    Useful?

    I don't understand you.
     
  23. BIGTIMEMASTER

    BIGTIMEMASTER

    Joined:
    Jun 1, 2017
    Posts:
    5,181
    Somewhere, alien overlords laugh as primitive apes grasp at a mere 4th dimension and it's utility.
     
    xVergilx, AcidArrow and MD_Reptile like this.
  24. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    Try to think a shadow of nD object; it is downgraded by 1D. You are 3D object, but your shadow is 2D.
     
  25. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,092
    How about a game where you have multiple maps that exist within the same space? An easy example would be the Legend of Zelda: Link to the Past where the player must switch between light and dark variations of the world map to progress.

    LightDarkWorld.png
     
    Last edited: Jun 18, 2018
  26. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    That's a common misconception.

    Time is not a spatial direction. Otherwise you would've been able to rotate itself so you'd be moving along x with time axes being to your right instead of x.
     
  27. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    "Pathetic creatures, unable to grasp reality with only 4th dimensions. *waves 11-dimensional tentackle about*"


    An 1d space is a stack of dots.Where any point of the line is a dot, and you can move about it seamlessly.
    A 2d space is a stack of lines. Where any point of a line is another line and they blend into each other seamlessly.
    A 3d space is a stack of 2d spaces. Where any point of the line, s another 2d space, and by moving along you'll have one of them belnding into another seamlessly.
    A 4d space is a stack of 3d spaces. Where any point of the line is a 3d space, and moving along the W makes them blend into each other seamlessly.
    A 6d space is a 3d space where each point is a 3d space.
    And so on.

    A creature that lives in a 2d world and sees a 3d sphere pass through it will be seeing slices. First there will be nothing, then there will be a smal lcircle that will expand to the sphere's maximum radius, and then contract and disappear.

    A creature that lives in a 3d world and sees a 4d sphere pass through it will be seeing slices as well. First there will be nothing, btu then there will be a small ball that will expand to 4d sphere maximum radius and then disappear.

    The problem here is that in to fully experience 4d space you'll probably need 3 eyes, if the eyes are acting like photo cameras.

    In the example I made the eye acts like a normal camera that projects onto 2d, because it is defined by 4 vectors - position, forward, right, up. That gives it a fairly bad case of tunnel vision when it comes to 4d.

    It might be possible to think about a differnet kind of projection, though
     
    JasonBricco likes this.
  28. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Can you visualize 4th dimension in your head .....?............ :)

    All those definitions are not classical , nor not-classical physics definitions of "Dimensions " ...
    just the same mathematical , string-theory ...... etc work of Fantasy .
     
    Last edited: Jun 19, 2018
    zombiegorilla likes this.
  29. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,663
    I get the first part - the 2D slice of a 3D world - but I don't get the second part. I can't wrap my head around there being another "slice" of a dimension above our own 3 traditional dimensions.

    Anyway I sort of follow what your saying and appreciate the explanation :)
     
  30. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    You're standding on XYZW 0, 0, 0, 0, surrounded by 4d teserracts (cubes) of varying size (cube means XSize == YSize == ZSize == WSize). Your view vectors are all with W = 0, meaning you aren't trying to peer towards 4th axis, and you view surroundings in the same way as camera in the example does. You have mostly normal human eyes, meaning the light projected through the lense and forms a 2d picture on retina. Except the light is four dimensiona.l.

    You see bunch of cubes around you. Bigger smaller. THey look like normal cubes.

    Then while standing still and maintaining restructions on view vectors (W == 0), you start moving along the W axis while standing still on XYZ. For a while all looks the same. Then smaller cubes disappear, because you can no longer see them. At the point hwere you moved too far away you'll see nothing, becasue your eyes geared to 2d are having bad case of tunnel vision.

    That's the part about a "line where each point is a 3d world". You're standing still on XYZ. What you "See" is a 3d slice of a 4d space aroudn you. While moving along the "line" (which is W axis) the slice you perceive would change, and you'll see different things. Same thing as a 3d sphere passing through a 2d plane.

    Thinking in 4d itself is quite problematic, because this is not what people are used to or can easily experience. But if you keep in mind this interpretation - a line of 3d space - it is manageable.
     
    MD_Reptile likes this.
  31. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    5,983
    The way I think about it is like this: If you have a 3D object projected into 2D (e.g. a shadow) then the 2D shape (shadow) changes as you rotate the 3D object. The 2D shape changes in both of the two dimensions of the 2D projection during rotation

    That's why a 4D object seen in a 3D projection changes shape in all three dimensions as it is rotated in 4D space.

    So let's go back to the 3D object being projected into 2D (shadow). If the 3D object is a cone, and the light source is behind it, then the shadow will show a circle. As you rotate it, the 2D projection will start to change shape according to the information previously represented only along in the 3rd dimension (the way that it goes from a flat circle to a pointy tip). So with a 4D shape, as you rotate it, the 3D projection will change according to the information that, previously, was only represented along the 4th dimensional axis.

    So we probably can't 'see' the 4th dimension, but since we can see three dimensions at once, we can conceive of it by momentarily transferring our usual (x,y and z) perspective to (y,z and w).
     
  32. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    It is actually a fairly good analogy.

    The difference is that rather being a "shadow" you have a camera that projects scene onto a canvas with lower number of dimensions. At least in this example.

    --

    Few other interesting things to ponder:

    * 4d lights will appear dimmer if you're sitting at W=0, and they're removed far away from you on W axis. Even if they have no attentuation. That's because W component affects both distance and light normal. So if you're sitting in the "normal world" (meaning W=0), and a light source will start moving away from you on W axis, it'll gradually dim, out.
    * It is possible to have "interdimensional" shadows. If you make a 4d spotlight, and point it at W=0 from W =/= 0, then lit spot will include objects inbetween those coordinates, which could include objects player can't currently see due to camera orientation.
     
    Last edited: Jun 19, 2018
    Billy4184 likes this.
  33. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    Well.... I made a Cardboard build, and to be honest I'm not seeing anything unusual when the shader starts jumping to fourth dimension coordinate.

    That was a letdown.

    Perhaps I'd need weirder objects.
     

    Attached Files:

  34. WillNode

    WillNode

    Joined:
    Nov 28, 2013
    Posts:
    420
    Wait, does Unity can do Raytracing? I thought It's only exist in DX12 which is a fairly new technology.

    EDIT: I tried and it worked, DX11. I must be missing something.
     
    Last edited: Jul 1, 2018
  35. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    Any system that has shader support above DX9 level can implement raytracing using shaders on GPU.

    Especially raytracing against pure mathematical primtiives like spheres.
     
  36. WillNode

    WillNode

    Joined:
    Nov 28, 2013
    Posts:
    420
    I looked at the shader code you shared and quite surprised that it's just regular vert and fragment code.

    Nice shader trick, btw. I was under impression that it uses DXR in DX12 :D
     
  37. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    It doesn't use DXR, obviosuly, as it was originally implemented as a WebGL shader.

    Speaking of DXR it is most likely possible to implement similar system using either Computer or Pixel shaders. The question is efficiency of the result, of course.

    As far as I can tell currently Microsoft will try to use DXR to push people onto their next Windows release, as they did before with DX10.
     
    WillNode likes this.
  38. WillNode

    WillNode

    Joined:
    Nov 28, 2013
    Posts:
    420
    (Sorry for being late to the party, I wasn't though this gonna be a moderately long post but I have interesting thought and experiences that I want to share (and few bits of rants))...

    This is what would be like:

    4DGizmoRotateIsAwesome.gif

    ^ Assume this is Scene Gizmo, but in 4D. (Yellow == W)

    There's some cool animation I wasn't think of.

    In the end it looks like we're summoning a new dimension while sacrificing the other dimensions out of nothing.

    And six rotations of freedom ;)

    Only physician will tell you that :p

    Only for simple games. Don't expect to see 4D AAA games become mainstream before we can put Quantum computer in our laptops (I'm serious, keep reading)

    No, it's an overly simplified depiction of 4 dimensional realm :cool:.

    It's not impossible as long as you knew the math behind that geometry. I mean somebody already figured on how to build sphere to any N-dimension, for example.

    However, there's one thing that I concern with: Complexity. Computation cost grows exponentially for each N in dimensions. For example, a circle with 4 subdivision has 16 verts, while a sphere has 128 verts. Now guess how much for a 4D sphere?

    2048

    Look small? Just deploy a hundred of them and you'll notice it's unforgiving cost. That's just unacceptable for such simple objects.

    Actually there are two ways (or three, if you count this) for one creature sees a higher world. What you describe (and everyone discussing here) is what commonly call as "Cross Section". The other projection type, Frustum, is what deployed in all 3D games -- or the one with Cube in a Cube if you familiar with that.

    What makes cross section so common in 4D is that because it's simpler: If you slice a 4D sphere, you get a simple sphere. That's also why it just "expands" and "shrinks", a same analogy when you cut a sphere and getting a circle out of it. You'll never get a complete depiction of what the object is unless you deploy another unique projection type: Frustum.

    Screenshot (247).png

    (if you ask me, yes that will still look like a sphere if the sphere is opaque)

    Nope, what's actually you need is MORE CONTROL. For such simple thing like orbiting an object, you can use mouse to rotating the camera horizontally and vertically, but what about into 4th dimension? Definitely not the ScrollWheel :eek:

    Also our eyes is 2D. Looking into 4D objects is a lot like looking to a camera inside a camera -- Which means there must be two things to control! So in my opinion in order to fully experience 4d world, you have to use VR headset while holding a gamepad in your hand (and use that to rotate 4D objects around) :D


    Finally About Lighting in 4D:

    I agree with everyone here. The general rule is shadow always one dimensional less than the object. But then it depends on what projection you choose -- Cross Section is easy (in theory) as it slices that shadow again into 2D at the end. But Frustum?? Maybe somebody knows how to do Volumetric Shadow? :confused:

    CONCLUSION

    It's always cool to try and think one dimension higher. I like to learn this kind of topic. It's just that lighting is one of most puzzling thing I can't think clearly (the other is UV and Proper Input Controllers).

    I appreciate OP sharing and tinkering this raytracer. There always something new to learn :)
     
    Last edited: Jul 1, 2018
  39. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,316
    Zero. Zero vertices for 2d (circle), 3d, 4d or 5d sphere.

    It is a perfect mathematical perspective. Being a mathematical primitive, it doesn't need to be polygonized.

    No. That's absolutely not what I meant.

    I was talking about stereoscopic parallax effect in 4d which can be only experienced with two eyes
    Your gif is 2d and depicts view only of one eye. Therefore it does not display the effect.

    My own VR test with my cardboard-compatible phone did not demonstrate significant effect due to eye distance, however. Which is a pity
     
  40. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    Is there anything 4D about them?
     
  41. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,982
    Yes, the math behind them. Did you watch the video?
     
  42. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    nah, just looked at a frozen frames and assumed it's stoner fuel.
     
    zombiegorilla likes this.
  43. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    10,982
    Okay then, some more stoner fuel for you, since you seem to enjoy that:

     
    chelnok likes this.
  44. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,244
    Guilty as charged, I'm afraid.