└── README.md /README.md: -------------------------------------------------------------------------------- 1 | # obscure-information 2 | Repository of dumb things Garry's Mod 3 | 4 | ---- 5 | 6 | ## General 7 | 8 | #### [Windows] [Client?] Use junction instead of symlink for addon folders 9 | Seems to work better (ie. models in `addons/mylink/models` load when using junction but not when using a symlink). 10 | 11 | 12 | ## API 13 | 14 | #### `GM` is available on first load, `GAMEMODE` on subsequent loads 15 | Can be worked around with something like `local GM = GM or GAMEMODE` 16 | 17 | > Meepen Ƹ̵̡Ӝ̵̨̄Ʒ: [you should] not do that 18 | 19 | #### Drawing a custom mesh with lighting requires rendering a model in the draw hook 20 | Source: https://facepunch.com/showthread.php?t=1456688&p=47356770&viewfull=1#post47356770 21 | 22 | #### If entity does not appear when rendering an entity manually, call `SetupBones` 23 | For instance: 24 | ```lua 25 | e:SetupBones() 26 | e:SetRenderOrigin(somepos) 27 | e:DrawModel() 28 | ``` 29 | 30 | #### Pre/Post opaque/translucent hooks are each called twice per frame 31 | Namely once for 3d skybox entities, once after (see https://wiki.garrysmod.com/page/Render_Order). 32 | If you do something expensive in the hooks that only needs to be done once per frame, it might be worth it to return early in one of the passes. 33 | 34 | #### Rendering custom stuff to a env_projectedtexture 35 | If you set the texture of env_projectedtexture to some string (eg. `myprojtex`), you can render to a RT clientside with same name to change what's displayed on the projectedtexture. 36 | 37 | #### HDR bloom/overexposure in RTs workaround 38 | Makes the rt look more like what you're actually drawing to it. 39 | ```lua 40 | local nilToneMappingScale = Vector(1, 1, 1) 41 | ``` 42 | ```lua 43 | local oldTMSL = render.GetToneMappingScaleLinear() 44 | render.SetToneMappingScaleLinear(nilToneMappingScale) 45 | -- Draw to RT here 46 | render.SetToneMappingScaleLinear(oldTMSL) 47 | ``` 48 | 49 | #### SetSubMaterial silently fails if material is not loaded 50 | Source: https://github.com/Facepunch/garrysmod-issues/issues/1511, https://facepunch.com/showthread.php?t=1374457&p=46073827&viewfull=1#post46073827 51 | 52 | You can load the material by using `surface.SetMaterial(mat)` anywhere on client. 53 | 54 | #### `Panel:SetDisabled` is placebo Garry code 55 | If you actually want to disable Panel functionality, use `Panel:SetEnabled(false)`. 56 | 57 | #### Creating a brush entity 58 | Source: https://facepunch.com/showthread.php?t=1529285&p=50927618&viewfull=1#post50927618 59 | Credits: wauterboi & rubat 60 | ```lua 61 | AddCSLuaFile(); 62 | 63 | ENT.Base = "base_anim"; 64 | ENT.Type = "anim"; 65 | 66 | ENT.RenderGroup = RENDERGROUP_TRANSLUCENT; 67 | 68 | function ENT:Initialize() 69 | if (SERVER) then 70 | self:SetMoveType(MOVETYPE_VPHYSICS); 71 | self:SetSolid(SOLID_VPHYSICS); 72 | self:SetModel(self.Model); 73 | else 74 | self:SetRenderBounds(self:OBBMins(), self:OBBMaxs()); 75 | end 76 | end 77 | 78 | function ENT:Draw() 79 | self:DrawModel(); 80 | end 81 | 82 | function ENT:KeyValue(key, value) 83 | if (key == "model") then self.Model = value end 84 | end 85 | ``` 86 | 87 | #### RenderTarget name truncation 88 | `GetRenderTarget` seems to truncate the name to x characters. If you experience render targets pointing to same buffer even with different names, try to shorten the used names to see if it's related to truncation. 89 | 90 | #### Transparent rendertargets 91 | Source: https://facepunch.com/showthread.php?t=1497293&p=49312072&viewfull=1#post49312072 92 | ```lua 93 | local nm = "myrt" 94 | 95 | local rt = GetRenderTargetEx( nm, 512, 512, RT_SIZE_NO_CHANGE, MATERIAL_RT_DEPTH_NONE, 8, 4, IMAGE_FORMAT_RGBA8888 ) 96 | render.PushRenderTarget(rt) 97 | render.OverrideAlphaWriteEnable( true, true ) 98 | render.ClearDepth() 99 | render.Clear(0, 0, 0, 0) 100 | render.OverrideAlphaWriteEnable( false ) 101 | render.PopRenderTarget() 102 | 103 | -- Note: specifying alphatest, vertexcolor in material constructor seems to be important 104 | local mat = CreateMaterial(nm, "VertexLitGeneric", {["$alphatest"] = "1", ["$vertexcolor"] = "1"}) 105 | mat:SetTexture("$basetexture", rt) 106 | ``` 107 | 108 | #### NextBot animations 109 | If using activities other than `ACT_WALK` or `ACT_RUN`, remember to edit BodyUpdate (https://github.com/garrynewman/garrysmod/blob/master/garrysmod/gamemodes/base/entities/entities/base_nextbot/sv_nextbot.lua#L64) 110 | 111 | #### 3D sounds played via BASS must be mono 112 | --------------------------------------------------------------------------------