#[Archive] The Shader Hole

1 messages · Page 6 of 1

snow cradle
#

On his blog, Matt Pettineo writes about his experiments on cascaded shadow maps, including cascade optimization, shadow map filtering and GPU scene submission: A Sampling of Shadow Techniques. You might also be interested in... Variance Shadow Maps Shadow mapping is … Continue reading →

timid pumice
#

There's no way to autoreload shaders after compiling right?

snow cradle
timid pumice
#

What does this even means NOOOO
Failed to create shader '49D1F464'

timid pumice
#

yeah, this occurred after supplying a simple _vs30

#

thanks, found the problem happy_doge

snow cradle
timid pumice
#

in my custom mat i was supplying twice pixshader, but on the one that override it was using a vs

hardy acorn
wispy birch
timid pumice
#

Tried SetViewPort, SetScissorRect, CopyRenderTargetToTexture NOOOO

timid pumice
#
    local ow, oh = ScrW(), ScrH()
    render.PushRenderTarget(BLUR_RT)
    surface.SetMaterial(matfb)
    surface.SetDrawColor(color_white)
    surface.DrawTexturedRectUV(0, 0, ow, oh,
        x / ow, y / oh,
        (x + w) / ow, (y + h) / oh)
    render.PopRenderTarget()

    MATERIAL_SetMatrix(ROUNDED_BLUR_MAT, "$viewprojmat", matrix)
    MATERIAL_SetTexture(ROUNDED_BLUR_MAT, "$basetexture", BLUR_RT:GetName())

    surface.SetMaterial(ROUNDED_BLUR_MAT)
    surface.SetDrawColor(color_white)
    surface.DrawTexturedRectUV(x, y, w, h, -0.015, -0.015, 1.015, 1.015)

I hated it

stark valve
#

Guys, can anyone confirm that the game.MountGMA method to make a shader work on clients work? I've been trying this with no success whatsoever. It seems it will only work if the shader exists in the physical path

hybrid trench
#

nice balls

timid pumice
#

For some reason, it breaks autorefresh

stark valve
#

I fixed it

#

Apparently I compiled it wrong or smth

snow cradle
#

4 cascades CSM test using 1 shader

#

1 Global shadow matrix + float3 offsets + float scale

snow cradle
#

@wispy quartz Hello. can u check it on linux? These arguments are in the source engine. But some arguments are only for D3D9EX. And it is not known how Linux will react to these arguments.

funcs: render.PushFilterMag( number texFilterType ), render.PushFilterMin( number texFilterType )

    TEXFILTER.PYRAMIDALQUAD     = 6
    TEXFILTER.GAUSSIANQUAD         = 7
    TEXFILTER.CONVOLUTIONMONO     = 8             /* D3D9Ex only -- */
    TEXFILTER.FORCE_DWORD         = 0x7fffffff     // force 32-bit size enum
snow cradle
#

Shadow stabilization (ON)

misty surge
#

Much better. Although those cascades look a bit off, tbh. Might need to increase the sizes. Games also use a blur to blend that shimmering issue, it looks great so far, keep it up 🙂

#

Reminds me of my many years ago in vulkan making CSM

#

Although this sounds dumb, to stop the shimmering some games even use the player as the origin of all the orthos

#

So your like layering it out just using the player pos

rain marten
#

So... I was experimenting with a way to make a custom shader work on props. I wanted it to look like a emissive VertexLitGeneric in-game, without using any Lua script, and uh...

I just copied the necessary .h files source code from the source SDK, used their functions on my custom shader is the same way I saw them used on VertexLitGeneric, and it just... worked

Here's my old LCD shader, but modified to use the same CalcPixelFogFactor and FinalOutput functions that I saw being used on the source code for VertexLitGeneric:

#

Oh yeah, on the vertex shader, I also used (mostly) the same logic that VertexLitGeneric used so my custom shader could work on a map with fog & water

#

Although... "just worked" really only applies on getting the shader compiled, I still played around with every parameter on the .vmt file to see how it affected things. I did find out that $flags2 hack and $softwareskin were unnecessary.

#

Side note: the game REALLY did not like when I changed $vertexcolor, $vertexnormal or $vertextransform while it was running, it crashed almost every time

timid pumice
#

Amazing

snow cradle
#

for models

#

max 510-511

#

do u make output of sv depth?

rain marten
#

nope, just color

#

here, I wasnt planning on sharing so its a bit messy, but I think you guys can understand it better than I could

I've replaced the texture used for the screen (a RT showing bad apple) with the plastic texture. Also, remember that the shaders uses includes from the Source SDK

Oh and, curiously, the // STATIC/DYNAMIC commented lines at the top actually seem to declare some constants, given that it doesn't compile without them

snow cradle
snow cradle
#

3d drawing quad using cam3d on player's screen

local w,h = ScrW(),ScrH()
local aspect = w/h
local viewSetup = {}

local bias = 0.001

hook.Add("CalcView",  libName, function(ply, origin, angles, fov, znear, zfar)
    local f ,r, u = angles:Forward(), angles:Right(), angles:Up()
    local center = origin + f * znear

    local halfH = math.tan(math.rad(fov * 0.5)) * znear
    local halfW = halfH * aspect

    viewSetup.tl = center - r * halfW + u * halfH
    viewSetup.tr = center + r * halfW + u * halfH
    viewSetup.br = center + r * halfW - u * halfH
    viewSetup.bl = center - r * halfW - u * halfH
end)

function shaderlib.DrawVertexScreenQuad() // Drawing PP shaders with MRT and vertex shader inputs
    cam.Start3D()
        render.SetWriteDepthToDestAlpha( false )
        cam.IgnoreZ( true )
        render.DrawQuad( viewSetup.tl,viewSetup.tr,viewSetup.br,viewSetup.bl )
        cam.IgnoreZ( false )
        render.SetWriteDepthToDestAlpha( true )
    cam.End3D()
end
snow cradle
snow cradle
# snow cradle 3d drawing quad using cam3d on player's screen ```lua local w,h = ScrW(),ScrH()...

maybe using RenderScene is more stable then CalcView

hook.Add("RenderScene",libName,function(origin, angles, fov, p2)
    local viewSetup = render.GetViewSetup(true)
    local znear = viewSetup.znear

    local f ,r, u = angles:Forward(), angles:Right(), angles:Up()
    znear = znear + bias
    local center = origin + f * znear

    local halfH = math.tan(math.rad(fov * 0.5)) * znear
    local halfW = halfH * aspect

    quadVerts.tl = center - r * halfW + u * halfH
    quadVerts.tr = center + r * halfW + u * halfH
    quadVerts.br = center + r * halfW - u * halfH
    quadVerts.bl = center - r * halfW - u * halfH
end)
snow cradle
#

lol c10 EyePos works

#

but ambient cube is default color

#

like blue/dark blue etc

#

and render.AmbientCube input not works

#

values is steel blue

#

idk

#

why

snow cradle
sonic lynx
timid pumice
#

https://sharex.imgonzo.dev/f/uOhDzT2pf1.mp4
WHY

struct PS_INPUT {
    // texture coordinates
    float2 uv            : TEXCOORD0;
    // vertex color
    float4 color        : TEXCOORD1;
    // screenspace position
    float2 pos            : VPOS;
};

sampler TexBase : register(s0); // $basetexture RTBuffer
sampler Tex1    : register(s1); // $texture1 Grayscale mask

const float4 Constants0 : register(c0);
float TransitionProgress = 0.5; //Supposed to return c0_x 0-1 CurTime() % 1

float4 main(PS_INPUT i) : COLOR {
    float4 rgb = tex2D(TexBase, i.uv);
    float value = tex2D(Tex1, i.uv).r;

    if (value > TransitionProgress) {
        rgb.a = 1;
    }
    return rgb;
}
timid pumice
timid pumice
#

It was funny, i was sending the FB into the shader which not contains the viewmodel, still doesnt explains why it becomes less transparent when you get near walls

The solution was just to clear at 0,0,0,0 or the material im just passing

graceful lynx
#

The example code in that wiki page is bad and should be ignored

timid pumice
#

But boy, they really tax a lot

lunar sinew
#

