• Help rendering image (Cam2D3D) lightning
    10 replies, posted
Hi there, I'm trying to make an image (png) go darker when in darker areas. (Image gets returned using Material) Explanation using screens: ( sorry for large screenshots :) ) [img]http://puu.sh/a7juX/a5f5712612.jpg[/img] [img]http://puu.sh/a7jx6/16cd1f886d.jpg[/img] Now, as you can see in the screenshots above the plate stays as bright as before, and I would like to find a way to make it go darker aswell. I tried several methods and none worked so far. (Code belown is original, without my failed attempts obviously) My code:[lua]hook.Add("PostDrawTranslucentRenderables", "cl_drawplates", function( depth, sky ) if sky or depth then return end for _,veh in pairs( ents.GetAll() ) do if !IsValid( veh ) or !veh:IsVehicle() or veh:GetPos():Distance( LocalPlayer():GetShootPos() ) > DistanceFade then continue end local vname = veh:GetNWString( "veh_name" ) local plates = GetVehiclePlates( vname ) if !plates then continue end local pserial = veh:GetNWString( "plate_serial" ) if !pserial or string.len( pserial ) < 1 then continue end render.SuppressEngineLighting( true ) for _,pinfo in pairs( plates ) do cam.Start3D2D( veh:LocalToWorld( pinfo.pos ), veh:LocalToWorldAngles( pinfo.ang ), pinfo.scale ) surface.SetMaterial( plateMat ) surface.SetDrawColor( Color( 255, 255, 255, 255 ) ) surface.DrawTexturedRect( -pwidth / 2 - 6, -pheight / 2 - 6, pwidth + 12, pheight + 12 ) draw.SimpleText( pserial, "PlateFontBig", 0, 0, PlateTextColor, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) cam.End3D2D() end render.SuppressEngineLighting( false ) end end)[/lua] Thanks in advance.
Maybe remove the [lua]render.SuppressEngineLighting( true )[/lua] ? [editline]11th July 2014[/editline] Not experienced with 3D2D neither shadowing, correct me if i am wrong
render.SuppressEngineLighting( true ) won't do anything. You gotta draw it darker according to these functions: [url]http://wiki.garrysmod.com/page/render/ComputeDynamicLighting[/url] [url]http://wiki.garrysmod.com/page/render/ComputeLighting[/url] [url]http://wiki.garrysmod.com/page/render/GetLightColor[/url] [url]http://wiki.garrysmod.com/page/render/GetAmbientLightColor[/url]
[QUOTE=GGG KILLER;45361903]Maybe remove the [lua]render.SuppressEngineLighting( true )[/lua] ? [editline]11th July 2014[/editline] Not experienced with 3D2D neither shadowing, correct me if i am wrong[/QUOTE] Tried that already and then the entire car and my physgun aswell are very, very bright. [editline]11th July 2014[/editline] [QUOTE=Robotboy655;45361916]render.SuppressEngineLighting( true ) won't do anything. You gotta draw it darker according to these functions: [url]http://wiki.garrysmod.com/page/render/ComputeDynamicLighting[/url] [url]http://wiki.garrysmod.com/page/render/ComputeLighting[/url] [url]http://wiki.garrysmod.com/page/render/GetLightColor[/url] [url]http://wiki.garrysmod.com/page/render/GetAmbientLightColor[/url][/QUOTE] Thanks, but how will that work exactly? I'm not really good with anything clientside related such as derma, and these functions aswell..
[QUOTE=boshadow;45361921]Tried that already and then the entire car and my physgun aswell are very, very bright. [editline]11th July 2014[/editline] Thanks, but how will that work exactly? I'm not really good with anything clientside related such as derma, and these functions aswell..[/QUOTE] I think they'll return the Color with the lightning to that area, now you just have to get the alpha and set the shadow of the plate with it(i think) [editline]11th July 2014[/editline] Something like this, i think:[lua] cam.Start3D2D( veh:LocalToWorld( pinfo.pos ), veh:LocalToWorldAngles( pinfo.ang ), pinfo.scale ) local asd = render.ComputeDynamicLighting( veh:GetPos(), veh:GetPos():Normalize() ) surface.SetMaterial( plateMat ) surface.SetDrawColor( Color( 255, 255, 255, asd.a ) ) surface.DrawTexturedRect( -pwidth / 2 - 6, -pheight / 2 - 6, pwidth + 12, pheight + 12 ) draw.SimpleText( pserial, "PlateFontBig", 0, 0, Color(PlateTextColor.r,PlateTextColor.g,PlateTextColor.b,asd.a) TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) cam.End3D2D() [/lua]
[QUOTE=GGG KILLER;45361948]I think they'll return the Color with the lightning to that area, now you just have to get the alpha and set the shadow of the plate with it(i think) [editline]11th July 2014[/editline] Something like this, i think:[lua] cam.Start3D2D( veh:LocalToWorld( pinfo.pos ), veh:LocalToWorldAngles( pinfo.ang ), pinfo.scale ) local asd = render.ComputeDynamicLighting( veh:GetPos(), veh:GetPos():Normalize() ) surface.SetMaterial( plateMat ) surface.SetDrawColor( Color( 255, 255, 255, asd.a ) ) surface.DrawTexturedRect( -pwidth / 2 - 6, -pheight / 2 - 6, pwidth + 12, pheight + 12 ) draw.SimpleText( pserial, "PlateFontBig", 0, 0, Color(PlateTextColor.r,PlateTextColor.g,PlateTextColor.b,asd.a) TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) cam.End3D2D() [/lua][/QUOTE] Let me test that out EDIT: Nope, [lua]bad argument #2 to 'ComputeDynamicLighting' (Vector expected, got no value)[/lua] When I try this no error was given but problem remains the same though. [lua]local asd = render.ComputeDynamicLighting( Vector(veh:GetPos()), Vector(veh:GetPos():Normalize()) )[/lua]
[lua] cam.Start3D2D( veh:LocalToWorld( pinfo.pos ), veh:LocalToWorldAngles( pinfo.ang ), pinfo.scale ) local asd = render.GetLightColor( veh:GetPos() ) surface.SetMaterial( plateMat ) surface.SetDrawColor( Color( 255, 255, 255, asd.a ) ) surface.DrawTexturedRect( -pwidth / 2 - 6, -pheight / 2 - 6, pwidth + 12, pheight + 12 ) draw.SimpleText( pserial, "PlateFontBig", 0, 0, Color(PlateTextColor.r,PlateTextColor.g,PlateTextColor.b,asd.a) TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) cam.End3D2D() [/lua] then?
[QUOTE=GGG KILLER;45362496][lua] cam.Start3D2D( veh:LocalToWorld( pinfo.pos ), veh:LocalToWorldAngles( pinfo.ang ), pinfo.scale ) local asd = render.GetLightColor( veh:GetPos() ) surface.SetMaterial( plateMat ) surface.SetDrawColor( Color( 255, 255, 255, asd.a ) ) surface.DrawTexturedRect( -pwidth / 2 - 6, -pheight / 2 - 6, pwidth + 12, pheight + 12 ) draw.SimpleText( pserial, "PlateFontBig", 0, 0, Color(PlateTextColor.r,PlateTextColor.g,PlateTextColor.b,asd.a) TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) cam.End3D2D() [/lua] then?[/QUOTE] Nope, triggers no errors but doesn't do the trick either :/
I have no idea then, sorry
[QUOTE=GGG KILLER;45362901]I have no idea then, sorry[/QUOTE] No problem, thanks anyway.
Bump. Someone?
Sorry, you need to Log In to post a reply to this thread.