Hey all, I'm working on making a glowing mystical entity. I'm trying to give it a nice glow, so I'm using [B][URL="http://wiki.garrysmod.com/?title=G.DynamicLight"]G.DynamicLight [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG][/URL][/B]. However, it only lights up the area around it. Is there any way to make a fuzzy orb type light in the middle of the prop?
i use the stencil buffers to do that for my gamemode
Could you explain further upon that? I've no idea how to use stencil buffers.
You'll need to use a sprite and DynamicLight. Look at the code for gmod_light in the garry's mod source code.
i dont know really how to use the stencil buffers either, but Jinto gave some really good example code. this is what i use:
include("shared.lua")
local MaterialBlurX = Material( "pp/blurx" );
local MaterialBlurY = Material( "pp/blury" );
local MaterialWhite = CreateMaterial( "WhiteMaterial", "VertexLitGeneric", {
["$basetexture"] = "color/white",
["$vertexalpha"] = "1",
["$model"] = "1", } );
local MaterialComposite = CreateMaterial( "CompositeMaterial", "UnlitGeneric", {
["$basetexture"] = "_rt_FullFrameFB",
["$additive"] = "1", } );
// we need two render targets, if you don't want to create them yourself, you can // use the bloom textures, they are quite low resolution though.
// render.GetBloomTex0() and render.GetBloomTex1();
local RT1 = render.GetBloomTex0()
local RT2 = render.GetBloomTex1();
/*------------------------------------ RenderToStencil() ------------------------------------*/
local function RenderToStencil( entity )
// tell the stencil buffer we're going to write a value of one wherever the model
// is rendered
render.SetStencilEnable( true );
render.SetStencilFailOperation( STENCILOPERATION_KEEP );
render.SetStencilZFailOperation( STENCILOPERATION_KEEP );
render.SetStencilPassOperation( STENCILOPERATION_REPLACE );
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_ALWAYS );
render.SetStencilWriteMask( 1 );
render.SetStencilReferenceValue( 1 );
// this uses a small hack to render ignoring depth while not drawing color
// i couldn't find a function in the engine to disable writing to the color channels
// i did find one for shaders though, but I don't feel like writing a shader for this.
cam.IgnoreZ( true );
render.SetBlend( 0 );
SetMaterialOverride( MaterialWhite );
entity:DrawModel();
SetMaterialOverride();
render.SetBlend( 1 );
cam.IgnoreZ( false );
// don't need this for the next pass
render.SetStencilEnable( false );
end
/*------------------------------------ RenderToGlowTexture() ------------------------------------*/
local function RenderToGlowTexture( entity )
local w, h = ScrW(), ScrH();
// draw into the white texture
local oldRT = render.GetRenderTarget();
render.SetRenderTarget( RT1 );
render.SetViewPort( 0, 0, 512, 512 );
cam.IgnoreZ( true );
render.SuppressEngineLighting( true );
render.SetColorModulation( 1, 0, 0 );
// Set color of glow here
SetMaterialOverride( MaterialWhite );
entity:DrawModel();
SetMaterialOverride();
render.SetColorModulation( 1, 1, 1 );
render.SuppressEngineLighting( false );
cam.IgnoreZ( false );
render.SetViewPort( 0, 0, w, h );
render.SetRenderTarget( oldRT );
end
/*------------------------------------ RenderScene() ------------------------------------*/
local function RenderScene( Origin, Angles )
render.ClearRenderTarget( RT1, Color( 0, 0, 0, 255 ) );
end hook.Add( "RenderScene", "ResetGlow", RenderScene );
/*------------------------------------ RenderScreenspaceEffects() ------------------------------------*/
local function RenderScreenspaceEffects( )
MaterialBlurX:SetMaterialTexture( "$basetexture", RT1 );
MaterialBlurY:SetMaterialTexture( "$basetexture", RT2 );
MaterialBlurX:SetMaterialFloat( "$size", 2 );
MaterialBlurY:SetMaterialFloat( "$size", 2 );
local oldRT = render.GetRenderTarget();
// blur horizontally
render.SetRenderTarget( RT2 );
render.SetMaterial( MaterialBlurX );
render.DrawScreenQuad();
// blur vertically
render.SetRenderTarget( RT1 );
render.SetMaterial( MaterialBlurY );
render.DrawScreenQuad();
render.SetRenderTarget( oldRT );
// tell the stencil buffer we're only going to draw
// where the player models are not.
render.SetStencilEnable( true );
render.SetStencilReferenceValue( 0 );
render.SetStencilTestMask( 1 );
render.SetStencilCompareFunction( STENCILCOMPARISONFUNCTION_EQUAL );
render.SetStencilPassOperation( STENCILOPERATION_ZERO );
// composite the scene
MaterialComposite:SetMaterialTexture( "$basetexture", RT1 );
render.SetMaterial( MaterialComposite );
render.DrawScreenQuad();
// don't need this anymore
render.SetStencilEnable( false );
end
hook.Add( "RenderScreenspaceEffects", "CompositeGlow", RenderScreenspaceEffects );
/*------------------------------------ PrePlayerDraw() ------------------------------------*/
function ENT:Draw()
self.Entity:DrawModel()
RenderToStencil( self );
RenderToGlowTexture( self );
end
[editline]03:01PM[/editline]
however, that requires some render targets' give me a sec to write it so it dosent
[QUOTE=Tobba;19588241]i dont know really how to use the stencil buffers either, but Jinto gave some really good example code. this is what i use:[/QUOTE]
Either you didn't understand his question, or you don't know what you're talking about.
[QUOTE=Gbps;19582593]You'll need to use a sprite and DynamicLight. Look at the code for gmod_light in the garry's mod source code.[/QUOTE]
This is the way to go. Do it.
[QUOTE=_Kilburn;19591541]Either you didn't understand his question, or you don't know what you're talking about.[/QUOTE]
How about both?
Sorry, you need to Log In to post a reply to this thread.