i noticed the more fps you have, the more you loose if something is happening

timid pumice
lunar sinew
#

for example, if you normally get 1000+ fps idle but as soon as there is something happening like a battle or something taxxing, it reduces to like 600

but if you normally get like 100 fps, it only reduces by a bit

timid pumice
#

i remember 3kliksphilip did a nice video about that on latency/frame time

dusty linden
short dirge
#

looks fine from a discord thumbnail, but fullscreen seems a lil slow

#

like less "on fire" and more "extreme heat/volcano biome"

#

needs more chaos

#

1st ver was pretty ok, just lacking flashiness

#

i think its the speed of the pattern being scrolled being relatively faster there

snow cradle
#

For some users default vertex shader not works

#

make own default vertex shader for pp

#

not use $vertextransform 1 instead of $vertexshader

#

rx 580

icy plume
#

still looks cool tho not trying to be mean

stark valve
#

well you could obviously scroll a bunch of flame sprites on the screen but it wouldnt be nearly as cool

snow cradle
snow cradle
fickle ocean
#

smelly bot, i was saying this is all sorcery to me

graceful lynx
snow cradle
timber narwhal
#

would be epic to add some sort of upscaling to gmod

#

dlss/fsr3 is impossible but im sure you can port the really basic CAS algorithms from AMD and maybe FSR1

#

run gmod at 128x128 and upscale it to 1080p

#

peak fps

snow cradle
hollow pollen
timid pumice
#

So nerd but so right

timid pumice
#

also the shader would have it own impact too

leaden mesa
snow cradle
leaden mesa
#

ik

snow cradle
misty surge
#

Is that even gmod anymore? Obviously not. That’s unreal @snow cradle

wispy quartz
#

and how do i even compare them

snow cradle
snow cradle
#

bumps from framebuffer

#include "common_ps_fxc.h"

sampler FrameBuffer   : register( s0 );
const float strength : register( c0 );
float2 TexBaseSize : register( c4 );

struct PS_IN
{
    float2 P            : VPOS;
    float2 vTexCoord    : TEXCOORD0;
};

float3 CalculateBumpFromDepth(float2 uv)
{
    float3 depthRight   =   tex2D(FrameBuffer, uv + int2( 1, 0) * TexBaseSize ).rgb;
    float3 depthLeft    =   tex2D(FrameBuffer, uv + int2(-1, 0) * TexBaseSize ).rgb;
    float3 depthTop     =   tex2D(FrameBuffer, uv + int2( 0, 1) * TexBaseSize ).rgb;
    float3 depthBottom  =   tex2D(FrameBuffer, uv + int2( 0,-1) * TexBaseSize ).rgb;
    
    float gradientX = Luminance( depthRight - depthLeft ) * 0.5;
    float gradientY = Luminance( depthTop - depthBottom ) * 0.5;
    
    float3 normal = normalize(float3(-gradientX * strength, -gradientY * strength, 1.0)) * 0.5 + 0.5;
    normal.z = sqrt(max(0.0, 1.0 - normal.x * normal.x - normal.y * normal.y));

    return normal;
}

float4 main(PS_IN i ) : COLOR
{   
    float2 center = (i.P+0.5)*TexBaseSize;
    float3 bumps = CalculateBumpFromDepth(center);

    return float4(bumps, 1);
};

#

same bumps in tangent space (using TBN matrix from GShader lib)

#

Frenel of tangent space bumps

#

i need to fix edges

#

Luminance is comment function from #include "common_ps_fxc.h"

snow cradle
timid pumice
#

Is there any cool usage for screen bump or it’s a cool way to test dynamic bump generation from fb

#

I think once im done with 2d shaders, i will go with 3d, but doing shaders for me been feeling like taking stuff from other people math and steal it sad

jolly talon
#

That's like saying putting a wheel on a car is stealing the idea from the guy who invented the wheel

#

Everything in graphics that Ur gonna be able to do in sm3 has been done by someone else already, just read papers on stuff if you want to do anything

timid pumice
#

The entry field is always knowing about integrals, i barely passed that in university, but at least i can say my brain is more woke than back then in maths wise, but still the entry floor is really high toocool

graceful lynx
#

I bet it would work also as an effect to indicate "This player is cloaked, but you're on their team so you can still partially see them"

stark valve
#

maybbbbeee

timid pumice
stark valve
#

how do you mean

timid pumice
#

In 2D, you have the implementation like a screenspace object with DrawScreenQuad, but not sure how does it works for 3d

stark valve
#

oh yeah its a screenspace pixel shader just like usual

#

but on a model

#

i have a very very minimal vertex shader

dusty linden
#

very nice

#

I wonder if I could replicate it ingame using the current vertexlitgeneric shaders and mat variables

timid pumice
#

Iridiscense from ministrider tho

#

Although glasses from portal 2 really blew my mind with the broken reflection

short dirge
#

Isn’t that just a normal map

#

Or dudv?

#

P2 had the benefit of higher quality textures and higher poly models, having them able to separate normal islands without anyone seeing texel transition in between

dusty linden
#

Refract shader

#

iridescence could possibly also be envmapped

snow cradle
hollow pollen
#

why tf do you need 8 textures

fickle ocean
#

What if he needs 9 textures

jolly talon
#

Really not uncommon to need 8 textures for a shader

#

Think of a two plus way blend shader where each material wants diffuse normals etc

#

My terrain shader is limited to not allowing spec maps since both my channels need colour and heightmaps which already reaches the max of four, and I can luckily reconstruct normals from the heightmap

hollow pollen
#

use a texture atlas

#

ez

snow cradle
#

PBR:

  1. ColorMap
  2. BumpMap
  3. MRAO
  4. CubeMap
  5. LightMap (theory)
  6. Emissive
  7. Detailtexture
#

8 is a power of two. 6 may not be enough. 7 is not a power of two.

#

So we need 8 textures

#

We can ask for 6. But wouldn't it be better to ask for 8 right away? And we wouldn't ask for 5. Or 7. Those are odd numbers.

#

8 is with a reserve, so as not to return again to the question of the number of textures

snow cradle
#

For 4way blend we will need 9 textures

#

But I would stop at 8

snow cradle
snow cradle
#

For parallax it is not ez

snow cradle
#

Well, what's the result? I request:

  • texture4
  • texture5
  • texture6
  • texture7
  • c4
  • c5
#

We do this - we close the issue of textures and the issue of constants for input into the pixel shader

hollow pollen
#

wouldnt hurt perf that much, if at all if you used viewports

snow cradle
#

What are the downsides of having 8 textures?

hollow pollen
#

there arent im just guessing rubat isnt gonna touch it

jolly talon
misty surge
#

Texture atlas would work but they’re annoying to calibrate (since we have to recalculate the UVs, requiring more processing than say storing it in the vram for quick access.) The main issue of using all 8 would be that the shader’s vram may be too bespoke and cause performance issues with potentially calling those 8 textures at once, yet the advantage is that you’re not adding extra math to calculating the correct atlas for that one sampler. Either way, it’ll affect the process.

I’d prefer to have 8, with that option. And allow atlas texturing if you reach 8 as a limit.

#

Also, if I’m not mistaken we had 4 samplers only because some hardware back in 2013 didn’t support more than 4. Today, it’s more common to have full support of 8 rather than just 4 (default minimal)

#

And the vram on cards today would have basically negligible draw backs because usually we have more than 2gb vram in most common setups.

hollow pollen
#

uv offset calculations are negligible compared to a texture lookup

#

again tho not saying ur wrong, 8 would be better im just assuming rubat isnt gonna touch screenspace_general again

misty surge
#

I agree! I’m not always right. Lol but yeah I think ideally 8 is just cleaner

#

I wanted to push atlases for my planet shaders to allow more than 16 planets at once with one shader using the same concepts. I resorted to just using separate shaders per planet.

hollow pollen
#

ideally you also wouldnt sample 8 times per pixel

#

memory lookup is slow

#

especially on older cards

#
  • if you dont optimize for cache locality its even worse
snow cradle
#

Forward rendering requires a lot of textures.

misty surge
#

