Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

[Tutorial] Custom props and rendertargets.


LeeC22
 Share

Recommended Posts

I recently posted a video on my YT channel about a mod I made last year that rebuilt the cablecars to be addon ped friendly. The video is set to start where I show the display screen being used... I hope.

 

 

In that mod I showed a custom display screen that I am using to show various bits of information. I thought some info about how that was created might be useful to anyone wanting to create something similar.

 

The game uses this feature quite a lot, for heist boards, computer screens, arcade machines etc... and it's fairly straightforward to setup your own custom display. I am using a test prop to show the setup, which is also available as a sample file in the link at the end of this post.

 

Model, Material and Texture

 

The first thing is to define the part of the mesh you want to use as the screen, you can see that as the Red section in the image below. You assign a material to that part of the mesh and give it a name that begins with "script_rt_", you can see in the image it is called "script_rt_tv_screen". I have the Shader and Parameter set configured as Emissive, so that it lights up at night. You can set it as a regular texture type and it will behave like a regular diffuse textured object. i.e. It receives shadows etc...

 

Edit: You do of course need to have that part of the mesh UV mapped, in this instance it was just Planar mapped with the UV area matching the mesh area.

 

In your diffuse texture you choose the texture to be applied to that part of the mesh, this also needs "script_rt_" at the start of the name. The one I have used originally came from the biker laptop prop "bkr_prop_clubhouse_laptop_01a", which is called "script_rt_prop_clubhouse_laptop_01a.dds". There are two texture layouts that you can use for this texture, one is like you can see in the below image, which is the same layout as a MipMap texture, this seems to give better detail as you move further away from the display. Or you can apply a POT (Power Of Two) texture that is just a black texture. You can see this type in the prop "bkr_prop_clubhouse_blackboard_01a" where it is just a 256 x 128 texture, which is what I used in the cablecar display screen.

 

Set the texture to embedded and set its Usage Type to Script.

 

That's all you need to do in the model and that defines the area you will be drawing to. Here's the image showing the setup.

 

rendertarget-max-setup.jpg

 

Script

 

In the script I have defined the following variables:

 

private Prop RendertargetProp;
private int RenderID;
int DefaultRenderID;

private string PropName = "props_test_tv";
private string RendertargetName = "tv_screen";

 

Note that with the rendertarget name, you don't put "script_rt_" at the start of it.

 

In my initialisation I use this native to get the default Render ID:

DefaultRenderID = Function.Call<int>(Hash.GET_DEFAULT_SCRIPT_RENDERTARGET_RENDER_ID);

 

I have two functions, one to set the rendertarget, which is literally just pulled straight from the decompiled scripts, hence the iVar2 name:

void SetRenderTarget()
{
	// Will hold the Hash of the prop used as the display
	int iVar2;

	iVar2 = Game.GenerateHash(PropName);

	// Check to see if the rendertarget is registered....
	if (!Function.Call<bool>(Hash.IS_NAMED_RENDERTARGET_REGISTERED, RendertargetName))
	{
		// If not, register it.
		Function.Call(Hash.REGISTER_NAMED_RENDERTARGET, RendertargetName, false);

		// Check to see if that rendertarget is linked with the prop...
		if (!Function.Call<bool>(Hash.IS_NAMED_RENDERTARGET_LINKED, iVar2))
		{
			// If not, link it.
			Function.Call(Hash.LINK_NAMED_RENDERTARGET, iVar2);
			
			// Then get a Render ID back from that rendertarget
			RenderID = Function.Call<int>(Hash.GET_NAMED_RENDERTARGET_RENDER_ID, RendertargetName);
		}
	}
}

 

and one to release it:

void ReleaseRenderTarget()
{
	// Check to see if the rendertarget is registered....
	if (Function.Call<bool>(Hash.IS_NAMED_RENDERTARGET_REGISTERED, RendertargetName))
	{
		// if so, release it.
		Function.Call(Hash.RELEASE_NAMED_RENDERTARGET, RendertargetName);
	}
}

 

After you have created your prop, such as:

RendertargetProp = World.CreateProp(PropName, PlayerPed.GetOffsetInWorldCoords(new Vector3(0, 5f, 0)), new Vector3(0, 0, PlayerPed.Rotation.Z), false, false);

 

Call SetRenderTarget() and that will get you a Render ID back. To draw something to the screen, you simply need to switch the Render ID to the one you got back from that SetRenderTarget() call.

UIText testText = new UIText("Hello", new Point(640, 360), .4f, Color.Green, Font.ChaletLondon, true);

// Set the custom Render ID
Function.Call(Hash.SET_TEXT_RENDER_ID, RenderID);
testText.Draw();

// Set the Render ID back to default after you have finished drawing everything
Function.Call(Hash.SET_TEXT_RENDER_ID, DefaultRenderID);

 

Anything you can draw to the screen can be drawn to a custom display, apart from something that uses UI.DrawTexture I suspect, although I haven't checked for certain.

 

Here is a link to a .7z file containing the default prop shown in the image above, plus a ytyp entry for it and the full script that can be used to spawn it. The script is a.cs file, so you can read exactly what it does.

https://drive.google.com/file/d/18IYwjDJ0AyLzEy_1IKe47MLO1R-foma7/view?usp=sharing

 

Simply enter the cheat code renderme to make something happen.

 

Edit: Just something to add to this... I had an idea about trying to set two rendertargets in the same prop, it doesn't work based on my first attempt. So it looks like it is 1 active rendertarget per prop although it might be possible to set the prop to the 1st rendertarget, draw to it, release that rendertarget and then register the second one. It would involve a lot of alternating between rendertargets which might work but I am unsure how that would be reflected in memory usage and overall stability.

 

Edit: Can confirm... releasing and registering every frame causes complete crash.

Edited by LeeC22
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.