Jump to content

Proper FPS weapon CS:GO-like ?


Slastraf
 Share

Recommended Posts

How do you properly render a weapon so that it doesnt clip or go trough walls,

 

I have remembered from some other thread that you make a new world, only render the fpsweapon inside of it like this:

 

post-12189-0-75981300-1466179440.png

 

and then apply all the rendered pixels to the actual camera, in the original world, so it looks something like this:

 

post-12189-0-18847400-1466179599_thumb.jpg

 

But how do you make it properly, that the shaders and lighthnings are visible on the weapon / melee,

in Leadwerks Lua ?

Link to comment
Share on other sites

One way off the top of my head, which can be buggy, is to turn off the Depth Test in the guns material settings, I believe, but the only downside to that is your weapon cannot have child entities, only 1 entity. If it does, then the entities behind each other will appear. It would look like your camera has X-Ray vision. Since I never tested this route, I could be wrong on this one.

 

Another way is to, like Josh said, scale the gun so small and position the weapon model really close to the camera so that it will not clip through anything. However, shadows will not appear on the gun model correctly because the model is so small. This will become more apparent when you have longer weapons like a rifle or shotgun.

 

Another way, which is more realistic, is to have the weapon normal size, but perform a raycast so that if the weapon comes close to a surface, perform an animation that it will bring up the weapon so it does not go through the surface. One game that did this was Call of Juarez: Bound in Blood. I think Crysis did this as well.

Play Our Latest Game: Relic Rogue

Link to comment
Share on other sites

If you want realistic shadows on your gun without shrinking it, you should implement a raycast and lower the gun when the player is close to a wall.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

I remember a technique where you have a second camera which renders the first-person model as a new layer. I found a good article about that recently, will come back with it soon

 

Edit: I think you can do something like SetRenderTarget to render a second camera's display to a texture (which is a big as your window), which you can use as an overlay on top of your main camera using something like DrawImage.

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

Why don't you just render the first-person model with a material that has shadows but discards the fragments of the model in the normal shader? Then, you get the best of both worlds.

 

Personally, I would do what Josh suggested though. If you decide to use environmental probes, you're going to be in trouble.

Link to comment
Share on other sites

But how do you make it render only your weapon?

 

You can try ForEachVisibleEntityDo: Hide all the entities visible for the second camera, store all the hidden entities and re-enable them using Show() after rendering. It's probably not performance friendly but it's quick to make. You can also try to make a new world and try to emulate lighting it from there.

 

Although I do like nick.ace's shader solution, would probably be the most performance-friendly solution of all.

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

But hidden entities won't cast shadows, will they?

 

Why don't you just render the first-person model with a material that has shadows but discards the fragments of the model in the normal shader? Then, you get the best of both worlds.

 

Personally, I would do what Josh suggested though. If you decide to use environmental probes, you're going to be in trouble.

How do you get your shadows from the first world render on top of the render from the second world?

 

I just don't like the idea of forcing player not to shoot simply because he is near the wall. It can be that he is still able to shoot someone but his controls are taken away.

 

Actually, while I was playing Fallout 4 I noticed that my weapon didn't seem to receive true shadows, most of the time it was completely dark or completely bright and I was wondering why. Maybe they simply check if the player is inside the light cone (they anyway need no to do this for the stealth system) and make the weapon darker if not. Have you noticed anything like this in other games?

Link to comment
Share on other sites

But hidden entities won't cast shadows, will they?

 

How do you get your shadows from the first world render on top of the render from the second world?

 

You don't actually hide the entity. You just use a garbage shader that tosses out the fragments on the model, but use a legit shader for the shadows in the main world. In the first-person model world, you would just render the mesh with shadows again (or without, but you may need self-shadowing). You would have to render the model twice (one in each world) but it shouldn't be a huge deal.

Link to comment
Share on other sites

I remember an engine in which they used to set a flag ZNEAR to lower the clipping distance of an object.

This said let me tell you i am far from understanding anything script related just in case this doesnt make any sense at all...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...