Having 8 would be great, 4 is definitely expensive as it is, but maybe having the choice would be nice, depending on what you’re making.

jovial tide
#

i dont think it makes sense to keep expanding screenspace_general, should make a new one that is tailored for flexibility

#

name it like CustomGeneric

hollow pollen
#

rubat?? adding something useful??

jovial tide
#

i mean just make the c++ code for it and send it to him, he will add it

#

i had one nearly done but i didnt finish adding flashlight support and morph weights

#

it supported everything else like variable mesh formats, skinning, fog, world lights, brush and model support, customizable pixel and vertex constants ($c and $v etc), 8 samplers, depthtesting, alphatesting

hollow pollen
#

oh neat

#

yeah world lights are definitely missing from screenspace_general

#

compile time constants might be nice as well

#

the // STATIC or // DYNAMIC stuff valve added

jovial tide
#

would need to be careful because that immediately opens a security hole

#

need to check if all the combo code is sanitized (hint: it wasnt, TF2 had some fixes for it recently)

hollow pollen
#

wasnt aware that was a security concern

#

interesting

snow cradle
#

I have such a goal for me. Screen space general will do. But I would like to add more textures

#

By the way, people have been waiting for you to make the custom shader you talked about for a long time.

#

But since the idea has died out, I can ask to improve the screen space general. Move in simple steps

snow cradle
# snow cradle

c4,c5 I can't offer it yet, because:

float2 TexBaseSize : register( c4 );
float2 Tex1Size    : register( c5 );
stark valve
#

do stencils fuck up screenspace shaders?

#

I'm having a damn hard time getting the same result for everyone

#

some people see white, other transparent, other see it fine

wispy birch
stark valve
#

losing my mind on a shader ive made a while ago, like i said its so fucking weird, at first I thought it was an AMD compat issue, then the way I package gmas and now its happening again

lunar folio
#

if you're compiling as ps3 try ps2. That was the only shader version I was able to get consistent results in with my players. Some people just could not see ps3 shaders at all (fully transparent).

stark valve
#

unfortunately I did just that and I'm not sure it helps

stark valve
#

transparent/fully white

snow cradle
#

tangent on models. result is same with$softwareskin 1 and with $softwareskin 0
this not works with $flags2 130. But works with $flags2 2 or $flags2 128

float3 outputNormal;
float4 outputTangent;
_DecompressUByte4NormalTangent( i.vNormalWS,outputNormal,outputTangent );
#

But without flags2 130 some models may be invisible

#

With flags 130 the normals become normalized

snow cradle
#

In short, I will ask for +2 textures on the screen space general. So that TexSize c8,c9 does not reach c10 - EyePos and does not disturb the order

#

I know how to add tangents for brushes. And you can add lightmaps, but it doesn't make much sense without flashlight support.

#

Adding 2 textures would be rational, but adding other features for direct rendering would not be entirely appropriate.

#

Just like adding the 7th and 8th texture will break the order of the registers c

snow cradle
#

Hello everyone! Please like the request on GitHub! ❤️❤️❤️ Requested from Rubat +2 additional textures for screenspace_general. This will allow using blending of conditional snow textures in deferred rendering, so that the surface looks more detailed, mixing several snow textures. Or it will help in creating shaders with multiple texture inputs.

This is the most rational request for additional textures, since they do not overlap registers and do not jump over them, preserving their logical sequence.
Thanks @misty dove for help!
https://github.com/Facepunch/garrysmod-requests/issues/2896

GitHub

Description I suggest adding the TEXTURE4 and TEXTURE5 for screenspace_general. The increased number of textures will allow texture blending in deferred rendering shaders. It will also make it easi...

jolly talon
hollow pollen
#

not saying ur wrong, 8 would be better. im just assuming rubat isnt gonna touch screenspace_general again

#

this is a valid, albeit annoying solution to the current problem

#

also you can still do wrapped sampling

#

assuming 4 atlas in a texture, like so:
[][]
[][]

might look something like this

// top left
float4 sample_uv00_wrapped(float2 pos) {
    return tex2D(BASETEXTURE, pos % 1.0 / 2.0);
}

// bottom right
float4 sample_uv11_wrapped(float2 pos) {
    return tex2D(BASETEXTURE, pos % 1.0 / 2.0 + 0.5);
}
jolly talon
#

Yea but it won't do blending between the values on opposite sides of the texture like normal

#

So there will be a seam of sorts

hollow pollen
#

yeah you'd need to do pointsampling or like you said add a "gutter"

jolly talon
#

For point sampling it would be fine but I'm using it for terrain shader so the textures do need to linear sample

#

And be tiled

hollow pollen
#

if you dont need to edit the texture in realtime you could make an animated vtf with 4 frames

#

then use a tex3D to sample the texture or "layer" you want

jolly talon
#

True that's an interesting idea

#

I guess with that you could actually send a crap ton of stuff into a shader

#

Makes me think how good it would be to get a way to send an array of vectors or something to the shader

#

Like I wanted to do foot steps affecting the parallax depth but id need a lot of data for lots of steps

snow cradle
wispy quartz
wispy quartz
stark valve
wispy quartz
#

i mean like all those 3d screenspace shit done with th eclouds

stark valve
#

🤔

surreal parcel
#

shader hole mole people when every corner isnt darkened

#

my favorite shader is fullbright

green forge
timber narwhal
#

looks cool but the video is super compressed i can barely see it

short dirge
#

That was compression? I thought that was temporal artifacting.

#

No, it probably still is.

timber narwhal
#

you can literally see the individual compression artifacts

graceful lynx
#

It's extremely compression artifacting

surreal parcel
stark valve
#

Brb making corruption shader

neat terrace
#

datamoshing

green forge
green forge
timber narwhal
#

still kinda eh. but i can see it much better now, looks sick

green forge
timber narwhal
#

looks nice, its so much better as an approximation of indirect occlusion

green forge
green forge
#

GTAO vs no gtao

timber narwhal
#

much nicer

green forge
#

This bot i swear

timber narwhal
#

gorgous

#

would be nice too if you could include normal mapping in the sampling

short dirge
#

Still can’t stand temporal artifacting when you’re moving slightly above walking pace

#

TSAA has the same issue though so

green forge
green forge
graceful lynx
green forge
graceful lynx
#

Oh great

stark valve
#

do you guys have any clever idea on how I could do a "projected" shader on map geometry?

#

I want to essentially display the world geometry in an area a particular way and blend its edge with whatever material the current geometry has

short dirge
#

so like, a decal/info_overlay

#

or are you referrring to a scope/fov vision box?

stark valve
snow cradle
#

using worldpos rendertarget

#

and model3x3 matrix

#

maybe u need make manual input of model matrix

snow cradle
#
local mModel = Matrix()
mModel:Identity()
mModel:Rotate(sticker:GetAngles())
mModel:SetTranslation(sticker:GetPos())
mModel:Invert()
mat:SetMatrix("$INVVIEWPROJMAT",mModel)
jolly talon
#

fullscreen pass for every decal 😭

snow cradle
#

this is box-model

jolly talon
#

oh I see clever

#

like the gta lamps

#

do you draw inside out box with no depth culling for it?

snow cradle
#

Use WorldPos

jolly talon
#

how to stop waste performance drawing decal through wall

#

but box mesh culls most waste yh

snow cradle
jolly talon
#

so where the box is on screen does calculation whether world pos is within box

snow cradle
#

You need 2 WorldPos - from rendertarget and from forward render box from vertex shader

#

Nothing complicated

jolly talon
#

alright ye, just wanted to know if a method to depth cull the decal box is possible

#

so if the decal is behind a wall it wont even draw a single pixel

#

i guess stencil but clearing and writing stencil for every decal is not good

snow cradle
#

How do you draw a decal in a pixel shader if you can't see it and it's behind the wall? It's impossible.

jolly talon
#

if you draw inside-out box for the decal projection it would draw through walls no?

snow cradle
#

You don't have a decal on your monitor. There is no decal on your monitor. The pixel shader doesn't work. The model is behind the wall. You can't see it.

jolly talon
#

you wont see it but the pixel shader will run i mean

snow cradle
snow cradle
#

A pixel shader can't calculate what it can't see.

