User Tag List

Page 2 of 2 FirstFirst 1 2
Results 11 to 19 of 19

Thread: 3D Voxel Model Shader

  1. #11
    Forum Moderator Fusion 2.5 MacFusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleFirefly 3D ModuleInstall Creator Pro
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Mac Export Module (Steam)Universal Windows Platform Export Module (Steam)Firefly 3D Module (Steam)
    NaitorStudios's Avatar
    Join Date
    May 2010
    Location
    Brazil
    Posts
    1,606
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Sounds good!
    Yeah, the PlayStation resolution is not too bad and would look like and interesting game, specially with a crt/ntsc shader applied to the frame.

    Honestly I've always wanted to make something Minecraft style!
    The fake depth buffer also sounds good.

  2. #12
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLC

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,553
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Nah, it's not for yet another Minecraft clone. Cubes are boring and ugly.



    It might not look like much, as I'm still testing with cubes, but each one you see is actually now a proper 16x16x16 voxel model, that you could make any shape you like - for example, remember my old Sopwith biplane?



    Just having some troublesome rounding issues at the moment, but it's getting there...

  3. #13
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLC

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,553
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    I've managed to fake a depth buffer in DX11, so now separate actives can be placed "inside" the voxel world, which is quite a significant change:



    The trick is that instead of using the red, green and blue components to store the colour of the voxel, I just use the red component to define a palette index, and then use the green and blue components to store lighting and depth information. And then each object samples the background, reading the blue component to decide whether it's in front of or behind it. And finally, another shader samples the red component and uses it to look up an RGB colour from a palettte image to display.

  4. #14
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleFirefly 3D ModuleInstall Creator Pro
    aenever's Avatar
    Join Date
    Jun 2013
    Posts
    1,691
    Mentioned
    34 Post(s)
    Tagged
    0 Thread(s)
    Very impressive, every time I check you're making amazing progress.

  5. #15
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLC

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,553
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Merry Christmas!
    Just thought I'd share the progress I've made on my Voxel World shader.
    I decided to try making a more complex scene (based on an image found online) as a way to test the shader, and decide what works and what doesn't, and what needs adding. I know I could fix some things with it, or add more detail, but I think it's served its purpose now.

    In a nutshell:
    * Happy with performance.
    * Not happy with lighting - will change to using a point light source instead of directional lighting.
    * Desperately needed a way to flip/mirror voxel blocks, so have now added that.


  6. #16
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export Module
    VBEinc's Avatar
    Join Date
    Oct 2015
    Posts
    881
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MuddyMole View Post
    Merry Christmas!
    Just thought I'd share the progress I've made on my Voxel World shader.
    I decided to try making a more complex scene (based on an image found online) as a way to test the shader, and decide what works and what doesn't, and what needs adding. I know I could fix some things with it, or add more detail, but I think it's served its purpose now.

    In a nutshell:
    * Happy with performance.
    * Not happy with lighting - will change to using a point light source instead of directional lighting.
    * Desperately needed a way to flip/mirror voxel blocks, so have now added that.
    Looks awesome! I agree with the Minecraft thing.
    However, the way minecraft only shows you surfaces you actually need to see is awesome for saving resources.
    Excellent work so far!

    As far as lighting goes. Maybe to save resources just have a .png in front of the player which size is controlled by floating Actives around the player.
    I.E. Left Active controls the stretch of the .png out to whatever it collides with. Right active does the same off to the right of the player's view. Same with up and down / Directional.
    If the active comes in contact with an object it forces the X of the active inwards squeezing the .png to make the light look like it is reflecting. Even though, it's obviously not true light!

    Example file
    Click image for larger version. 

Name:	FAKE LIGHT.jpg 
Views:	9 
Size:	27.9 KB 
ID:	32152

    Attached thumbnails Attached thumbnails Click image for larger version. 

