Garry's Mod
184 คะแนน
Maxofs2d's Dynamic Shadows Tutorial
โดย Purple Toupee
This is a written form of Maxofs2d's Dynamic Shadows Tutorial. That video guide was made before Gmod13 was released, so some parts and visuals may not be relevant anymore.

This will cover everything in the video, with some additional lessons provided by me.
3
   
รางวัล
ชื่นชอบ
ชื่นชอบแล้ว
เลิกชื่นชอบ
autoexec.cfg
If you are running Garry's Mod on older hardware, there is a chance that your game will crash if you attempt to change any of the values while running the game (specifically the console command r_flashlightdepthres). To get around this, add the commands to your
autoexec.cfg file, which is found in Steam>steamapps>common>GarrysMod>garrysmod>cfg>. Open it with notepad or similar program and add the commands and values you want. This also saves time by not needing to type in the commands every time you launch the game.

This is what my autoexec.cfg file looks like. Don't worry, all the commands and values will be explained in this guide. Don't add these commands until after finishing this guide.

Shadow Map Resolution: r_flashlightdepthres
r_flashlightdepthres determines the resolution of projected textures, aka the shadows created from casting a lamp onto an object.

The default value is 512, and the increasing values are 1024, 2048, 4096, and 8192. The higher the value, the higher quality shadows will be. Smaller objects will also cast their own shadows as the value increases.

Here are examples of each value. Take note of the shadow being casted by the subject, the grenades on his chest, and the antennae on the back of his head that is visible in his shadow.

Value set at 512


Value set at 1024


Value set at 2048


Value set at 4096


Value set at 8192


While the difference between 4096 and 8192 don't appear to be very different, it is much more noticable in game. This value should be set as high as your hardware can handle it.
Shadow Map Filtering: r_projectedtexture_filter
The filter value is one you may be changing a lot in order to get the results you aim for.

As you go higher, the shadows become more blurry. This is good if you're going for softer lighting. Setting this too high may cause fuzzy shadows and shadows to disappear from certain areas.

As you go lower the shadows become more sharp. This is good if you're going for sharper lighting. Setting this too low may result in jagged shadows and shadow artifacts appearing.

Most people stick with the value of 0.2, as it's arguably the best balance of soft and sharp for what the Source engine can render, with some light methods and post editing added (more on that later).

Below are examples.

Value set to 1


Value set to 0.8


Value set to 0.2


Value set to 0


Value set to 10


Value set to 0.1
Shadow Map Accuracy: mat_slopescale_depthbias and mat_depthbias_shadowmap
TL;DR keep mat_slopescaledepthbias_shadowmap at 2, and mat_depthbias_shadowmap 0.000005

These two commands determine how biased the Source engine will be when tracing shadow maps.

If left unchecked, small parts of objects may be ignored or shaded incorrectly.

This is what the subject looks like when mat_depthbias_shadowmap is set to 0.001. Take notice of the subject's collar and underneath her hat brim.


This is what the subject looks like when mat_depthbias_shadowmap is set to 0.000005


With mat_depthbias_shadowmap set to 0.000005, this is what the subject looks like when mat_slopescaledepthbias_shadowmap is set to 10.


When mat_slopescaledepthbias_shadowmap is set to 2.


The difference of mat_slopescaledepthbias_shadowmap values are much more noticeable in-game.

If you go too low (both commands at 0), shadow artifacts will appear.


These commands may require experimentation on your part to see what looks best for your scene, but I personally keep mat_slopescaledepthbias_shadowmap at 2, and mat_depthbias_shadowmap 0.000005. These commands rarely need to be adjusted.
The Importance of nearz: clamping where the shadows start being traced will drastically increase accuracy
As far as I know, this isn't an issue found within Gmod13 (the version we all play right now). Simply put, the further away a lamp source was, the less accurate shadows would be rendered. Max's tutorial was made before Gmod13 released. The easy solution was to 1) get the lamp as close as possible to the subject or 2) command the lamp to trace shadows much farther away from its origin.

This part of the guide is here to inform the people that have watched the video that this is no longer an issue in Gmod13.
Overriding Local Diffuse Lighting: How to set your lamp as the sole source of direct lighting
Sometimes when casting a lamp onto a model on a bright map, parts of the subject may appear overly bright. This is because the map light and the light from the lamp are being stacked on top of each other, resulting in double the brightness.