jolly talon
#

I think you draw the inverted box with no depth to draw the projected decal to the screen using the depth buffer so if its behind a wall it will still do the world pos calculations?

#

idk maybe i misunderstand ur idea

snow cradle
#

I don't use depth buffer for screen space decals

#

i use _rt_WPDepth from GShader library and worldpos from vertex shader from box-model of decal

jolly talon
#

what if your camera enters the box

snow cradle
jolly talon
#

inverted box no?

snow cradle
#

Do

jolly talon
#

ooh, if camera is outside the box, draw as usual with depth, if its inside draw inverted i guess

#

When I did screenspace decals I did with purely inverted

#

Also spherical mapped and cylindrical mapped decals are fun

stark valve
snow cradle
#
RESHADE     = file.Exists("ReShade.ini", "EXECUTABLE_PATH")
DGVOODOO     = file.Exists("dgVoodoo.conf", "EXECUTABLE_PATH")
DXVK         = !DGVOODOO and !RESHADE and file.Exists("d3d9.dll", "EXECUTABLE_PATH")
#

vertex shader fog constanst not works for DXVK

snow cradle
#

Getting videocard name and vendorID if user has installed reshade

RESHADE     = file.Exists("ReShade.ini", "EXECUTABLE_PATH")
local vendorID = 0

VENDORID_NVIDIA = 0x10DE
VENDORID_ATI     = 0x1002
VENDORID_INTEL     = 0x8086

local vendors_id = {
    [VENDORID_NVIDIA]     = "NVIDIA";
    [VENDORID_ATI]         = "AMD";
    [VENDORID_INTEL]     = "INTEL";
}

local driverName = "UNKNOWN"

local function ReadReshadeGPU()
    local i = 0

    while true do
        local file_name = "ReShade.log"
        if i > 0 then file_name = file_name .. i end

        local log_reshade = file.Exists(file_name, "EXECUTABLE_PATH")

        if log_reshade then
            local log_text = file.Read( file_name, "EXECUTABLE_PATH" )
            local log_text_lower = string.lower(log_text)

            for id, vendor_name in pairs(vendors_id) do
                local finded, diver_start = string.find( log_text_lower, string.lower(vendor_name) )

                if finded then
                    vendorID = id
                    local end_test = string.find(log_text_lower, "driver", diver_start)
                    driverName = string.sub( log_text, finded, end_test-2 )
                    print("[GShader library] Found " .. driverName .. " driver")
                    break
                end
            end

            if vendorID != 0 then break end
        else
            if i != 0 then
                break
            end
        end

        i = i + 1
    end
end

if RESHADE then
    ReadReshadeGPU()
end

function system.GetVendorID()
    return vendorID
end

function system.GetVendor()
    return vendors_id[system.GetVendorID()] or "UNKNOWN"
end

function system.GetDriverName()
    return driverName
end
calm root
#

The irony, the reason crash dump can't be read and were blocked (when I reported it) is because they contain this and other private information

snow cradle
snow cradle
stark valve
#

poggers

#

on another note why cant we have system.SysInfo() that returns GPU vendor, etc...

snow cradle
#

It is also unknown how Intel will behave.

stark valve
#

who cares about intel lol

#

but yes

snow cradle
# stark valve who cares about intel lol

There is a risk group:

  • Linux
  • Proton
  • DXVK
  • DGVOODO
  • RX580
  • Intel

Proton has almost no chance of being detected, since it is considered gmod like Windows. It has DX95 (although Linux should have 92)

DXVK does not receive fog data from the vertex shader. It is difficult to detect (by exclusion) - d3d9.dll

I have already written about RX580.

If you ignore each group of players, then there will be a solid number of deprived people

stark valve
#

Thats not solid at all, together this isnt even 1% of all players

#

The only thing worth looking into in this list is proton

snow cradle
stark valve
#

Garry's Mod on Linux/macos is awfully broken, there are plenty of more pressing issues to address than this if you really want to go that way.

DXVK is very very niche, only developers would know where to get it and how to use it, same with DGVOODOO.

As for the RX580, that one defo deserves attention along with Proton.

And I've yet to see intel GPUs

#

I'm also not sold on the "divide people with %", thats how you prioritize. You can't sell a feature to rubat if you mention only the 1%

timber narwhal
hexed parrot
stark valve
#

oh

#

I didnt know proton uses that

#

in which case ok

snow cradle
#

How to detect water in frame?

wispy quartz
#

dxvk doesn't put d3d9.dll inside gmod's folder

wispy quartz
snow cradle
wispy quartz
#

it's contained under System32

snow cradle
#

btw reshade same has d3d9.dll

#

and it not needed to put it into system32 folder

vapid reef
snow cradle
#

hm ok

snow cradle
snow cradle
snow cradle
#

Getting bumps from FrameBuffer. I used the method for removing edge defects as in ACCURATE method reconstruction of Normals.
Due to using DX9 and the pixel shift problem, I had to shift by 1 pixel float depth_c = tex2D(WPDepth, (i.P - 1)*TexBaseSize ).a;.

float4 main(PS_IN i ) : COLOR
{   
    float2 vpos = i.vTexCoord;

    float2 ts1 = float2(1.0, 0.0) * TexBaseSize;
    float2 ts2 = float2(0.0, 2.0) * TexBaseSize;
    float2 ts3 = float2(0.0, 1.0) * TexBaseSize;
    float2 ts4 = float2(2.0, 0.0) * TexBaseSize;

    float3 colorRight   =   tex2D(FrameBuffer, vpos + ts1 ).rgb;
    float3 colorLeft    =   tex2D(FrameBuffer, vpos + float2(-1.0, 0.0) * TexBaseSize ).rgb;
    float3 colorTop     =   tex2D(FrameBuffer, vpos + ts3 ).rgb;
    float3 colorBottom  =   tex2D(FrameBuffer, vpos + float2( 0.0,-1.0) * TexBaseSize ).rgb;

    float depth_c = tex2D(WPDepth, (i.P - 1)*TexBaseSize ).a;

    float4 H = float4(
        tex2D(WPDepth,vpos - ts1).a,
        tex2D(WPDepth,vpos - ts4).a,
        tex2D(WPDepth,vpos + ts1).a,
        tex2D(WPDepth,vpos + ts4).a
    );

    //vertical depths
    float4 V = float4(
        tex2D(WPDepth,vpos - ts3).a,
        tex2D(WPDepth,vpos - ts2).a,
        tex2D(WPDepth,vpos + ts3).a,
        tex2D(WPDepth,vpos + ts2).a
    );

    //find diff of true center and extrapolated one
    float2 he = abs((2.0*H.xz - H.yw) - depth_c);
    float2 ve = abs((2.0*V.xz - V.yw) - depth_c);

    //from which direction to sample
    float gradientX = he.x+bias < he.y ? 0 : Luminance( colorRight - colorLeft );
    float gradientY = ve.x+bias < ve.y ? 0 : Luminance( colorTop - colorBottom );

    float3 normal = float3(gradientX * strength, gradientY * strength, 1.0);
    normal.z = sqrt(max(0.0, 1.0 - normal.x * normal.x - normal.y * normal.y));

    return float4(normal * 0.5 + 0.5, 1);
};
#
screenspace_general
{
    $pixshader         "pp_bumps_test38_ps30"
    $vertexshader     "pp_vs30"

    $basetexture         "_rt_FullFrameFB"
    $texture1         "_rt_WPDepth"

    $LINEARREAD_BASETEXTURE     1
    $linearwrite             1

    $c0_x 5
    $c1_x 0.000009 // bias

    "<dx90"
    {
        $no_draw 1
    }
}
#

idk but here i need small bias to remove depth deffect lol

#

btw i use depth=1/depth/4000 or depth=1/(depth*4000)

snow cradle
#

The essence of the method is to simply zero the bump in the edge zone. Edges can be defined in any way.

