Depth perception

I’m trying to figure out something that’s hard to explain so I’m including some screenshots to indicate what I mean.

I have a voxel game that I’m stress testing by setting the chunk render distance to 32. Each chunk is 16X256X16. When I look around it seem smooshed and the objects in the distance don’t look so far away. Below I include a screenshot of my game at 32 chunk render distance and a screenshot of minecraft at 12 chunk render distance. In minecraft it seems like a long way away when you look in the distance but in mine it looks really close and almost distorted in the distance.

I hope I’m describing this in an understandable way and if not hopefully you can get a sense of what I mean from the images below. It’s probably something common in game dev but I’m just not a seasoned game developer.

My guess is that it’s something with the viewport, or perhaps a scaling within the shader that I need to change but I hope someone can comment and give advice as to what I need to do to look more like minecraft.

By the way my intent is to release this to the JME community soon as a starting point for people wanting to build a voxel game. I don’t feel as though it’s ready yet but the source is at GitHub - jcraft-team/jcraft2: Rewrite of JCraft.

Thanks ahead of time for the help.

It’s a bit hard to tell from these two pictures, because the context of the views are so different. Maybe take a shot in your game from a similar vantage point as the Minecraft shot?

It’s possible that there is a difference in FOV (field of view) between the cameras.

It’s more immediately obvious that Minecraft is using a trick borrowed from the analog art world. Look up “atmospheric perspective.” It refers to the way distant objects look hazier and desaturated compared to nearby objects. Minecraft appears to be using two layers of fog, applied at specific depths, but you could get more involved if you wish.

Yes, field of view is probably what you are looking for. Minecraft’s is pretty wide.

I suggest to do as I once did… create a nice big 3-4 block deep square pit in minecraft… stand insde one corner with your back to the corner… look at the other corner. See how much of each wall you can see in your view.

…create a similar scene in your game and set the FOV until they look similar.

It’s a common trick to add visual distance as to fit more stuff in your field of view, the things in the distance have to be much smaller.

Edit: and after that if you want a super-simple fog, you can potentially look at what I did in this shader:

FogUnshaded.j3md is based directly on Unshaded.j3md so it should be easy to diff to see what few lines I added. Fog is then configured by setting FogColor and FogDepth. It’s a linear fog (not exponential) but may work ok for you until you want to learn more about the functions involved. (The assumption is that you’re using your own shader.)

Thanks for the suggestions guys. I’ve been playing around with the frustum settings and that’s exactly what I was describing. I just need to toy with it to get the desired effect. Just changing the field of view with this gets me closer but I think I’ll have to do some more tinkering with the frustum(that sounds dirty for some reason) :slight_smile:

This is the code I was using. If there’s something else I should do let me know.

cam.setFrustumPerspective(70, cam.getWidth()/cam.getHeight(), 1, 1000);

I might try directly setting the frustumLeft, frustumRight…etc components individually. The field of view angle caps off and minecraft is still wider. Maybe taking direct control over those separate variables would work.

@pspeed, Thanks for the fog shader! I actually understood it and even modified mine to get what I wanted. I used the linear fog equation I found here and ended up with:

        float fogFactor = (m_FogEnd - cameraDistance)/(m_FogEnd - m_FogStart);
        fogFactor = clamp(fogFactor, 0.0, 1.0);
        color = mix(m_FogColor, color, fogFactor);

The screenshots are below.

One thing I couldn’t figure out was how to incorporate it as a separate .vert and .frag in my material def. I guess it would be another Technique block but when I added it, nothing happened. I ended up having to add the code to my blocks.vert and blocks.frag files which will eventually get out of hand if I don’t figure out how to properly do that. Not a big deal for now.

1 Like

Without shader nodes, that’s what you have to do. There is only one .vert and .frag sent to the card for a particular rendering pass. No way around it.

Shader nodes is a way to have those assembled from smaller parts that are hooked together.

Edit: and 70 is what I ended up with for my camera’s FOV. Be careful setting the frustum planes directly else you might mess up the aspect ratio.

There’s still quite a difference so that’s why I was thinking of messing with the planes directly.

That doesn’t even look like 70… seems like maybe your settings aren’t being used.

Turn the camera so that you have at least one wall in place… then we might be able to guesstimate the FOV.

You’re right. I know I saw a difference at one time because I changed it to something absurdly low and saw a change.

I’m an idiot. I just did a text search for setFrustumPerspective in my workspace and found that when I spawn the player I set it to 45. I was playing with this before and that code got left in there. CRAP!

I got it. I had to move my near plane back a bit because of some clipping. It looks right now.

Tadah!

I’m pretty sure you have remote access to my development machine. Get out of my machine @pspeed!