[QUOTE=Entoros;18278565][url]http://www.facepunch.com/showpost.php?p=18277721&postcount=84[/url]
QUICK JINTO, GO![/QUOTE]
Oh man, that would be awesome if Garry included this in vanilla Gmod.
[QUOTE=Jinto;18275971]Elaborate. What specific info do you want about the mesh?[/QUOTE]
And if possible, something in an output that [url=http://wiki.garrysmod.com/?title=Entity.PhysicsFromMesh]Entity.PhysicsFromMesh[/url] would accept.
[editline]03:32PM[/editline]
[QUOTE=Entoros;18278565][url]http://www.facepunch.com/showpost.php?p=18277721&postcount=84[/url]
QUICK JINTO, GO![/QUOTE]
And yes, do it.
Not everything will be added. But most of the functions will be.
[QUOTE=Jinto;18283947]Not everything will be added. But most of the functions will be.[/QUOTE]
Why not everything?
Could you give a list of what will be included?
[quote]render.PushCustomClipPlane( normal, distance )
render.PopCustomClipPlane()
render.EnableClipping( enabled )
render.SetStencilEnable( enabled )
render.SetStencilFailOperation( stencil operation )
render.SetStencilZFailOperation( stencil operation )
render.SetStencilPassOperation( stencil operation )
render.SetStencilCompareFunction( stencil function )
render.SetStencilReferenceValue( value )
render.SetStencilTestMask( value )
render.SetStencilWriteMask( value )
render.ClearStencilBufferRectangle( left, top, right, bottom, value )
render.ClearStencil()
render.ClearBuffersObeyStencil( r, g, b, a, depth )
render.PerformFullScreenStencilOperation()
render.FogMode( fog mode )
render.FogStart( start )
render.FogEnd( end )
render.SetFogZ( height )
render.GetFogMode()
render.FogColor( r, g, b )
render.GetFogColor()
render.GetFogDistances()
render.FogMaxDensity( density )
render.CullMode( culling mode )
render.SetScissorRect( x, y, width, height, enabled )
Entity:SetRenderClipPlane( normal, distance )
Entity:SetRenderClipPlaneEnabled( enabled )
STENCILOPERATION_KEEP
STENCILOPERATION_ZERO
STENCILOPERATION_REPLACE
STENCILOPERATION_INCRSAT
STENCILOPERATION_DECRSAT
STENCILOPERATION_INVERT
STENCILOPERATION_INCR
STENCILOPERATION_DECR
STENCILCOMPARISONFUNCTION_NEVER
STENCILCOMPARISONFUNCTION_LESS
STENCILCOMPARISONFUNCTION_EQUAL
STENCILCOMPARISONFUNCTION_LESSEQUAL
STENCILCOMPARISONFUNCTION_GREATER
STENCILCOMPARISONFUNCTION_NOTEQUAL
STENCILCOMPARISONFUNCTION_GREATEREQUAL
STENCILCOMPARISONFUNCTION_ALWAYS
MATERIAL_FOG_NONE
MATERIAL_FOG_LINEAR
MATERIAL_FOG_LINEAR_BELOW_FOG_Z
MATERIAL_CULLMODE_CCW
MATERIAL_CULLMODE_CW
[/quote]
As it stands now, those are all the ones I gave him. It's all garry's choice in the end. He may add, remove, or change any one of those, so don't think this is final or that any of them will even be in it.
It won't include any rendertarget creation functions, as garry removed those for a reason. You'll have to use the GetRenderTarget function and a text file.
[QUOTE=Jinto;18293801]As it stands now, those are all the ones I gave him. It's all garry's choice in the end. He may add, remove, or change any one of those, so don't think this is final or that any of them will even be in it.[/QUOTE]
Do you think you can you give him the mesh functions?
[QUOTE=Spacetech;18300430]Do you think you can you give him the mesh functions?[/QUOTE]
I will but, it'll work a bit differently.
Sent him these, again, no guarantees they'll be added.
[quote]mesh.Begin( primitive type, primitive count )
mesh.End()
mesh.AdvanceVertex()
mesh.Position( position )
mesh.Normal( normal )
mesh.Color( r, g, b, a )
mesh.TexCoord( stage, u, v )
mesh.Specular( r, g, b, a )
mesh.TangentS( tangent )
mesh.TangentT( tangent )
mesh.VertexCount()
MATERIAL_POINTS
MATERIAL_LINES
MATERIAL_TRIANGLES
MATERIAL_TRIANGLE_STRIP
MATERIAL_LINE_STRIP
MATERIAL_LINE_LOOP
MATERIAL_POLYGON
MATERIAL_QUADS
[/quote]
I chose to do it that way to keep in the gmod style. If these are added, here is some stuff to know. As soon as you call mesh.End() it's drawn. So have your model matrix pushed and ready to go.
from the beta SVN changelog
[code]
Added render.PushCustomClipPlane( vector, distance )
Added render.PopCustomClipPlane()
Added render.EnableClipping( enabled )
Added render.SetStencilEnable( enabled )
Added render.SetStencilFailOperation( stencil operation )
Added render.SetStencilZFailOperation( stencil operation )
Added render.SetStencilPassOperation( stencil operation )
Added render.SetStencilCompareFunction( stencil function )
Added render.SetStencilReferenceValue( value )
Added render.SetStencilTestMask( value )
Added render.SetStencilWriteMask( value )
Added render.ClearStencilBufferRectangle( left, top, right, bottom, value )
Added render.ClearStencil()
Added render.ClearBuffersObeyStencil( r, g, b, a, depth )
Added render.PerformFullScreenStencilOperation()
Added render.FogMode( fog mode )
Added render.FogStart( start )
Added render.FogEnd( end )
Added render.SetFogZ( height )
Added render.GetFogMode()
Added render.FogColor( r, g, b )
Added render.GetFogColor()
Added render.GetFogDistances()
Added render.FogMaxDensity( density )
Added render.CullMode( culling mode )
Added render.SetScissorRect( x, y, width, height, enabled )
Added Entity:SetRenderClipPlane( vector, distance )
Added Entity:SetRenderClipPlaneEnabled( enabled )
Added mesh.Begin( primitive type, primitive count )
Added mesh.End()
Added mesh.AdvanceVertex()
Added mesh.Position( position )
Added mesh.Normal( normal )
Added mesh.Color( r, g, b, a )
Added mesh.TexCoord( stage, u, v )
Added mesh.Specular( r, g, b, a )
Added mesh.TangentS( tangent )
Added mesh.TangentT( tangent )
Added mesh.VertexCount()
[/code]
:iia:
I'm going to guess that this means we can use these functions in the gamemode competition now. Awesome.
A great module finally getting into the vanilla.
:D
EDIT:
Wait a minute, I tried the beta SVN for gmod that should include this... I don't think ALL of it was included...
This is probably the newbiest thing I'm every going to say but how do you define the normal?
[QUOTE=Hemroid_Man;18470236]This is probably the newbiest thing I'm every going to say but how do you define the normal?[/QUOTE]
Normal for what? Mesh? Plane?
[QUOTE=Jinto;18477522]Normal for what? Mesh? Plane?[/QUOTE]
Plane.
[QUOTE=Hemroid_Man;18485280]Plane.[/QUOTE]
It's just a unit vector in any direction. To calculate the distance for the plane do this.
[lua]local dist = normal:Dot( point );[/lua]
Where normal is the normal, and point is any point in the world.
Hey Jinto, In the beta SVN I've been trying to make two entities display a dynamic mesh at the same time, but when I spawn more than one of them, the old mesh disappears until I delete the entity I just spawned. Am I doing something wrong, or is it just impossible?
Also in the beta SVN I can't change the colors of the vertices.
[QUOTE=helpiminabox;18493371]Hey Jinto, In the beta SVN I've been trying to make two entities display a dynamic mesh at the same time, but when I spawn more than one of them, the old mesh disappears until I delete the entity I just spawned. Am I doing something wrong, or is it just impossible?
Also in the beta SVN I can't change the colors of the vertices.[/QUOTE]
Changing the vertex colors on a VertexLitGeneric material doesn't seem to work. Change the shader to something else and it will. It's very possible to show more than one at a time. Can you show your drawing code?
[lua]function ENT:Draw()
self:SetRenderBounds(Vector(-32768,-32768,-32768),Vector(32768,32768,32768))
render.SetMaterial(Material("models/debug/debugwhite"));
mesh.Begin(MATERIAL_TRIANGLES, 1 );
mesh.Position(self.Entity:GetPos()+Vector( 128, 128, 0 ) );
mesh.Normal(Vector(0,0,1) );
mesh.TexCoord( 0, 0, 0 );
mesh.Color(255,0,0,255);
mesh.AdvanceVertex();
mesh.Position(self.Entity:GetPos()+Vector( 128, 0, 0 ) );
mesh.Normal(Vector(0,0,1) );
mesh.TexCoord( 0, 1, 0 );
mesh.Color(255,0,0,255);
mesh.AdvanceVertex();
mesh.Position(self.Entity:GetPos()+Vector( 0, 0, 0 ) );
mesh.Normal( Vector(0,0,1) );
mesh.TexCoord( 0, 1, 1 );
mesh.Color(255,0,0,255);
mesh.AdvanceVertex();
mesh.End();
end
[/lua]
That's all of it right there. Just a simple triangle that I was testing.
Edit: Also, tried changing the material to UnlitGeneric and then LightmappedGeneric and I still couldn't change the colors.
Edit2: Found out what was wrong with my code, I only have the color problem now.
When I try to render a cube with the mesh builder, some of the triangles are randomly blacked out:
[IMG]http://i46.tinypic.com/acxzkh.jpg[/IMG]
Here's the code I'm using to draw this:
[lua]
ENT.BoxSize = 32
function ENT:GetMeshTable()
local mesht = MeshCube( self.BoxSize, 2 )
local sqrt3 = math.sqrt( 3 ) / 3
for k, v in pairs( mesht ) do
v.normal = v.pos * sqrt3
end
return mesht
end
[/lua]
[lua]
function ENT:Draw()
local neo = Matrix()
neo:Translate( self:GetPos() )
neo:Rotate( self:GetAngles() )
cam.PushModelMatrix( neo )
local r, g, b, a = self:GetColor()
self.MeshTable = self.MeshTable or self:GetMeshTable()
render.SetMaterial( self.Mat )
mesh.Begin( MATERIAL_TRIANGLES, 12 )
for k, v in pairs( self.MeshTable ) do
mesh.Position( v.pos )
mesh.Normal( v.normal )
mesh.TexCoord( 0, v.u, v.v )
mesh.Color( r, g, b, a )
mesh.AdvanceVertex()
end
mesh.End()
cam.PopModelMatrix()
end
[/lua]
What am I doing wrong?
[b]Edit:[/b]
It does the same thing if I build it out of quads, but it only affects one quad (the last one drawn). For drawing with triangles, the same thing seems to happen with the bump-maps and specular maps too (they're not rendered for random triangles, even though the texture might be).
math.sqrt(3)/3 is the same as 1/math.sqrt(3) or just 1/3^0.5
not that it helps in the slightest, perhaps you should build the box from triangles yourself and see if it works, that will tell you if it's the MeshCube() or your render function.
Using a bit of code to draw stencil for whatever the player is looking at (minus the world)
Is there a way to change the colour easily? I don't want to have to create a fresh texture for every different colour.
E.g. render.SetDrawColor() or something, I can't see that function in the wiki, anyhow.
Sorry to bump this thread, but these new render library elements need some documentation. Maybe who knows what they do, should go to the Lua Wiki and add them up. (With example and a good description).
Also, it's a shame not all of them were added by Garry...
Okay, nvm. I dug around and found some code for drawing with the stencils, and edited it so I could try it on stuff I was looking at.
[b]Okay nevermind I was a dumbass and didn't realise it doesn't work in HUDPaint[/b]
[code]
CreateConVar("entityhighlight_mat","models/debug/debugwhite")
local curmat = "models/debug/debugwhite"
local mat = Material(curmat)
hook.Add("HUDPaint","AwesomeStencil",function()
local tr = LocalPlayer():GetEyeTrace()
if input.IsKeyDown(KEY_COMMA) and ValidEntity(tr.Entity) and !tr.Entity:IsWorld() then
render.ClearStencil()
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)
// draw the model into the stencil buffer
tr.Entity:DrawModel()
// setup the stencil buffer
render.SetStencilTestMask(1)
render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_EQUAL)
render.SetStencilPassOperation(STENCILOPERATION_REPLACE)
// disable depth writing
//render.OverrideDepthEnable(true,false)
// draw
if GetConVarString("entityhighlight_mat") ~= curmat then
//Time for a change
curmat = GetConVarString("entityhighlight_mat") or "models/debug/debugwhite"
mat = Material(curmat)
end
render.SetMaterial(mat)
render.DrawScreenQuad()
// enable depth writing
//render.OverrideDepthEnable(false,true)
// disable stencil buffer
render.SetStencilEnable(false);
end
end)
[/code]
Unfortunately it doesn't work, i'm assuming that's because I had to comment out the OverrideDepthEnable thing.. did garry forget this function or has it been added to the update in a new form?
I've noticed that, too. I think he forgot to add more (such as the Plane() function and related)...
EDIT: I've also tried the very first example Jinto wrote and it doesn't work without that 'magical function'.
Also, to Jinto: *begs* Give us some documentation to chew on, please.
Okay, I had another go.
I spawned a few barrels and had it hooked up to the comma key. On press, it rendered a blob near the right of the screen. Then spawned kleiner, tried it on him, and it turned out it was rendering below the entity! (it was rendering his feet)
I think with a bit of INVERT I managed to get it to draw black, but not much else.
No idea until Jinto releases his example code.
You can just use cam.IgnoreZ() in place of OverrideDepthEnable. As for plane, I don't see the point in it anymore. Just use this.
[lua]
local normal = Vector( 0, 0, 1 );
local dist = normal:Dot( point );
[/lua]
I'm cleaning up the code for the outline effect now, then I'll release.
[editline]05:06PM[/editline]
This is very crude. But it works. If the player goes outside your PVS it won't render anymore. Keep that in mind. I'm sure one of you guys can clean it up and maybe make use of it.
[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 = GetRenderTarget( "L4D1" );
local RT2 = GetRenderTarget( "L4D2" );
/*------------------------------------
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()
------------------------------------*/
local function PostPlayerDraw( pl )
// prevent recursion
if( OUTLINING_PLAYER ) then return; end
OUTLINING_PLAYER = true;
RenderToStencil( pl );
RenderToGlowTexture( pl );
// prevents recursion time
OUTLINING_PLAYER = false;
end
hook.Add( "PostPlayerDraw", "RenderGlow", PostPlayerDraw );
[/lua]
The above code will generate the following.
[img]http://cdbarrett.com/dm_overwatch0000.jpg[/img]
I'm liking this stencil buffer:
[IMG]http://i48.tinypic.com/2yn41w4.jpg[/IMG]
I'm confused about some things though...
1. Does STENCILOPERATION_REPLACE replace the pixels with the reference value?
2. What do the write masks and test masks do exactly?
3. When is the fail operation called?
4. What does render.PerformFullScreenStencilOperation do?
5. Is there any way to create and draw to additional stencil buffers?
Once the documentation's up, I think we'll see a lot more renderX functions being used in the future!
Sorry, you need to Log In to post a reply to this thread.