snow cradle
stark valve
#
                        pixel_mat:SetString("$pixshader", shader)
                        pixel_mat:Recompute()```

Can you not do that? It doesnt seem to work for me
#

pixel_mat is an IMaterial

wispy quartz
snow cradle
snow cradle
#

I think i can make support of 3d skybox for depthbuffer as pass where in depth == 1 make 3d sky depth render. depth from sky i will write using DepthWrite Shader. so i will save treesway support and alphatest. this pass can be optional. also i will render 3d sky as combined meshes (if mesh has no treesway and no sorted by alphatested texture). but it will requre NikNaks

snow cradle
snow cradle
#
function shaderlib.GetViewProjZ(viewData)
    if !ismatrix(viewData) then viewData = shaderlib.GetViewProjMatrix(viewData) end
    return Vector4(viewData:GetField( 3,1 ),viewData:GetField( 3,2 ),viewData:GetField( 3,3 ),viewData:GetField( 3,4 ) )
end
#

getting ViewProjZ from VIewProj matrix

#

fog calculation:

float flProjPosZ = dot( float4(1/tex2D(WPDepthBuffer,i.vTexCoord).xyz,1), ViewProjZ );
float3 fogParams = i.fogParams;
float fog = max( fogParams.z, ( flProjPosZ * fogParams.y + fogParams.x ) );
fog = pow(fog,fog_power);
blazing mason
#

let's say I have an entity that is essentially a prop, I then set the material of that entity to a vmt that uses screenspace_general, with all the proper flags so it shows up on a model correctly
let's say I also use the custom inputs, in this example, just $c0_x
if in the entity's lua, I change $c0_x, does it change it for every instance of the material? or just the specific entity

#

if it's every instance of the material I think what I'm trying to do is impossible then

#

looks like its for every instance based on testing with my current implementation....

#

shared.lua

ENT.Type = "anim"
ENT.Base = "base_anim"
ENT.Category = "Test"
ENT.PrintName = "Test"
ENT.Spawnable = true
ENT.Mat = Material("gmod_shader_guide/test.vmt")
ENT.Index = 0
ENT.AutomaticFrameAdvance = true

function ENT:Think()
  self.Mat:SetFloat("$c0_x", self:GetNWInt("test1"))
end

function ENT:Use( activator )
  self.Index = self.Index+1
  self:SetNWInt("test1", self.Index)
  print(self:GetNWInt("test1"))
end

function ENT:Initialize()
  self:SetModel( "models/test/cube.mdl" )
  self:SetMaterial(self.Mat:GetName())
  self:PhysicsInit(SOLID_VPHYSICS)
  self:SetMoveType(MOVETYPE_VPHYSICS)
  self:SetSolid(SOLID_VPHYSICS)
  if SERVER then
    self:SetUseType(SIMPLE_USE)
  end
  self:Activate()
end

test.vmt

screenspace_general 
{
  $pixshader "test_ps20b"
  $vertexshader "test_vs20"
  $basetexture "gmod_shader_guide/al_child"
  $texture1 "gmod_shader_guide/al_child_palette"
  $POINTSAMPLE_TEXTURE1 1
  $POINTSAMPLE_TEXTURE2 1
  $c0_x 0
  $cull 1
  $depthtest 1
  $model 1
  $softwareskin 1
  $vertexnormal 1
  $linearwrite 1
}

essentially in the shader I am changing the color of the material based on c0_x

#

spwaning multiple instances of the entity, they all are the same color as the most recently spawned one, ignoring their own index variable, presumably because the custom shader does not instance itself per instance of the material?

blazing mason
#

I had assumed because I'm creating an IMaterial object for each entity by doing ENT.Mat = Material("gmod_shader_guide/test.vmt"), that it was creating multiple instances of each material. Which it's probably doing, but all those material use the same shader, which doesn't instance itself?

blazing mason
#

nevermind, just tried creating a material on the fly, an instance for each and that solution works.
so I think it's a matter of I'm somehow using ENT:SetMaterial() incorrectly with Material()?

#

currently using CreateMaterial(), but won't work long-term for what I'm trying to do, so its not ideal over having a .vmt that i reference with Material()

hollow pollen
#

if you want multiple entities with the same shader that have different material values, you will need multiple materials

#

Material() just references an existing one

#

so your only option in this regard is CreateMaterial

stark valve
snow cradle
#

perspective matrix:

float4 offset = float4(samplePos, 1.0);
//offset = mul(offset,g_ProjMatrix);
offset.x = samplePos.x*ViewProjX.x+samplePos.y*ViewProjX.y+ViewProjX.w;
offset.y = samplePos.x*ViewProjY.x+samplePos.y*ViewProjY.y+samplePos.z*ViewProjY.z+ViewProjY.w;
float raw_z = samplePos.x*ViewProjZ.x+samplePos.y*ViewProjZ.y+samplePos.z*ViewProjZ.z;
offset.z = raw_z+ViewProjZ.w;
offset.w = -raw_z+ViewProjW.w;
[0.34870,    0.52388,    0.00000,    -2429.19531]
[0.12408,    -0.08259,    -1.10883,    76.26141]
[0.82504,    -0.54915,    0.13322,    -560.02454]
[-0.82504,    0.54915,    -0.13322,    561.02454]

ViewProjZ.xyz == -ViewProjW.xyz only .w is different

#

getting only projPos.xy:

float2 shadowCoord;
shadowCoord.x = wp_offset.x*ViewProjX.x+wp_offset.y*ViewProjX.y+ViewProjX.w;
shadowCoord.y = wp_offset.x*ViewProjY.x+wp_offset.y*ViewProjY.y+wp_offset.z*ViewProjY.z+ViewProjY.w;
snow cradle
#

But having 2 digits, we can make ProjPosZ out of it

#

default way to get ProjPosZ:

float flProjPosZ = dot( float4(worldPos,1), ViewProjZ );
#

This is useful to calculate the fog in the shader and reduce the effect of the shader on the fog.

#

Making Fog using ResolvedFullFrameDepth:

float4 main(PS_IN i ) : COLOR
{   
    float projPosW = tex2D(ResolvedFullFrameDepth, i.vTexCoord)*4000;
    float raw_z = projPosW-ViewProjW.w;
    float flProjPosZ = -raw_z+ViewProjZ.w;
    float3 fogParams = i.fogParams;
    float fog = max( fogParams.z, ( flProjPosZ * fogParams.y + fogParams.x ) );
    fog = pow(fog,fog_power);
    return float4(fog,fog,fog,1);
};
snow cradle
#

Fog works:

mat_fog:SetFloat("$c3_x", viewProj:GetField(4,4))
mat_fog:SetFloat("$c3_y", viewProj:GetField(3,4))
#

or u can get ProjPosZ from ProjPosW using precomputed value:

-- lua
mat_fog:SetFloat("$c3_x", viewProj:GetField(4,4) + viewProj:GetField(3,4))
// hlsl
float flProjPosZ = W_X - tex2D(ResolvedFullFrameDepth, i.vTexCoord).a*4000;
#

but viewProj:GetField(4,4) + viewProj:GetField(3,4) == 1

#

so ViewProjZ == 1 - ViewProjW

snow cradle
#

Final version:

float4 offset = float4(samplePos, 1.0);
offset.x = samplePos.x*ViewProjX.x+samplePos.y*ViewProjX.y+ViewProjX.w;
offset.y = samplePos.x*ViewProjY.x+samplePos.y*ViewProjY.y+samplePos.z*ViewProjY.z+ViewProjY.w;
offset.z = samplePos.x*ViewProjZ.x+samplePos.y*ViewProjZ.y+samplePos.z*ViewProjZ.z+ViewProjZ.w;
offset.w = 1-offset.z;
#

Thus, in any layout - both in the ortho projection and in the perspective projection - the last row is not used, so the matrix can be transmitted as float4x3, and not float4x4 - during manual calculation.
That is, the last row of the matrix can be left for any data you want.

vague jetty
#

Did you ever solve this? I'm having issues with the same thing. My shader rendering code that worked a long time ago no longer works, presumably from an update. I'm able to make it work with this code:

    local shader = Material("effects/shaders/testshader")

    hook.Add("RenderScreenspaceEffects", "MyScreenOverlay", function()
        cam.Start2D()
            surface.SetMaterial(shader)
            surface.SetDrawColor(255, 255, 255, 255)
            surface.DrawTexturedRectUV( -1, -1, 2, 2, 0, 1, 1, 0 )
        cam.End2D()
    end)```
