Тёмный

The BEST way to fix gun clipping in Godot 4.3 (Use a Shader) 

Chaff Games
Подписаться 8 тыс.
Просмотров 8 тыс.
50% 1

In Godot 4 There are several ways to address Gun Clipping in your view model.
In a Fps shooter there can be some problems with you gun mesh clipping through the game world. In this video we're going to look at the BEST ways to solve the gun clipping issue in the Godot Game Engine. And some of the worst ways and why you shouldn't use them
We're going to use a shader to stop Gun Clipping. This is quick efficient and will prevent your Gun From Clipping through objects.
Project: github.com/cha...
Support the Channel: / chaffgames
Join The Discord: / discord
My Latest Course: www.udemy.com/...
Get the FPS Template Here: chaffgames.com...
Need more Juice? Get the FPS Pro Here: chafmere.itch....
---------------------------------------------------------------------------------------------
My Set Up:
VO Mic: amzn.to/3QfnL6d
Audio Interface: amzn.to/46MFidg
CloudLifter: amzn.to/49dMUqE
Camera Mic: amzn.to/4980cFh
Case: amzn.to/46JiTxi
CPU: amzn.to/471Jeah
GPU: amzn.to/3si8r0G
Keyboard: amzn.to/3tPL6nC
Mouse: amzn.to/46KhM0h
As an Amazon Associate I earn from qualifying purchases.
----------------------------------------------------------------------------------------------
Please like and Subscribe! It's truly appreciated
#GameDevelopment #GameJam #Godot
Links to my Socials
Instagram: / chaff.dev
Twitter: / chaffdev
Itch.io: chafmere.itch.io/
Website: chaffgames.com

Опубликовано:

 

