[ZSCRIPT]How to put an overlay on a camera view?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

[ZSCRIPT]How to put an overlay on a camera view?

Post by Sir Robin »

I've got a locked door but I let the player peek through the keyhole. I've got a camera on the other side and it works how I want it to. How do I put a keyhole silhouete over that camera view?

I found a post on how to do that in ACS using a HUD message, but how to do it with ZScript?
User avatar
Cherno
Posts: 1318
Joined: Tue Dec 06, 2016 11:25 am

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Cherno »

You use either a custom ZScript Statusbar or, probably more appropriate here, an EventHandler's RenderOverlay virtual.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Sir Robin »

Wow, things aren't hard to do once you know where to find them. Thanks!

An example for anyone else trying to do this:

Code: Select all

class MWR_Silhouette_Handler : EventHandler
{
	TextureId tKeyhole;
	
	override void OnRegister()
	{
		tKeyhole = texman.CheckForTexture("Keyhole");
	}
	
	override void RenderUnderlay (RenderEvent e)
	{
		if (!(e.camera is "MWR_PeekCamera")) return;
		
		Screen.DrawTexture(tKeyhole, false, 0, 0, DTA_FullScreen, 1);
	}
}
And a screenie to see what it could look like
Spoiler:
User avatar
Dan_The_Noob
Posts: 877
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Dan_The_Noob »

Sir Robin wrote: Sat Oct 07, 2023 6:19 pm
And a screenie to see what it could look like
Spoiler:
IDEA - make overlay the shape of the pixels the keyhole is made off on the door texture
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Sir Robin »

Dan_The_Noob wrote: Sun Oct 08, 2023 12:35 am IDEA - make overlay the shape of the pixels the keyhole is made off on the door texture
I'm trying out a few different things to see what looks good

The textures I'm using are pretty low res (I'm revamping a game from 1990), the door is 32x52, the lock is about 5x7 and the keyhole is 3x4. So blowing that up to fullscreen would be like minecraft level chunkiness.

See it here:
Spoiler:
So far I love it but I'm still playing with ideas. Like there is a random chance that looking tough the keyhole will just see a big eye looking back and play some jump-scare music
User avatar
Dan_The_Noob
Posts: 877
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Dan_The_Noob »

Sir Robin wrote: Sun Oct 08, 2023 7:30 pm
See it here:
Spoiler:
So far I love it but I'm still playing with ideas. Like there is a random chance that looking tough the keyhole will just see a big eye looking back and play some jump-scare music
Ya see, make the hole cross-shaped to match right?
attention to detail is a big thing for some people
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Sir Robin »

Dan_The_Noob wrote: Sun Oct 08, 2023 10:44 pm Ya see, make the hole cross-shaped to match right?
attention to detail is a big thing for some people
Yeah, I see what you're saying. But in game design there is a balance between realism and playability. My first try I made it a more realistic looking keyhole slot, a circle with a slit below it like you'd expect an old skeleton key to look. It looked cool but you can't hardley see anything through it because it's so narrow. Anything I want the player to see has got to be right in line with it. So I made the overlay hole more stretched out and exaderated looking. Yes, less realistic, but much more functional.

But whatever, the code is posted. On your levels you can make the keyhole look however you want :)

I also have other parts of the levels where you look into a crystal ball to peek at other parts of the level. I just realized I could make some cool overlays for those too.
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Sir Robin »

I just realized this will draw over the automap. If you don't want that, throw this line in the RenderOverlay:

Code: Select all

	override void RenderUnderlay (RenderEvent e)
	{
		if (automapActive) return;
		if (!(e.camera is "MWR_PeekCamera")) return;
		
		Screen.DrawTexture(tKeyhole, false, 0, 0, DTA_FullScreen, 1);
	}
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Sir Robin »

I just noticed this doesn't scale the overlay with the screen size. How to fix that?

See for example:
User avatar
Dan_The_Noob
Posts: 877
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Dan_The_Noob »

maybe just add a binding to shrink it X amount on the key for shrink/grow screen
Jarewill
 
 
Posts: 1805
Joined: Sun Jul 21, 2019 8:54 am

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Jarewill »

There is no need to mess with bindings, you can just check the screenblocks CVar of the player.
User avatar
Dan_The_Noob
Posts: 877
Joined: Tue May 07, 2019 12:24 pm
Graphics Processor: nVidia with Vulkan support

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Dan_The_Noob »

Jarewill wrote: Tue Nov 07, 2023 4:42 am There is no need to mess with bindings, you can just check the screenblocks CVar of the player.
I had no idea this can be controlled by cVars!
any idea the ratio of these? is it 10% downsize per step?
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Sir Robin »

so is the CVARs the way to go? Is there no function in screen or somewhere that is aware of the frame?
Also, where can I draw the overlay so that it is under the frame?
User avatar
Sir Robin
Posts: 537
Joined: Wed Dec 22, 2021 7:02 pm
Graphics Processor: Intel (Modern GZDoom)
Location: Medellin, Colombia

Re: [ZSCRIPT]How to put an overlay on a camera view?

Post by Sir Robin »

I just dropped a demo where you can see the keyhole in action:

See it at about 7:00 minutes in
link

Return to “Scripting”