Take notice of how bright the subject's head and fingers are.


Here is my setup and lamp settings.



There are two methods to get around this.

1) Using the Prop Shadow Remover Tool to disable shadows on the model.

This will force the model to enter a "mat_fullbright 1" mode, and all shadows are disabled for that model. Map lighting will no longer have an effect on the model, and will only recognize the light from the lamp.



This tool will NOT work on animated props/ragdolls.

2) Using the ent_fire command.

In this method, the subject will copy the lighting condition of another separate prop.

Point your crosshair at your subject, and assign it a name by typing ent_setname anything. You can use any name you want.


Spawn any prop, and assign it a name (ie sample)


Move the prop to a dark part of the map.


Return to your subject. Point your crosshair at it, and type ent_fire anything setlightingorigin sample


This allows you to have full control of how your subject is lit. The downside of using this command is that some spots may appear darker than it should be for the setting.



Do note that if you move the prop, the subject sharing the prop's lighting condition will update accordingly. If you move the prop from a dark spot to a bright spot, the subject sharing that prop's lightning condition will become brighter.

ent_fire [your subject name] setlightingorigin [your prop name]
Post-editing and Lighting Methods
Although Garry's Mod is a powerful tool when it comes to lighting, it does have its limitations that can't be solved in game.

Post-editing
Here is a screenshot I took with the settings I have shown in the autoexec.cfg section of this guide.



Looking closer, you can see shadow transitions that aren't entirely smooth, as well as shadow artifacts and missing shadows.


However with the magic of post-editing, these issues can be solved.


The image editor I use is GNU Image Manipulator,[www.gimp.org] or simply known as GIMP. For those new to it, think of it as a tool that has its quirks, but is just as powerful as Photoshop.


The two tools I use to edit shadows is the Smudge and Paintbrush tool.

Zoom in onto a trouble spot in your screenshot.


Use the Smudge tool and smudge the shadow lines away in tiny strokes. Think of it as if you're rubbing your computer screen to clean off a fingerprint.


Here's the before and after of this trouble spot.



For spots where shadows should be but aren't, you need to use the Paintbrush tool.


Use the Colorpicker tool to get the exact colors of the surrounding shadows, and apply the colors to the spots you want filled.


Use the Smudge tool to smooth out the colors you've just added.


Continue editing rough spots until you reached your desired outcome.


While you're in your editing program, you might as well add some subtle filters to help add to your image.


This is a time-consuming and tedious process, but it will always be worth doing in order to create a much better image.

Lighting Methods

Lamps don't simulate light realistically. The light casted from lamps don't bounce back and reflect light off the ground. This is trouble some when doing lighting in darkrooms, as shown in this image with standard three-point lighting.



The shadows should not be that dark, considering the surrounding lighting and setting.

The easiest work around is to spawn a lamp that has small FOV and distance, and is very dim. The sole purpose of this lamp is to simulate light bouncing off the ground and hitting the subject. Point this lamp at the shadows you want to lighten.



Just like that, the shadows are now lighter and reflect the surrounding area much more accurately.

6 ความเห็น
DaniVader97 25 ส.ค. 2023 @ 6: 10pm 
One thing that I've noticed QUITE late is that flashlight shadows in Garry's Mod x64 branch look more accurate and grainy just like this guide's screenshoots unlike the normal branch. So, if you want to get results LIKE the ones here just switch from vanilla x32 to the x64 branch
King Halfi Bedalfi 23 ก.ค. 2022 @ 3: 33pm 
Thank you so much for making this guide. I took a several year hiatus from making Garry's Mod screenshots after 3k hours of playtime and needed to make sure my launch options still checked out with all the Garry's Mod updates that've happened between then and now. This was very short and had all the information I needed. :47_thumb_up:
ꁝꄲꃳꄲꉔꀘꏂ꓄ 10 มิ.ย. 2022 @ 6: 51am 
Really, I thank you for helping all of the people who you helped make the best posters out of this guide!
B-TO480 24 มี.ค. 2021 @ 7: 23pm 
Very uselful!! Thanks for sharing some interesting knowledge!:cleanfloppy::cleankey:
Uber S S R 7 ก.ค. 2020 @ 8: 01am 
Thanks dude! i have watched the video about it but there are some things that i did not understand.

You makin this really helps me out