And it works with r_screenoverlay, but my old code does not work and instead draws incorrectly on the top right quad.
```lua
    local shader = Material("effects/shaders/testshader")

    hook.Add("PostDrawTranslucentRenderables", "TranslucentTextDisplay", function()
        render.UpdateScreenEffectTexture()
        render.SetMaterial(shader)
        render.DrawScreenQuad()
    end)```

I'm trying to render it in PostDrawTranslucentRenderables so I can render certain UI elements properly.
snow cradle
#

Sponza map ft. СЛон for shader dev and tests

snow cradle
#

@wispy quartz IA88 is works good for u? (for linux)

#

linux user screen:

#

he have colors in IA88 lol

#

R32F looks like red for linux

#

@wispy quartz
Is your R32F not working? As far as I remember.

#

lua say: dx90
mat_dxlevel say: dx92

wispy birch
wispy birch
# snow cradle wtf

mat_dxlevel might just be the target, that might not be available at all times

wispy birch
# snow cradle how?

windows subsystem for linux
officially supported linux under windows (if you run win11 you have graphics by default)

#

google the installation process if you want it

snow cradle
#

Because, for example, I don’t understand how the colors were preserved in IA88

#

And I wonder what could be connected with this.

stark valve
#

I do remember spending quite a long time trying to setup gmod for it

#

And it didn’t even work

blazing mason
#

... is there any way to get flex/morph data using screenspace_general? or am I shit outta luck

misty surge
#

Not really, unless you make the bone tree yourself somehow, and include bone weights, at that point you might as well use VertexLitGeneric because this is supported, but screen space is limited to screenspace mainly. There’s only reconstruction available because 3D geometry isn’t processed the way a 2D shader is. Screenspace uses your screen to make shaders, when the ideal way for 3D is to include skins in the render call which refers to the bone tree.

#

A mesh you produce outside the screen space meaning you can inject your mesh data, it’s possible to make somewhat of a replacement, but it won’t work without properly distributing weights and bone IDs, which is called in a normal draw model, but not in screen space.

blazing mason
#

yeah I ended up having to go with a workaround

snow cradle
#

no $flags2, no $softwareskin, #define COMPRESSED_VERTS 1

timid pumice
#

That's fucking huge

stark valve
#

not sure what tangents/binormals mean in this context

snow cradle
#

I don't have a ready-made parallax shader, but I know a working way to get tangents and binormals, and I've uploaded it.

stark valve
#

its very nice

snow cradle
#

btw i try to add flashlight support. now i add fog support, 6face lighting. and now i calc matrix of flash on lua (3st steen my wip test)

#

we can add flashlight support using only 1 texture and some data

#

with no NoiseSampler (shadows disable)

#

at final screespace general can get light, fog, depth, flashlight support but only for dynamic ents (to get info from lua)

#

we can make 2-3 lighting support for bumps and spec

misty surge
snow cradle
snow cradle
graceful lynx
nocturne patio
#

Does anyone know how to pass the intensity of lights around the mesh to the shader?
I'm trying to draw a model with basic lighting to make it look just like VertexLitGeneric.

My current setup is as follows:
I tried to use render.GetLightColor but it brightens up all the surface uniformly like the screenshot below.

// Pixel shader
sampler Albedo : register(s0); // $basetexture
const float4 c0 : register(c0);
struct PS_INPUT {
    float2 pos : VPOS;
    float2 uv  : TEXCOORD0;
};
float4 main(const PS_INPUT i) : COLOR0 {
    float4 albedo = tex2D(Albedo, i.uv);
    return c0 * albedo;
}
// Vertex shader
const float4x4 cModelViewProj : register(c4);
struct VS_INPUT {
    float4 pos    : POSITION0;
    float2 uv     : TEXCOORD0;
    float3 normal : NORMAL0;
};
struct VS_OUTPUT {
    float4 pos : POSITION;
    float2 uv  : TEXCOORD0;
};
VS_OUTPUT main(const VS_INPUT v) {
    VS_OUTPUT output;
    output.pos = mul(v.pos, cModelViewProj);
    output.uv = v.uv;
    return output;
}
"Screenspace_General"
{
    "$pixshader"    "pixelshader"
    "$vertexshader" "vertexshader"
    "$basetexture"  "uvtest"

    "$cull"         "1"
    "$depthtest"    "1"
    "$model"        "1"
    "$softwareskin" "1"
    "$vertexnormal" "1"
}
local mdl = ClientsideModel "models/props_junk/CinderBlock01a.mdl"
mdl.RenderOverride = function(self)
    render.OverrideDepthEnable(true, true)
    self:DrawModel()
    render.OverrideDepthEnable(false)
end
local mat = Material "myshader_vmt"
local light = render.GetLightColor(mdl:GetPos())
mat:SetFloat("$c0_x", light.x)
mat:SetFloat("$c0_y", light.y)
mat:SetFloat("$c0_z", light.z)
mat:SetFloat("$c0_w", 1)
wispy birch
#

you should have this from the engine from the start

wispy birch
nocturne patio
#

thanks, I'll try

hollow pollen
#

ideally source would set the lights up for you but I’m unsure if thats the case

nocturne patio
# hollow pollen render.setlocalmodellights, then you can use the `cLightInfo` array in the verte...

Interesting!

but I set the first light's dir to Vector(1, 1, 1) but it seems I'm getting (1, 0, 0) in the pixel shader.

// Vertex shader
#include "common_vs_fxc.h"
struct VS_INPUT {
    float4 pos    : POSITION0;
    float2 uv     : TEXCOORD0;
    float3 normal : NORMAL0;
};
struct VS_OUTPUT {
    float4 pos   : POSITION;
    float2 uv    : TEXCOORD0;
    float4 light : COLOR0;
};
VS_OUTPUT main(const VS_INPUT v) {
    VS_OUTPUT output;
    output.pos = mul(v.pos, cModelViewProj);
    output.uv = v.uv;
    output.light = float4(cLightInfo[0].dir.xyz, 1.0);
    return output;
}
// Pixel shader
float4 main(const PS_INPUT i) : COLOR0 {
    return tex2D(Albedo, i.uv); * float4(i.light.rgb, 1.0);
}
local function RenderOverride(self)
    render.SetLocalModelLights({
        {
            pos = self:GetPos() - Vector(50, 50, 50),
            dir = Vector(1, 1, 1),
            color = Vector(1, 1, 0),
            type = MATERIAL_LIGHT_DIRECTIONAL,
        }
    })
    render.OverrideDepthEnable(true, true)
    self:DrawModel()
    render.OverrideDepthEnable(false)
end
hollow pollen
#

you will need to use render.supressenginelighting to prevent source from internally overriding those values

nocturne patio
nocturne patio
#

Drawing VertexLitGeneric once fixed the problem with cAmbientCubeX/Y/Z 🤗

local function RenderOverride(self)
    render.SuppressEngineLighting(true)
    render.OverrideDepthEnable(true, true)
    local rainbow = HSVToColor(CurTime() * 120 % 360, 1, 1):ToVector()
    local dummy = Material "metal2"
    render.SetModelLighting(BOX_FRONT, rainbow:Unpack())
    render.SetModelLighting(BOX_LEFT, Color(255, 0, 0):ToVector():Unpack())
    render.SetModelLighting(BOX_TOP, Color(0, 255, 255):ToVector():Unpack())
    render.MaterialOverride(dummy)
    self:DrawModel()
    render.MaterialOverride()
    self:DrawModel()
    render.OverrideDepthEnable(false)
    render.SuppressEngineLighting(false)
end
// Vertex shader
#include "common_vs_fxc.h"
struct VS_INPUT;
struct VS_OUTPUT; // same as above
VS_OUTPUT main(const VS_INPUT v) {
    VS_OUTPUT output;
    output.pos = mul(v.pos, cModelViewProj);
    output.uv = v.uv;
    output.light = AmbientLight(v.normal);
    return output;
}
wispy birch
nocturne patio
#

Honestly I don't want to draw a model twice but I guess this is the best bet for now.

nocturne patio
#