5 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 73   
@Chaff_Games
@Chaff_Games Месяц назад
For All those coming in Godot 4.3 use the below Vertex Shader Function void vertex() { UV = UV * uv1_scale.xy + uv1_offset.xy; /* begin shader magic*/ float onetanfov = 1.0f / tan(0.5f * (viewmodel_fov * PI / 180.0f)); float aspect = VIEWPORT_SIZE.x / VIEWPORT_SIZE.y; // modify projection matrix PROJECTION_MATRIX[1][1] = -onetanfov; PROJECTION_MATRIX[0][0] = onetanfov / aspect; // draws the viewmodel over everything (disable if you want dof near on viewmodel) POSITION = PROJECTION_MATRIX * MODELVIEW_MATRIX * vec4(VERTEX.xyz, 1.0); POSITION.z = mix(POSITION.z, 0, -0.999); /* end shader magic */ }
@inculetbogdan
@inculetbogdan Месяц назад
This does absolutely nothing
@Chaff_Games
@Chaff_Games Месяц назад
@inculetbogdan unhelpful comments get unhelpful responses.
@inculetbogdan
@inculetbogdan Месяц назад
@@Chaff_Games I meant the code you provided its not fixing the issue. The viewmodel still clips
@Chaff_Games
@Chaff_Games Месяц назад
Did you try downloading the example. It shows a working version, so you can check that for set up. Also what version of godot, 4.3 recently changed, I’ve updated the script to work with 4.3, so if you’re on 4.2 the script won’t work.
@inculetbogdan
@inculetbogdan Месяц назад
@@Chaff_Games yes, I tried it on godot 4.3 with the example provided by you
@p3ng00
@p3ng00 10 месяцев назад
after so much fiddling and trying to make this work I found an easier method that works for me. firstly, my weapon is rendered on layer 2. lets say I have a 3d rectangular wall with a meshinstance3d and a collisionshape3d both as a box mesh. on the wall I duplicated its meshinstance3d and for the new meshinstance3d I set the layer to 2 (same as weapon) and the Geometry.CastShadow to "Shadows Only". this may not be the best fix if you already have a lot of meshes but my environment is simple enough and I spent too much time fiddling with this script that I have to accept this as a solution for now
@getout0_______0
@getout0_______0 10 месяцев назад
Heres a tiny gift for the hard work you put into making these tutorials. I'm new to godot, and I've learnt alot just from your tutorials alone. Thanks for the tutorials, and I can't wait to see the projects you work on in the future.
@Chaff_Games
@Chaff_Games 10 месяцев назад
Thank you so much. ☺️
@Jun-o3l6t
@Jun-o3l6t 9 месяцев назад
Could you make a video discussing shotguns and spread please? Your tutorials are really well thought out and concise
@Chaff_Games
@Chaff_Games 9 месяцев назад
Thanks and yes, it’s on the list of things to do.
@saltyku7454
@saltyku7454 Месяц назад
In 4.3, i added " vec4 clip_pos = PROJECTION_MATRIX * vec4(VERTEX, 10.0); DEPTH = clip_pos.z;" to the fragment function and it worked. EDIT: Forgot to add, you need to comment or delete "POSITION.z = mix(POSITION.z, 0,0.999)" in vertex function
@Chaff_Games
@Chaff_Games Месяц назад
There's a number of different ways to do a shader like this. I tend to prefer to use " DEPTH = FRAGCOORD.z * 2.99; " in my fragment shader these days.
@daviddraper6468
@daviddraper6468 Месяц назад
Definitely a little late to this, but there's one aspect that causes some issues for me. The shader doesn't allow changes to the sampling, so I'm stuck with the blurry linear filtering where I'd want the sharp pixelated look of closest. I'm not sure if there's any sort of way around this. I found a solution to this for anyone experiencing the same thing: (I am using the shader version released right after Godot 4.3 came out) On line 7, "uniform sampler2d texture_albedo : source_color", add whatever filtering option you would prefer. I wanted nearest, so it looks like this now: "uniform sampler2d texture_albedo : source_color, filter_nearest" The values should autofill for whatever filtering option you want to use
@LionTheUncommonSamurai
@LionTheUncommonSamurai 10 месяцев назад
You don't need to set the fov on every material shader parameter. Godot 4+ has global shader uniforms if your project settings add your variable name, type and value to shader globals and in your shader use `global uniform float viewmodel_fov;`
@Chaff_Games
@Chaff_Games 10 месяцев назад
Oh that's awesome. Thanks for pointing that out.
@Chaff_Games
@Chaff_Games 10 месяцев назад
I've updated the repo to include this change.
@DayMoniakkEdits
@DayMoniakkEdits 6 часов назад
If you'd like to have a checkbox to turn off this effect without swapping the material here's the shader code for it (it is Chat GPT, I have no idea how shaders works) After that you can disable the effect from code by setting "shader_parameter/disable_effect" to true shader_type spatial; uniform float viewmodel_fov = 75.0f; uniform bool disable_effect = false; uniform vec4 albedo : source_color = vec4(1.0f); uniform sampler2D texture_albedo : source_color; uniform float specular = 0.0f; uniform float metallic = 0.0f; uniform float roughness : hint_range(0,1) = 1.0f; uniform sampler2D texture_metallic : hint_default_white; uniform vec4 metallic_texture_channel = vec4(1.0, 0.0, 0.0, 0.0); uniform sampler2D texture_roughness : hint_default_white; uniform vec4 roughness_texture_channel = vec4(1.0, 0.0, 0.0, 0.0); uniform sampler2D texture_normal : hint_normal; uniform float normal_scale : hint_range(-16,16) = 0.5f; uniform vec3 uv1_scale = vec3(1.0f); uniform vec3 uv1_offset = vec3(0.0f); void vertex() { UV = UV * uv1_scale.xy + uv1_offset.xy; // Default projection matrix POSITION = PROJECTION_MATRIX * MODELVIEW_MATRIX * vec4(VERTEX.xyz, 1.0); if (!disable_effect) { // If the effect is active, apply the custom projection to render “on top”. float onetanfov = 1.0f / tan(0.5f * (viewmodel_fov * PI / 180.0f)); float aspect = VIEWPORT_SIZE.x / VIEWPORT_SIZE.y; // Modify the projection matrix PROJECTION_MATRIX[1][1] = -onetanfov; PROJECTION_MATRIX[0][0] = onetanfov / aspect; // Force z position to ensure object is always on top POSITION.z = mix(POSITION.z, 0, -0.999); } } void fragment() { vec2 base_uv = UV; vec4 albedo_tex = texture(texture_albedo, base_uv); albedo_tex *= COLOR; ALBEDO = albedo.rgb * albedo_tex.rgb; float metallic_tex = dot(texture(texture_metallic, base_uv), metallic_texture_channel); METALLIC = metallic_tex * metallic; float roughness_tex = dot(texture(texture_roughness, base_uv), roughness_texture_channel); ROUGHNESS = roughness_tex * roughness; SPECULAR = specular; NORMAL_MAP = texture(texture_normal, base_uv).rgb; NORMAL_MAP_DEPTH = normal_scale; // Set depth mode according to disable_effect if (disable_effect) { // Respect normal depth (z-buffer) DEPTH = FRAGCOORD.z; } else { // Draw the “above all” object DEPTH = FRAGCOORD.z * 2.99; } }
@sinewavey
@sinewavey 10 месяцев назад
hahaha dammit I was about to go to sleep, too
@Numa369
@Numa369 10 месяцев назад
You should set up render priority when you use no depth test to avoid ordering problems.
@Chaff_Games
@Chaff_Games 10 месяцев назад
That helps a little. But you still only get to choose one render priority. eg. I can still see the mag within my M4 when activated and they share the same material. So now way to change the render order on those. Also on a full rig, it's fine when hold the gun, the gun is drawn on top. But on reload the left hand passes over weapon and will still be drawn behind the gun. So you would need to switch render priorities part way through. And the right hand holding the trigger would look wrong.
@alexanderstreng4265
@alexanderstreng4265 10 месяцев назад
Ah so you finally took a look at the link that I sent :D
@dashfoxgames
@dashfoxgames 7 месяцев назад
This is fantastic, thank you for the info! How would you go about adding text (onto the model - for example bulelt count?). I imagine it's pretty tricky - right now I'm just manually showing text on it with No Depth Test but it's pretty hacky.
@Chaff_Games
@Chaff_Games 7 месяцев назад
You mean like an ammo counter on the gun model like in halo or titanfall? I have a video on that from the 3.5 era. Principle is pretty much the same. Shader code will be a tiny bit different.
@cs3705
@cs3705 9 месяцев назад
Thank you for sharing this technique! I applied this shader to my models, and it solves most of the issues. However, there is one issue with this shader that I have not been able to overcome. The weapon does not cast shadows in the proper place, so there is no self-shadowing. If you look down at the right angle, it's apparent that the shadows are being cast from a location near the directional light sun, as a huge shadow will cover the play area. Have you experienced this issue, and if so, how did you resolve it?
@Chaff_Games
@Chaff_Games 9 месяцев назад
Actually, Yes. I have noticed the shadowing issue. I had not investigated yet. So thanks for linking it to the shader. I guess I gotta make another video on moving the view model out of the wall's way lol.
@cs3705
@cs3705 9 месяцев назад
@@Chaff_Games Hey, no problem. I figure there is something that can be adjusted in the shader code to anchor the shadows. From what I've figured out, the vertices are being moved by modifying POSITION to draw over everything, but having the vertex positions changed leads to the shadows being cast from the wrong place. I believe a different method of drawing over everything needs to be used in order for this bug to be fixed. If I figure something out I'll share it, just wanted to see if you had a solution before I go experiment.
@rozaco_games
@rozaco_games 8 месяцев назад
Hey chaff would you help me. If we use navigation enemy automatically finds us but I don't want it.i want that when my player enters enemy's area enemy should follow and hit the player
@nic8967
@nic8967 10 месяцев назад
Thank you saviour
@lucameuleman4123
@lucameuleman4123 8 месяцев назад
wow nice
@dr.oswald5400
@dr.oswald5400 3 месяца назад
Could I put the shader on a node that holds all the models instead of each individual weapon model
@Chaff_Games
@Chaff_Games 3 месяца назад
Probably not. But someone else pointed out that you can use global shaders and then the code is a little simpler.
@kaduyeah
@kaduyeah 9 месяцев назад
It's just removing the old material, help?
@Chaff_Games
@Chaff_Games 9 месяцев назад
It’s meant to. If you right click and select convert to shader before putting the new shader on then it should work. Unless you’re doing something fancy with your shaders. This would only work with your basic albedo, normal and roughness kind of shader.
@kaduyeah
@kaduyeah 9 месяцев назад
@@Chaff_Games it's exactly the case, the only thing in the material was an albedo color change to brown, i converted it amd then i put the new shader on top, it removes the brown change i did. I am in 4.2.1 btw.
@Chaff_Games
@Chaff_Games 9 месяцев назад
@kaduyeah ah I kinda know what you’re talking about you might need to find out what that parameter is called and add it to the shader provided. Will check later
@kaduyeah
@kaduyeah 9 месяцев назад
@@Chaff_Games ok, thanks though. The tutorial is great
@Smileydiecast2024
@Smileydiecast2024 2 месяца назад
how to use on animatedspirite3d??? i get a grey square i fuguried out ticking no depth test shows the sprite but the transparent background if filled with a grey square
@fergusdrummyt2342
@fergusdrummyt2342 4 месяца назад
if i make my game multiplayer will the other players be able to see the models through walls
@Chaff_Games
@Chaff_Games 4 месяца назад
No because the other players would be represented by something else, not their view model
@AndreaTerenziani
@AndreaTerenziani 4 месяца назад
You could also just increase the shadow atlas size of the viewport tbh
@Chaff_Games
@Chaff_Games 4 месяца назад
Have you tried. How big did you have to make it to make it work?
@Chaff_Games
@Chaff_Games 4 месяца назад
Yeah Just tried at 10x the default. No Change. Unless there some other view port setting I'm missing?
@shirotonbo6315
@shirotonbo6315 5 месяцев назад
I maybe really stupid but why not just set up collision on the gun model with the wall? I am sorry for being dumb pleade forgive me 😂
@Chaff_Games
@Chaff_Games 5 месяцев назад
You could totally do that. Although you may end up getting stuck on things…
@GraveReaperCushions
@GraveReaperCushions 10 месяцев назад
There's another method which I'd love to see a tutorial on, which I've been calling the "Starbreeze method", on account of how I really started noticing it while playing Starbreeze-developed FPSs (although now I think about it, I think even Goldeneye did this too, but hey...). It's the one where, as the player (and crucially the weapon they're carrying) gets closer to a surface, the character gradually draws the weapon closer to them, so clipping is avoided by keeping the weapon model from passing through surfaces in the first place 🤔
@Chaff_Games
@Chaff_Games 10 месяцев назад
Oh yeah, I thought of that but then I figured that you’d probably want to have some other method like this shader to prevent absolutely nothing from getting in the way. I’ve done it very briefly with an area3d and tweens. I’ll look into maybe there’s a third video in this series 😀. Thanks.
@xf1521
@xf1521 10 месяцев назад
the project in the link is broken when i start the game the weapon is placing middle of the screen and camera does not shows anything then crashes
@Chaff_Games
@Chaff_Games 10 месяцев назад
Hey, Really sorry about that. I have downloaded and experienced the same error "Script Hides a global resource". I actually don't know why it would do that. So i'm not sure how to prevent it on download. For me this was "class_name secondary_fire_resource" and "class_name Weapon_Resource" that produced the error. All I did was delete the "e" from resource "class_name Weapon_Resource" and then put it back. Don't rename them completely since the controller is dependent on them. But changing them and then changing them back seems to fix it.
@andrewb4611
@andrewb4611 10 месяцев назад
Hi, the weapon model jitters when its further from position(0,0,0). Is there any way to fix this ?
@Chaff_Games
@Chaff_Games 8 месяцев назад
I don't have the same issue, sorry.
@galemannenman
@galemannenman 3 месяца назад
I can't add a shader to a read only mesh because it's blender imported, what did you do?
@Chaff_Games
@Chaff_Games 3 месяца назад
Right click make unique
@dee_sgusting
@dee_sgusting 10 месяцев назад
*resolved* dumb question but do you have the godot 4 compatible version somewhere? cant find a link to it in the description
@Chaff_Games
@Chaff_Games 10 месяцев назад
Oh damn, I forgot to link it. Let me fix that now. Good catch thank you.
@Chaff_Games
@Chaff_Games 10 месяцев назад
Should be there now.
@dee_sgusting
@dee_sgusting 10 месяцев назад
@@Chaff_Games thanks ^^
@Alexey_Pe
@Alexey_Pe 3 месяца назад
Causes errors when intersecting with decals
@Chaff_Games
@Chaff_Games 3 месяца назад
Interesting
@potatofaceguy9808
@potatofaceguy9808 Месяц назад
I downloaded a model with multible meshes how can I combine them in a meshinstance3D ?
@Chaff_Games
@Chaff_Games Месяц назад
You just apply the same shader to all the meshes. Well. At least that’s what I do.
@potatofaceguy9808
@potatofaceguy9808 Месяц назад
​@@Chaff_GamesI just had to look at the model scene and found my solution, but thanks anyway for the tutorial, you are a real one (:
@Chaff_Games
@Chaff_Games 10 месяцев назад
Hey all, My Asset, Godot 4 FPS Template PRO is on special as a part of the Itch.io Creator day sale! Get 50% off until Tuesday at 6pm AEST. itch.io/s/109166/black-friday-creator-day-2023
Далее
Using Composition to FINALLY Make A Shotgun in Godot 4
10:23
1 Year of Developing My Game in Godot
19:19
Просмотров 285 тыс.
НЮША УСПОКОИЛА КОТЯТ#cat
00:43
Просмотров 642 тыс.
The Woke Video Games Detector is Bizarre...
12:50
Просмотров 136 тыс.
The Worst Part of Gamedev
9:32
Просмотров 13 тыс.
An Unusual Way to Fix This Common Problem in FPS Games
2:09
Why Slopes are Shockingly Difficult for Indie Game Devs
17:20
What 3 YEARS of Linux does to you
42:08
Просмотров 10 тыс.
Every Level of Civlilization Explained
15:19
Просмотров 273 тыс.
Is This The End Of Godot!?!?
6:23
Просмотров 6 тыс.
Optimizing my Game so it Runs on a Potato
19:02
Просмотров 606 тыс.