Garry's Mod

Garry's Mod

1,428 个评价
GShader Library
13
5
7
10
4
4
2
2
7
4
3
2
2
2
   
奖励
收藏
已收藏
取消收藏
素材类型: 插件
插件类型: 工具
插件标签: 风景
文件大小
发表于
更新日期
229.800 KB
8 月 5 日 上午 6:08
11 月 14 日 下午 9:19
115 项改动说明 ( 查看 )

订阅以下载
GShader Library

描述
GShader Library
— a shader library that serves as the foundation for creating Deferred Renderer (shading & lighting) shaders, acting as a convenient tool for creating advanced post-processing effects.

Brief list of textures in the addon:
  • _rt_WPDepth
  • _rt_NormalsTangents
  • _rt_Velocity
  • _rt_ResolvedFullFrameDepth
  • _rt_BumpFog

The addon includes:
  • Reconstruction of WorldPos, WorldNormals and Tangents from _rt_ResolvedFullFrameDepth.
  • Normal smoothing.
  • Increasing the bit depth of the depth buffer _rt_ResolvedFullFrameDepth.
  • View and projection matrices: View, Proj, ViewProj. For perspective and orthogonal projection.
  • Newly discovered texture formats that allow more flexible work with shaders.
  • Encoding Normals and Tangents into a single texture, packing WorldPos and Depth, which will fit within the 4-texture limit in screenspace_general.
  • Choice of normal reconstruction method[wickedengine.net]: Simple, 3 Tap, Improved, Accurate[atyuwen.github.io].
  • Function shaderlib.DrawScreenQuad() with Multiple Render Target support.
  • Function shaderlib.DrawVertexScreenQuad() with input data to vertex shader and MRT support. More info here: Example 6[github.com].
  • Velocity Buffer.

Encoding Normals and Tangents
Normals and Tangents are stored in the render target _rt_NormalsTangents, where:
  • .RG — Normals
  • .B — Tangents
  • .A — Sign: A value of 1 or -1. It will help you with lighting and creating Post-Process Parallax Mapping.
Normals are encoded using Octahedron normal vector encoding [knarkowicz.wordpress.com]
Normal decoding is done via the function:
float3 Decode(float2 f) { f = f * 2.0 - 1.0; // https://twitter.com/Stubbesaurus/status/937994790553227264 float3 n = float3(f.x, f.y, 1.0 - abs(f.x) - abs(f.y)); float t = saturate(-n.z); n.xy += n.xy >= 0.0 ? -t : t; return normalize(n); }
Tangents are encoded using Diamond Encoding [www.jeremyong.com]
Tangent decoding is done via the function:
float2 decode_diamond(float p) { float2 v; // Remap p to the appropriate segment on the diamond float p_sign = sign(p - 0.5f); v.x = -p_sign * 4.f * p + 1.f + p_sign * 2.f; v.y = p_sign * (1.f - abs(v.x)); // Normalization extends the point on the diamond back to the unit circle return normalize(v); } float3 decode_tangent(float3 normal, float diamond_tangent) { // As in the encode step, find our canonical tangent basis span(t1, t2) float3 t1; if (abs(normal.y) > abs(normal.z)) { t1 = float3(normal.y, -normal.x, 0.f); } else { t1 = float3(normal.z, 0.f, -normal.x); } t1 = normalize(t1); float3 t2 = cross(t1, normal); // Recover the coordinates used with t1 and t2 float2 packed_tangent = decode_diamond(diamond_tangent); return packed_tangent.x * t1 + packed_tangent.y * t2; }

Example of working with _rt_NormalsTangents:
float4 normals_tangets = tex2D(NormalTangentBuffer,uv); float flipSign = normals_tangets.a; float3 worldNormal = Decode(normals_tangets.xy); float3 tangents = decode_tangent(worldNormal, normals_tangets.z); float3 binormals = normalize(cross(worldNormal,tangents))* flipSign; float3x3 TBN = float3x3(tangents, binormals, worldNormal);

Packing WorldPos and Depth
WorldPos and Depth are stored in the render target _rt_WPDepth, where:
  • .RGB1/WorldPos: This means that WorldPos is packed into values <1. To unpack, use float3 worldPos = 1/tex2D(WPDepthBuffer,uv).xyz; in the shader.
  • .A — Depth

NOTE:
The depth buffer does not write translucent objects, so you will most likely render shaders in the PreDrawTranslucentRenderables [wiki.facepunch.com] hook.

Special thanks to:
Meetric [github.com] — WorldPos reconstruction.
notunknowndude— the idea to improve the depth buffer.
puwada — the tip about texture format compatibility and DirectX.
LVutner [github.com] — implementation Velocity Buffer encoding of CryTeck method.

Links:

引用自 devonium
SHADERS FOR EVERYONE!!!! i have no idea wtf is going on

P.S. Shader examples are not in the addon. Screenshots show what the GShader library allows you to do.
热门讨论 查看全部(16)
34
9 月 16 日 下午 8:05
Why is there a DMCA notice on this Addon?
CosmicInterloper
11
9 月 19 日 上午 5:29
can someone send a shader from this addon if there is one?
ModestShoducks
7
8 月 28 日 上午 11:12
How this works как это работает?
Tixon-11
434 条留言
mj 11 月 17 日 上午 10:37 
this glitches a lot with third person is there any way to fix it?
Soul Forge 11 月 17 日 上午 12:16 
Valid! :gman:
Evgeny Akabenko  [作者] 11 月 16 日 上午 3:21 
Evgeny Akabenko  [作者] 11 月 16 日 上午 3:21 
I wrote to the MW base developer half a year ago and explained the problem. He didn't create a patch or a fix.

The MW base is just cool modern guns. But damn, let them be compatible with the depth buffer and shaders. It's not my concern, no matter how much I'd like it to be. If I were the developer of the weapons base, I would have made a fix.
It's almost 2026, and the MW base can't be used with a depth buffer to create shaders. Although it could be a nice combination.
I just often get messages saying there's a bug with this addon, or with another one. But it's not my bug. These aren't shader library bugs. All addons that don't work with GShader are the addons' problems, not the GShader library's.
Soul Forge 11 月 16 日 上午 1:49 
Can you fix Gshader for MW base please? world and viewmodels both freeze when switching to a different regular item that is NON-MW base like an HL2 weapon or something
็̶̠̌͋̕☠︎a̴s̷h̷ 11 月 10 日 下午 7:13 
this is cool and all but this makes my flashlight have a shadow for some reason
Rasmordem 11 月 9 日 上午 12:11 
@Evgeny Akabenko

Okay I did some troubleshooting and the issue I posted on your CSM addon I now believe is an issue with the GShader Library.

With debug mode on, the "_rt_WPDepth" and "_rt_NormalsTangents" windows will just stop updating and just freeze after a short while and never unfreeze. "_rt_Fog" seems to break also. Whenever this happens the shaders also break.

This was tested with only this, your CSM Shader, and your Volumetric lighting shader as the only addons enabled. It happens on regular branch and x86_64 branch. I tried lowering resolution and it still freezes.

Not sure why this is happening.
sweeteyes7 11 月 6 日 下午 6:13 
Okay I figured out that the thing causing the double body is Enhanced Camera 2, but the model is transparent for some reason even with EH2 off
OD_toast 11 月 6 日 下午 1:32 
are you going to make a parallax snow shader
Lambda 11 月 6 日 上午 10:50 
此留言正在等待我们的自动内容检查系统分析。在我们证实其内容无害之前(例如试图窃取信息的钓鱼站点链接),留言将暂时隐藏。