It turned out that I can use DoLighting if I draw VertexLitGeneric once

local function RenderOverride(self)
    render.MaterialOverride(vertexlitgeneric)
    render.SetBlend(0) -- Do not actually render
    self:DrawModel()
    render.SetBlend(1)
    render.MaterialOverride()
    render.OverrideDepthEnable(true, true)
    self:DrawModel()
    render.OverrideDepthEnable(false)
end
// Vertex shader
#include "common_vs_fxc.h"
struct VS_INPUT;
struct VS_OUTPUT; // same as above
VS_OUTPUT main(const VS_INPUT v) {
    VS_OUTPUT output;
    output.pos = mul(v.pos, cModelViewProj);
    output.uv = v.uv;
    output.light = DoLighting(v.pos, v.normal,
        float4(0.0, 0.0, 0.0, 0.0), true, true, true);
    return output;
}
snow cradle
#

@nocturne patio

shaderlib.BuildPerspectiveWorldToFlashlightMatrix is afloat4x4 g_FlashlightWorldToTexture:

function shaderlib.BuildWorldToShadowMatrix(translation, ang) // View Flashlight
    local vForward = ang:Forward()
    local vLeft = ang:Right()
    local vUp = ang:Up()
    
    local matBasis = Matrix()
    matBasis:SetForward(vLeft)
    matBasis:SetRight(vUp)
    matBasis:SetUp(vForward)
    local matWorldToShadow = matBasis:GetTransposed()

    translation = matWorldToShadow * translation
    translation = -translation

    matWorldToShadow:SetTranslation(translation)

    matWorldToShadow:SetField(4,1,0)
    matWorldToShadow:SetField(4,2,0)
    matWorldToShadow:SetField(4,3,0)
    matWorldToShadow:SetField(4,4,1)

    return matWorldToShadow
end


function math.cot(x) // cotangent
    return 1 / math.tan(x)
end

function shaderlib.BuildPerspectiveWorldToFlashlightMatrix(viewSetup) // ViewProj for Flashlight g_FlashlightWorldToTexture
    local pos, ang = viewSetup.origin, viewSetup.angles
    local mFlashlightView = shaderlib.BuildWorldToShadowMatrix(pos, ang)

    local fov = viewSetup.fov
    fov = math.cot( math.rad(fov * 0.5)  )
    local f = viewSetup.zfar
    local n = viewSetup.znear
    local aspect = viewSetup.aspect or 1

    local mProj = Matrix({
        {    fov,  0,            -0.5,              0,            },
        {    0,  fov*aspect,        -0.5,              0,            },
        {    0,     0,                1,                 1,            },
        {    0,  0,                -1,             0            }
    })

    mProj:Mul(mFlashlightView)

    return mProj
end
#

sampler FlashlightSampler           : register(s3);

const float4x4 g_FlashlightWorldToTexture : register( c15 );
#define FLASHLIGHT bool(Constants0.w > 0)
#define g_FlashlightPos EyePosition
#define m_fConstantAtten 0
#define m_fLinearAtten 100
#define m_fQuadraticAtten 0
#define m_FarZ 750
#define g_FlashlightAttenuationFactors float4(m_fConstantAtten, m_fLinearAtten, m_fQuadraticAtten, m_FarZ)

#define bDoShadows          false   // need RandRotSampler
#define bAllowHighQuality   false
#define bClip               false
#define nShadowLevel        int(0)

// code
if (FLASHLIGHT) {
    float4 flashlightSpacePosition = mul( float4( worldPos, 1.0f ), g_FlashlightWorldToTexture );

    diffuseLighting += DoFlashlight( g_FlashlightPos, worldPos, flashlightSpacePosition, worldNormal,
    g_FlashlightAttenuationFactors.xyz,
        g_FlashlightAttenuationFactors.w, FlashlightSampler, FlashlightSampler, // 
        FlashlightSampler, // RandRotSampler
        nShadowLevel, bDoShadows, bAllowHighQuality, i.pPos, bClip);

    pixLight += diffuseLighting;
}
#

vmt:

$texture3             "effects\flashlight001"  // FlashlightSampler
#

default view matrix +- same as flashlight view matrix

#

they have very minor differences

#

I mean in terms of the result

#
local viewSetup = render.GetViewSetup()
viewSetup.aspect = 1
viewSetup.fov = GetConVar("r_flashlightfov"):GetFloat()
flashlightMatrix = shaderlib.BuildPerspectiveWorldToFlashlightMatrix(viewSetup)
#

this is g_FlashlightAttenuationFactors. but i hardcode it. i have no free constants

local atten = Vector4(
    GetConVar("r_flashlightconstant"):GetFloat(),        // Set the flashlight attenuation factors
    GetConVar("r_flashlightlinear"):GetFloat(),
    GetConVar("r_flashlightquadratic"):GetFloat(),
    GetConVar("r_flashlightfar"):GetFloat()
)
#

This is in case you want to make a game-ready shader.

#

This will be useful to you

wispy quartz
#

well, a directx alias

wispy quartz
#

There's no any particular reason to actually do any of that since vram size have changed from 256-512mb up to 16gb

#

even low end video cards have minimum 4gb of video memory, that's really huge for gmod

snow cradle
#

No matter how long I've been here, I constantly hear destructive comments:

  1. "Linux? Who the hell uses Linux? Just cut off their support, that's all. They only play on Windows."
  2. "IA88? What kind of format is that? Increase the video memory consumption, that's all."

We need to think about all users—Linux users, weaker PCs. Everything. We can't ignore it. Nothing. Your idea is negligent.

#

With your thoughtless actions, you are weeding out players due to your recklessness.

snow cradle
#
GitHub

I propose adding $basetexturetranform support for DepthWrite shader. This shader uses render.GetResolvedFullFrameDepth It's good and supports $treesway, but some map developers use $basetexture...

wispy quartz
#

You trying to squeze extra 2 megabytes in vram is dumb considering the amount of vram you consumed already via your extensive usage of deffered rendering technique, not talking about the sttuff that you used multiple render passes to do stuff that could be done in forward rendering

#

that was a silly attempt to gaslight me dude

snow cradle
# wispy quartz You trying to squeze extra 2 megabytes in vram is dumb considering the amount of...

Deferred rendering render targets consume a significant amount of video memory.

worldpos + depth = 32323232F bits, despite the fact that a separate R32F depth buffer already exists.

World normals can be stored in either RGBA16F or RGBA32F. They could also, in theory, be stored as RGBA8 (alpha channel - sign of tangents).
Also for Worldnormals IMAGE_FORMAT_RGBA1010102 would be nice, but it is not available to us.

But I don't use multiple render passes, that is, I don't call any render.RenderView, but reconstruct the data from the depth buffer.
Btw, if it is possible to use IA88 and I8 for other purposes, then there is no point in abandoning them.

#

You don't determine where the necessary video memory consumption is and where it's negligence.

wispy quartz
snow cradle
wispy quartz
#

There's no reason to overoptimize some unesufficient stuff since the way you do your unreasoned shading methods are already unoptimized

#

"wow my stuff needs 8mb of vram!!! But it requires rtx 5090 to actually compute my screenspace shadows!"

#

that's how you sound

#

like

wispy quartz
#

and that's minimal system specs required for gmod

snow cradle
# wispy quartz Yes i do determine it, since system specs of gmod did already increase

1080p:

WorldPos + depth.a rgba32f: 32,4m
resolved full frame buffer 32f: 8,1m
WorldNormals+Tangent - Saving method: ||8 bit 8,1m||/16 bit 16.2m/32 bit 32,4m

It would be nice to make WorldPos as IMAGE_FORMAT_RGB323232F = 28 (3 layers), without adding depth buffer to alpha channel, to save video memory, but this image format is not available to us.
Also i haven't made 8-bit normals yet, but I have plans to implement it. Because it is important to save video memory.

So, ideally (from the point of view of video memory), I would do it like this:

WorldPos: IMAGE_FORMAT_RGB323232F
Depth: IMAGE_FORMAT_RGB32F
NormalsTangents: IMAGE_FORMAT_RGBA1010102

