• CreateMaterial UnlitTwoTexture/VertlitGeneric Texture Proxies
    4 replies, posted
Hello, I've got a quite weird issue and I'm honestly not sure if what I'm trying to do is even possible. I've been using the following code to "recreate" the female player_sheet VMT. The idea is to embed a secondary texture within the first one without having to manually edit the texture. The texture2 and texture2transform parameters only seem to work in UnlitTwoTexture, but the shader completely ignores/invalidates all of the playercolor proxies and such. In VertlitGeneric the texture works fine, but since texture2 and texture2transform are non-existent, they don't ever get rendered. Is there anyway around this? [lua]local params = { ["$basetexture"] = "models/humans/female/group01/players_sheet", ["$bumpmap"] = "models/humans/female/group01/players_sheet_normal", ["$texture2"] = "proximity/acat1.jpg", ["$texture2transform"] = "center .5 .5 scale 5 5 rotate 0 translate 1.4 -1.6", ["$halflambert"] = "1", ["$phong"] = "1", ["$phongboost"] = "0.3", ["$phongfresnelranges"] = "[0.1 0.2 0.5]", ["$phongexponenttexture"] = "models/humans/female/group01/players_sheet_phong", ["$rimlight"] = "1", ["$rimlightexponent"] = "8", ["$rimlightboost"] = "2", ["$rimmask"] = "1", ["$blendtintbybasealpha"] = "1" , ["$blendtintcoloroverbase"] = "0", ["$PhongBrightnessScalar"] = "0.5", ["Proxies"] = { ["PlayerColor"] = { ["resultVar"] = "$color2", ["default"] = "0.23 0.35 0.41", }, ["Clamp"] = { ["min"] = "0.01", ["max"] = "1.25", ["srcVar1"] = "$color2", ["resultVar"] = "$color2" }, ["Clamp"] = { ["min"] = "0.5", ["max"] = "1.0", ["srcVar1"] = "$color2", ["resultVar"] = "$phongtint" }, ["Equals"] = { ["srcVar1"] = "$color2", ["resultVar"] = "$PhongBrightnessScalar" }, ["Multiply"] = { ["srcVar1"] = "$phongtint", ["srcVar2"] = "$phongBrightnessScalar", ["resultVar"] = "$phongtint", }, ["Clamp"] = { ["min"] = "0.25", ["max"] = "1.0", ["srcVar1"] = "$phongtint", ["resultVar"] = "$phongtint" }, } } local n = "acat" .. tostring( math.random( 1, 10000 ) ) mat = CreateMaterial(n, "UnlitTwoTexture", params ) print( n ) LocalPlayer():SetSubMaterial( 2, "!" .. tostring( n ) ) LocalPlayer():SetPlayerColor( Vector( 1, 1, 1 ) ) breen_img:SetImage( "!" .. tostring( n ) )[/lua] full color UnlitTwoTexture:[t]https://i.gyazo.com/2ec9431a94b47a51321bab19ac2edc81.png[/t] PlayerColor UnlitTwoTexture:[t]https://i.gyazo.com/241f2d7f5979c8e263e04981448d891d.png[/t] PlayerColor VertLitGeneric:[t]https://i.gyazo.com/c7abda4d99e8987c2391504bda198dca.png[/t]
You're probably better off using a rendertarget for your basetexture and drawing your second image into that
[QUOTE=TFA;52310238]You're probably better off using a rendertarget for your basetexture and drawing your second image into that[/QUOTE] Got any good examples of building 2 textures into a single rendertarget? Never quite played around with them, and it doesn't look to have much documentation EDIT: hold up I think I'm getting on the right track ok my tests have failed
[QUOTE=kpjVideo;52310311]Got any good examples of building 2 textures into a single rendertarget? Never quite played around with them, and it doesn't look to have much documentation EDIT: hold up I think I'm getting on the right track ok my tests have failed[/QUOTE] The was a rollercoaster of a post. Basically, create a render target texture. To that, render the texture used by the model, and then render your image to the right coordinates. Create a material and set the basetexture to your rendertarget, then set the material of the model to the material you have just created.
[QUOTE=James xX;52311291]The was a rollercoaster of a post. Basically, create a render target texture. To that, render the texture used by the model, and then render your image to the right coordinates. Create a material and set the basetexture to your rendertarget, then set the material of the model to the material you have just created.[/QUOTE] Hmm, I've found this example on another old thread. [lua] local _Rand = tostring( math.random(1,99999) ) local _Material = CreateMaterial("uniquemat" .. _Rand, "UnlitGeneric", params) local _Cat = Material( "proximity/roulette_logo.png" ) local ost = os.time() local RT = GetRenderTarget( "RENDERER" .. ost, 1024, 1024 ) local OldRT = nil local OldScrW = nil local OldScrH = nil local RenderWidth = 1024 local RenderHeight = 1024 local screenMat = _Material local OldTex = nil local CamData = {} hook.Add( "HUDPaint", "TestScreen", function() OldRT = render.GetRenderTarget() OldScrW = ScrW() OldScrH = ScrH() render.SetViewPort( 0, 0, RenderWidth, RenderHeight ) render.SetRenderTarget( RT ) render.Clear( 0, 0, 0, 255 ) CamData = { x = 0, y = 0, w = RenderWidth, h = RenderHeight, origin = EyePos(), angles = EyeAngles(), drawhud = false, drawviewmodel = false, dopostprocess = false, } render.RenderView( CamData ) render.SetRenderTarget( OldRT ) cam.Start2D() surface.SetMaterial( _Material ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.DrawTexturedRect( 0, 0, 1024, 1024 ) surface.SetMaterial( _Cat ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.DrawTexturedRect( 125, 750, 256, 128 ) cam.End2D() render.SetViewPort( 0, 0, OldScrW, OldScrH ) OldTex = screenMat:GetTexture( "$basetexture" ) screenMat:SetTexture( "$basetexture", RT ) screenMat:SetTexture( "$basetexture", OldTex ) end ) [/lua] I'm using HUDPaint to temporarily show me the texture on screen, which appears to be what I'm looking for, but I have a strange feeling that the location of the cam.Start2D Is just rendering outside of the render target. I've attempted to double check this, but setting any entity's material to screenMat, OldRT, or RT doesn't do anything :s:
Sorry, you need to Log In to post a reply to this thread.