Name:	muddy.jpg‎ 
Views:	15 
Size:	14.8 KB 
ID:	32153  

  7. #17
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLC

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,553
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Thanks I like the vignetting for a kind of flashlight effect - especially in horror games.

    The lighting system actually has a pretty negligible cost in terms of performance. Basically, the shader relies heavily on one complex function which gets the contents of a point in 3D space. The lighting system is mostly just calling that function once for each space neighbouring a solid voxel that a ray hits (so 6 times if we just consider orthogonally adjacent spaces) in order to calculate a surface normal. However, the same function gets called once for each space between the camera and that first solid voxel that the ray hits, and that distance is generally going to be much, much greater than 6, and potentially as much as 1000 (or whatever the maximum draw distance is). The cost of the fog/darkness effect is essentially zero, since it's just using information that we needed to calculate anyway.

    The real issue is that unlike outdoor environments, which often only have one lightsource (the sun), indoor environments usually have many (that test scene has rows of lights in both the ceiling and floor). Baking the light into the model is the obvious solution, and that's mostly fine (apart from making it even more difficult to create maps), except for when there are glowing objects such as lamps - it looks very wrong for them to be affected by the darkness/fog, the same as any other material.

    I think I need to replace the directional light with a point light (ie. instead of using a fixed light vector, I'd use the vector from a fixed point to each voxel). It could still be used like a directional light if placed far away from the scene, or it could be always placed at the player's location for more of a torchlight effect.

    And then I'm thinking that the 256 colour palette could be divided into sections with different properties - for example:
    0: transparent
    1-50: matte surfaces (no specular highlights)
    51-150: standard surfaces
    151-200: glossy sufaces (more intense specular highlights)
    200-245: illuminated surfaces (effect of darkness varies continuously, from 200:"almost normal", to 245:"almost no effect").
    246-255: emissive materials (not affected by darkness at all)

    The real challenge will be "inserting" models using separate actives into the same scene. The demo above with the smiley face shows that the depth system should work, but the objects still need to be correctly positioned, scaled, rotated and illuminated to match everything else (or at least positioned and scaled in the case of a billboarded 2D sprite) - that's going to involve a lot of complicated maths, much of which needs to be done outside the shader, using CF2.5 events...

  8. #18
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLC

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,553
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Who wants a little maths lesson?

    The shader for the tile-based voxel environment is pretty much finished now, so it's time to move on to the next part of the engine - other objects that can be placed within the environment.



    Let's start with 2D "billboard" sprites - and just while we figure out the maths, we'll work in two-dimensions only.

    So, first of all we need a vector pointing in the direction the camera is facing:
    camDirX = cos(cameraAngle)
    camDirY = 0 - sin(cameraAngle)
    (right now, that's a "unit vector", with a length of 1)



    Next we need a vector (purple) perpendicular to that, some distance in front of the camera, and with a length equal to the width of the viewing window. If if we were to draw lines from each end of this vector to the camera, the area inside would be our field of vision.
    The distance of this vector from the camera (ie. the length of the orange vector) defines how wide the field of vision is - the shorter the distance, the wider the field of vision (we just pick a value that looks "right").

    Next, let's calculate the vector perpendicular to the camera direction vector. To do this, we simply swap the X and Y components, inverting one of them. Note that there are two possibilities - either 90 degrees to the left or 90 degrees to the right - so we'll pick the vector to the right.
    perpCamDirX = -1 * camDirY
    perpCamDirY = camDirX



    Now, we need the vector from the camera to the sprite (white).
    camToSprX = spritePosX - cameraPosX
    camToSprY = spritePosY - cameraPosY

    Next comes the clever part. Instead of using the sprite's position relative to the X and Y axis, we can find its position relative to the camera direction (orange) and the vector perpendicular to that (blue). We can find the length of the light purple vector by calculating the "dot product" of the sprite's position vector and the camera direction vector:
    camToSprA = (camToSprX * camDirX ) + (camToSprY * camDirY)

    Note that if this value is negative, it means the sprite is behind the camera, and will therefore not be visible.

    And we can find the length of the light green vector by calculating the dot product of the sprite's position vector and the vector perpendicular to the camera direction:
    camToSprB = (camToSprX * perpCamDirX ) + (camToSprY * perpCamDirY)

    To get the gradient of the line from the camera to the sprite (white), we can divide the second of those values (green) by the first (purple).
    gradSpr = camToSprB / camToSprA

    Next, we need to find the gradient of a line from the camera to the right edge of the field of vision (red). We could do the same as before, but there's an easier way. We know that the length of the orange vector is simply our cameraDistance variable. We also know that the total length of the purple vector is equal to the width of the viewing window, so if we halve that we get the length of vector to the right of the camera direction. Divide one by the other, and we have the gradient of the red line:
    gradView = (viewWidth / 2) / cameraDistance



    If we divide gradSpr by gradView, we get the position of the horizontal position of the sprite relative to the centre of the viewing window. A value of 0 means the sprite is in the centre of the view. A value of +1 means the sprite is at the right edge of the view. A value of -1 means the sprite is at the left edge of the view. A value outside the range -1 to +1 means the sprite is outside the field of view.

    If we add 1 and then divide the result by 2, we convert that to a value in the range 0 to 1, and if we multiply this value by the width of the viewing window, we get the horizontal position of the sprite on screen, in pixels (light mauve).

    It's basically the same for the vertical position, although things do start to get complicated if we add another degree of freedom for the camera (roll)... And then there's the small matter of scaling the sprite with distance...

  9. #19
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCHTML5 Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)

    Join Date
    Dec 2010
    Posts
    200
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Damn. This is very impressive.

Page 2 of 2 FirstFirst 1 2

Similar Threads

  1. Detect device model with "Model" expression
    By willy in forum iOS Export Module 2.5
    Replies: 4
    Last Post: 22nd February 2018, 01:43 PM
  2. 3D Voxel City
    By SolarB in forum File Archive
    Replies: 4
    Last Post: 4th December 2013, 06:19 AM
  3. Voxel extension? Mode 7 ex?
    By Sebaceous in forum Extension Development
    Replies: 3
    Last Post: 9th January 2010, 07:59 PM
  4. Voxel Style graphics
    By Atherton in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 4th May 2009, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •