-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added static, prerendered hat icons to drastically shorten the …
…open time of the shop
- Loading branch information
1 parent
4fdaf39
commit 3d91654
Showing
10 changed files
with
378 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
-- Adapted from MDave's MIT Licensed code. Now ISC | ||
Pointshop2.IconQueue = Pointshop2.IconQueue or LibK.CircularQueue() | ||
Pointshop2.IconPromises = {} | ||
|
||
local queue = Pointshop2.IconQueue | ||
local promises = Pointshop2.IconPromises | ||
|
||
local function getIconUID( itemClass ) | ||
return "ps2/" .. itemClass.UUID:lower() | ||
end | ||
|
||
local function getIconPath( itemClass ) | ||
return string.format( "spawnicons/%s_256.png", getIconUID(itemClass) ) | ||
end | ||
|
||
function Pointshop2.RequestIcon( itemClass, panel ) | ||
local iconID = getIconUID( itemClass ) | ||
local pending = promises[iconID] | ||
if pending then | ||
return pending | ||
end | ||
|
||
-- Check if the icon exists | ||
local path = getIconPath( itemClass ) | ||
|
||
print(path) | ||
if file.Exists( "materials/" .. path, "GAME" ) then | ||
return Promise.Resolve(Material( path )) | ||
end | ||
|
||
promises[iconID] = Deferred() | ||
queue:Add( itemClass ) | ||
return promises[iconID] | ||
end | ||
|
||
do | ||
Pointshop2.rIcon = Pointshop2.rIcon or vgui.Create( "ModelImage" ) | ||
Pointshop2.rModel = Pointshop2.rModel or ClientsideModel( "error" ) | ||
|
||
local rIcon = Pointshop2.rIcon | ||
local rModel = Pointshop2.rModel | ||
|
||
local rTable = { | ||
ent = rModel, | ||
|
||
cam_pos = Vector(), | ||
cam_ang = Angle(), | ||
cam_fov = 90 | ||
} | ||
|
||
local rTexture | ||
|
||
|
||
rIcon:SetVisible( false ) | ||
rIcon:SetSize( 256, 256 ) | ||
|
||
rModel:SetNoDraw( true ) | ||
|
||
function rModel:RenderOverride() | ||
if not rTexture then return end | ||
cam.Start2D() | ||
surface.SetDrawColor( 255, 255, 255 ) | ||
|
||
render.PushFilterMin( TEXFILTER.ANISOTROPIC ); | ||
render.PushFilterMag( TEXFILTER.ANISOTROPIC ); | ||
surface.SetMaterial( rTexture ) | ||
surface.DrawTexturedRectUV( 0, 0, 512, 512, 0, 0, 1, 1 ) | ||
render.PopFilterMag( ) | ||
render.PopFilterMin( ) | ||
cam.End2D() | ||
end | ||
|
||
hook.Add( "HUDPaint", "TShop: ProcessIconQueue", function() | ||
if queue:IsEmpty() then | ||
return | ||
end | ||
|
||
-- Render icon | ||
local itemClass = queue:Pop() | ||
|
||
rTexture = Pointshop2.RenderModelIcon(itemClass) | ||
|
||
rIcon:SetModel( getIconUID( itemClass ) ) | ||
rIcon:RebuildSpawnIconEx( rTable ) | ||
end ) | ||
|
||
hook.Add( "SpawniconGenerated", "TShop: IconPopulate", function( model, image ) | ||
local pending = promises[model] | ||
|
||
if pending then | ||
local path = image:gsub( "materials\\", "" ) | ||
local icon = Material( path ) | ||
|
||
-- Force the icon to refresh | ||
icon:GetTexture( "$basetexture" ):Download() | ||
|
||
pending:Resolve(icon) | ||
end | ||
|
||
if !pending then | ||
print( "no prom for ", model ) | ||
end | ||
end ) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
local plyModel = hook.Run( "PS2_GsetPreviewModel" ) or "models/player/alyx.mdl" | ||
local entity = ClientsideModel( plyModel, RENDER_GROUP_OPAQUE_ENTITY ) | ||
pac.SetupENT( entity ) | ||
entity:SetNoDraw(true) | ||
entity:SetIK( false ) | ||
local colAmbientLight = Color( 50, 50, 50 ) | ||
local colColor = Color( 255, 255, 255, 255 ) | ||
local directionalLight = { | ||
[BOX_TOP] = Color(255, 255, 255), | ||
[BOX_FRONT] = Color(255, 255, 255) | ||
} | ||
local function paintActual(itemClass) | ||
local outfit = itemClass.getOutfitForModel(plyModel) | ||
pac.SetupENT( entity ) | ||
entity:AttachPACPart(outfit) | ||
entity:FrameAdvance( 100 ) | ||
|
||
|
||
local viewInfo = itemClass.iconInfo.shop.iconViewInfo | ||
for i = 1, 100 do | ||
pac.Think() | ||
end | ||
|
||
cam.Start3D( viewInfo.origin, viewInfo.angles, viewInfo.fov - 20, 0, 0, 512, 512, 5, 4096 ) | ||
cam.IgnoreZ( true ) | ||
render.SuppressEngineLighting( true ) | ||
render.SetLightingOrigin( entity:GetPos() ) | ||
render.ResetModelLighting( colAmbientLight.r/255, colAmbientLight.g/255, colAmbientLight.b/255 ) | ||
render.SetColorModulation( colColor.r/255, colColor.g/255, colColor.b/255 ) | ||
render.SetBlend( 1 ) | ||
|
||
for i=0, 6 do | ||
local col = directionalLight[ i ] | ||
if ( col ) then | ||
render.SetModelLighting( i, col.r/255, col.g/255, col.b/255 ) | ||
end | ||
end | ||
|
||
pac.FlashlightDisable( true ) | ||
pac.ForceRendering( true ) | ||
pac.RenderOverride( entity, "opaque" ) | ||
pac.RenderOverride( entity, "translucent", true ) | ||
entity:DrawModel( ) | ||
pac.RenderOverride( entity, "translucent", true ) | ||
pac.ForceRendering( false ) | ||
pac.FlashlightDisable( false ) | ||
|
||
cam.IgnoreZ( false ) | ||
render.SuppressEngineLighting( false ) | ||
cam.End3D( ) | ||
|
||
entity:RemovePACPart(outfit) | ||
end | ||
|
||
|
||
local mat_BlurX = Material( "pp/blurx" ) | ||
local mat_BlurY = Material( "pp/blury" ) | ||
local mat_Copy = Material( "pp/copy" ) | ||
local blurredRt, otherRt | ||
local function blur( rt, x, y, w, h, sizex, sizey, passes ) | ||
blurredRt = blurredRt or GetRenderTarget("BlurredRT", 512, 512) | ||
otherRt = otherRt or GetRenderTarget("TempRT", 512, 512) | ||
|
||
render.PushRenderTarget( blurredRt, 0, 0, 512, 512 ) | ||
render.OverrideAlphaWriteEnable( true, true ) | ||
render.Clear( 0, 0, 0, 255, true, true ) | ||
|
||
-- Copy rt to blur texture | ||
mat_Copy:SetTexture( "$basetexture", rt ) | ||
surface.SetMaterial(mat_Copy) | ||
surface.SetDrawColor(color_white) | ||
surface.DrawTexturedRectUV(0, 0, 512, 512, 0, 0, 1, 1) | ||
|
||
mat_BlurX:SetTexture( "$basetexture", blurredRt ) | ||
mat_BlurY:SetTexture( "$basetexture", otherRt ) | ||
mat_BlurX:SetFloat( "$size", sizex ) | ||
mat_BlurY:SetFloat( "$size", sizey ) | ||
|
||
for i=1, passes+1 do | ||
render.SetRenderTarget( otherRt ) | ||
surface.SetMaterial( mat_BlurX ) | ||
surface.DrawTexturedRect(0, 0, 512, 512) | ||
|
||
render.SetRenderTarget( blurredRt ) | ||
surface.SetMaterial( mat_BlurY ) | ||
surface.DrawTexturedRect(0, 0, 512, 512) | ||
end | ||
render.OverrideAlphaWriteEnable( false ) | ||
render.PopRenderTarget() | ||
end | ||
|
||
local UID = "ItemTextureRT" | ||
local csgoBg = Material('materials/itembg-ps2.png') | ||
function Pointshop2.RenderModelIcon(itemClass) | ||
local rt = GetRenderTarget( UID, 512, 512 ) | ||
local mat = CreateMaterial( UID .. "_Mat", "UnlitGeneric", { | ||
["$basetexture"] = rt, | ||
} ) | ||
|
||
local oldW, oldH = ScrW(), ScrH() | ||
local oldRt = render.GetRenderTarget( ) | ||
render.SetRenderTarget( rt ) | ||
render.Clear( 0, 0, 0, 255, true, true ) | ||
render.SetViewPort( 0, 0, 512, 512 ) | ||
cam.Start2D() | ||
surface.SetDrawColor( 255, 255, 255, 255 ) | ||
surface.SetMaterial(csgoBg) | ||
surface.DrawTexturedRect(0, 0, 512, 512) | ||
paintActual(itemClass) | ||
blur(rt, 100, 100, 512, 512, 2, 2, 25) | ||
|
||
cam.IgnoreZ(true) | ||
mat:SetTexture( "$basetexture", blurredRt ) | ||
surface.SetMaterial(mat) | ||
render.SetScissorRect( 0, 512 - 120, 512, 512, true ) -- Enable the rect | ||
surface.DrawTexturedRect(0, 0, 512, 512) | ||
render.SetScissorRect( 0, 0, 0, 0, false ) -- disable the rect | ||
cam.IgnoreZ(false) | ||
cam.End2D() | ||
render.SetViewPort( 0, 0, oldW, oldH ) | ||
render.SetRenderTarget( oldRt ) | ||
|
||
mat:SetTexture( "$basetexture", rt ) | ||
return mat | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.