But the only render targets that allow me to save any video memory are IA88 and I8 in specific cases. And they should be used if possible.

wispy quartz
#

and your worldpos/depth stuff is actually 256mb

wispy quartz
# snow cradle

you do realise that 32 bit * 4 * 1920 * 1080 is not 32mb

#

same stuff for your normals, its 128mb not 32mb too

snow cradle
#

I can also mention the importance of saving video memory in an article by MJP, Lead Rendering Programmer at Sony Santa Monica Studio, where he discusses the attitude of video game developers and video memory consumption:

https://mynameismjp.wordpress.com/2015/02/18/shadow-sample-update/
The paper primarily suggests two variants of the technique: one that directly stores the 1st, 2nd, 3rd, and 4th moments in an RGBA32_FLOAT texture, and another that uses an optimized quantization scheme (which essentially boils down to a 4×4 matrix transform) in order to use an RGBA16_UNORM texture instead. The first option most likely isn’t immediately interesting for people working on games, since 128 bits per texel requires quite a bit of memory storage and bandwidth.

MJP

You can find an ad-free static site version of this post here: Update 1/24/2016: one of the authors of the Moment Shadow Mapping paper contacted to let me know that there was an issue in my impleme…

wispy quartz
#

your level is literally ps3 graphics, same for effects

#

the issue they had with so huge vram usage is that they used pbr + higher res textures for almost everything

#

(Still not talking that gmod's recommended vram is 4gb, 2 times higher than that)

hollow pollen
#

AAA gamedev over here

wispy quartz
wispy quartz
hollow pollen
#

fair enough wtf is that format

wispy quartz
#

IA8 also holds alpha channel, but i don't think squezing anything of that cuz of 1 rt is like a huge need to actually hack around that to support linux / ditch linux cuz of that (including proton/dxvk)

hollow pollen
#

tbf this kind of thing happens all the time, he can just have different pipelines for different systems

#

if (windows) {I8} else {RGBA8888}

wispy quartz
#

since there's already more huge bottlenecks in akabenko's shaders, such as tflops/fillrate limitations for gpus
So it's not really supporting so budget gpus (like 560ti/etc) with low vram available since they couldn't really handle shadowmaps/volumetric lighting with descent fps

#

It's just decreasing vram usage for almost no reason

wispy quartz
#

well, as well as windows users with dxvk applied

hollow pollen
#

but youre probably right for his cases

wispy quartz
hollow pollen
#

is it? if hes doing CSM and stuff thats multiple texture lookups per pixel

wispy quartz
#

not VRAM usage.
The fps with like 100mb of vram usage will be around the same as with 10gb vram usage basically (if gpu has 10gb of memory, of course)

wispy quartz
hollow pollen
#

oh yeah if hes using that F32 depth reconstruction that’d kill any old gpu

wispy quartz
wispy quartz
hollow pollen
#

could maybe precompute the direction in the vertex shader but you’d still need that texture lookup

hollow pollen
#

ya

wispy quartz
#

it will have so tricky optimizations by gpu, but still

wispy quartz
#

system specs of gmod is huge

#

a lot of space for modders

#

and shaders

#

to not care about additional 8mb of vram memory

hollow pollen
#

its mostly about optimizing those texture lookups

#

a GPU cache is like 128kb or something

#

big performance difference between sampling a higher res texture and lower res

#

I presume same goes for RGBA8888 and I8

#

~3x less “compute”

wispy quartz
#

(just use new assets/maps with your own shaders, that's all)\

#

waiting for CustomGeneric from ficool2 / Material:SetShader return

hollow pollen
#

i wouldnt hold ur breath

#

lol

wispy quartz
#

nah i'd still do my stuff with screenspace_generic stuff, i don't really think doing that all work with post processing stuff would really make such a difference vs doing that shit with remade assets + replacing default shaders to custom ones

#

Like ditching all source lighting and baking it into textures myself, like that guy did with blender
https://www.youtube.com/watch?v=so1TWKkfhXQ

Tried to test my map in HL1, using my 2002 laptop as benchmark!
Download link for HL1 map (for those who doesn't believe that is GoldSrc): https://drive.google.com/file/d/1_PHGYpIu_annAQr_TI_JTgKwrqje17gk/view?usp=sharing

Laptop specs:
Motherboard - ECS Elitegroup G730, Intel i845 chipset
CPU - Pentium 4 Northwood, 1 core 1 thread, 2 ghz
GPU - ...

▶ Play video
#

That will really result in good looking graphics in gmod, i think

hollow pollen
#

holy crap lol

#

clean as hell

wispy quartz
#

I mean, it's just people didn't use this custom shit since it requires baking that into models, etc

hollow pollen
#

right

wispy quartz
#

and therefore you have to ditch brushes (only use them for pvs/collision, etc)

#

and use models

#

well, basically it's possible to bake all that shit into brushes

#

just will need custom compiler toolkit

#

custom shaders for brushes

#

etc

wispy quartz
#

but that's made mainly for other reasons

hollow pollen
#

¯_(ツ)_/¯

wispy quartz
wispy quartz
#

and w/e akabenko is doing rn

hollow pollen
#

source is old as hell

#

I think the bad graphics give it charm

#

if you wanted “realism” you had reshade for that

wispy quartz
hollow pollen
#

what akabenko is doing is cool though

#

im not gonna stop him from doing a personal project

wispy quartz
placid stream
#

I'm not even sure if most GPUs natively support I8 or IA8, they might just end up getting converted to something like BGR888 or BGRA8888 when they reach the GPU

wispy quartz
#

how can i do that lol

#

🤔

hollow pollen
#

by not playing it

wispy quartz
#

i still do it but gmod is not dead yet

#

what to do then

hollow pollen
#

make a better sandbox game

wispy quartz
#

i'll call it roblox

#

still people play gmod for w/e reason

#

🙁

hollow pollen
#

gmod isnt run by pedos

timber narwhal
wispy quartz
#

GMOD 1942 RP

hollow pollen
#

lol

wispy quartz
#

with minors... you know what minors i mean

wispy quartz
#

like made a statement

#

no nazi

#

no nsfw

#

etc

wispy quartz
snow cradle
#

extremism

wispy quartz
#

idk how but that's funny

timber narwhal
snow cradle
#

how to use D16 SHADOWS D32 INTZ D24X8 image formats?

snow cradle
#

and why RGBA1010102 has shader api error?

calm root
graceful lynx
misty surge
#

If we are the shader hole, where is water?

calm root
#

in his bio (/s)

jovial tide
#

good news: ive been researching the depth buffer situation, because im making something and this has become an obstacle

#

it should be possible to fetch the hardware depth buffer, without ever having to draw a depth pass

#

if i get it working (and test that it works on amd + nvidia + intel), i'll forward the details to rubat

wispy quartz
jovial tide
#

stencil should also be fetchable

#

i wont test this though as i dont need it

jovial tide
#

stencil will not work if MSAA is enabled

jovial tide
#

no

timber narwhal
#

cool

jovial tide
#

INTZ doesnt work with MSAA

#

this is RESZ

timber narwhal
#

aahhh ok

jovial tide
#

with an asterisk, because nvidia needs a hack

timber narwhal
#

last time i tried intz it was really buggy on msaa like you said

#

sweet

jovial tide
#

no

wispy quartz
#

thanks for clarification though

timber narwhal
#

taa ❤️

wispy quartz
#

at least without notice

jovial tide
#

it may end up being better (or worse) in practice

wispy quartz
graceful lynx
#

[Archve] The Shader Hole

heavy blade
#

R.I.P

rain marten
fickle ocean
#

why

vapid reef
#

@graceful lynx Archve

fickle ocean
#

oh the new channel was hidden okay yea

wispy birch
#

archve 🗣️

graceful lynx
#

I do not have the ability to archive the thread

vapid reef
timid pumice
#

you cannot name it archive as it dissapears due Peacekeeper, you guys should do your homework

lunar sinew
#

archyve

graceful lynx
#

[Archive] The Shader Hole

timber narwhal
#

now we can say goodbye to this thread

graceful lynx
#

🫡

surreal parcel
#

I feel like being the last poster here 🦹🏻‍♂️

stark valve
#

too bad