#[Archive] The Shader Hole

1 messages · Page 3 of 1

wispy quartz
#

This is literally the same stuff

graceful lynx
#

For water stuff? No, it works

wispy quartz
wispy quartz
graceful lynx
#
hook.Add( "PostDrawTranslucentRenderables", "A1_RenderTargetTesting_ClearWaterRenderTargets", function()
    local renderTargetName = render.GetRenderTarget():GetName()
    if renderTargetName == "_rt_waterreflection" or renderTargetName == "_rt_waterrefraction" then
        render.Clear( 0, 0, 0, 255, true, true )
    end
end )
wispy quartz
#

cursed

#

render.MaterialOverride and renderView with material with WriteZ shader

snow cradle
#

what is writez shader

wispy quartz
#

For your case you already use lightmap pass which includes your Z buffer values, which you can actually use already

#

by lightmap pass i mean your's rt_lightmap or how was that called idk

wispy quartz
graceful lynx
#

Huh

#

I didn't realize lightmaps were just a texture that was available

#

Neat

neat terrace
#

render the shader to screen & grab the pixels

wispy birch
#

no depth

#

obv no depth

#

enable depth

#

thus you have two rendertargets bound, read both

#

what

#

ah, that

#

yeah

#

whats ur problem here

#

get? maybe set?

wispy birch
#

COLOR0 -> idx 0 rt
COLOR1 -> idx 1 rt

#

literally just create a rendertarget (three in your case) and set them via

render.SetRenderTargetEx(0, rtWorldNormals)
render.SetRenderTargetEx(1, rtWorldPos)
render.SetRenderTargetEx(2, rtDepth)
#

rt0 is 1 here? wtf

#

also are you rendering right away

#

RenderView might be messing with rts

#

wdym

#

show results

#

you have to restore the rts

#

at the very least

#

but thats probably not the issue

#

this is probably a direct binding to directx set shader api

#

so uhh

#

i literally have no idea why it doesnt work unless
a. something is resetting them in renderview
b. something is overwriting your rts before you draw them to screen

#

nope thats not it

#

this is literally how it is supposed to work

#

we have had this before

#

ah, well still, it should work
you can test it by doing something simpler than a renderview, maybe render a single model and immediately draw the result to screen

#

ну епта делай что говорю

#

протестируй на более легком примере

#

да, просто одну модельку вьеби в рендертаргет и сразу на экран после этого

#

да похуй, главное вывод на несколько рт проверить

#

что внутри не так важно

#

тем, что ты проверишь, баг в самой функции, или в RenderView

#

это мы и проверяем

#

пшел тестить

#

неподатливый какой попался

#

там есть еще одна проблема, эта хуйня глобальная

#

так что если что то еще юзает эту хуйню внутри, это вызовет конфликт

#

и либо тебе в рт ебень запишет какую то, либо просто нахуй пошлет

#

каво

#

потому что это не имеет смысла

#

да потому что они на разные слоты нацелены еб твою мать

#

есть несколько слотов рендертаргетов

#

COLORn на них и ссылается

#

а я о чем

#

сука ну ты тугой что ли

#

ты пойми разницу между SetRenderTarget и SetRenderTargetEx

#

ой бля

#

щас

#

секунду

#
struct PSOutput {
    float4 out0 : COLOR0;
    float4 out1 : COLOR1;
};

PSOutput main()
{
    PSOutput o;
    o.out0 = float4(1, 0, 0, 1);
    o.out1 = float4(0, 1, 0, 1);
    return o;
}
-- rt0 и rt1 создаешь сам

render.SetRenderTarget(rt0)
render.Clear(0, 0, 0, 0)

render.SetRenderTarget(rt1)
render.Clear(0, 0, 0, 0)

render.SetMaterial(matShader) -- тот, который я написал сверху (мб придется подредачить для гмода)

render.SetRenderTargetEx(0, rt0)
render.SetRenderTargetEx(1, rt1)

render.DrawScreenQuad()

render.SetRenderTargetEx(0)
render.SetRenderTargetEx(1)

-- не обязательно сразу, если невозможно, но лучше как можно скорее отрисовать на экран
render.SetMaterial(rt0mat)
render.DrawScreenQuadEx(0, 0, ScrW() / 2, ScrH() / 2)

render.SetMaterial(rt2mat)
render.DrawScreenQuadEx(0, ScrH() / 2, ScrW() / 2, ScrH() / 2)
#

если один рт красный, а другой зеленый - все работает, как должно

#

ты ебанутый один и тот же материал использовать?

#

rt0mat (и 1) должен быть как во втором примере здесь

#
#

ты другой материал для рисования на экран использовать должен

#

да пиздец, всё за тебя сделай

#
local rt0mat = CreateMaterial("mat_rt0", "UnlitGeneric", {
    ['$basetexture'] = rt0:GetName(),
    ["$translucent"] = "1"
})

local rt1mat = CreateMaterial("mat_rt1", "UnlitGeneric", {
    ['$basetexture'] = rt1:GetName(),
    ["$translucent"] = "1"
})
#

ну походу оно в гмоде сломано, хули

#

других вариантов особо не вижу

#

хз

exotic willow
#

так это не шейдер у которого вообще глубина должна быть. говорили же что будет генерал шейдер со всеми приколами

errant nacelle
#

Moon runes

misty surge
#

Figures the week I get off of shaders, we got some inspiration lmaoo

wispy birch
short dirge
#

is just greek innit

#

people used to speak it all the time

obsidian merlin
#

How do I set the language of the chat to English

misty surge
misty surge
#

Wauterboi and I go way back. Lol out of context

wispy quartz
#

Блять я же писал

#

Берешь, рисуешь сначала всю сцену с материалом на котором WriteZ шейдер стоит

#

он тебе просто глубину сцены запишет

#

потом снова рисуешь ту же самую сцену, но со своим шейдером

#

И все

#

Я писал об этом много раз, да даже фикул об этом писал так же

#
render.Set*Override(writeZMaterial)
render.RenderView()
render.Set*Override(customShaderMaterial)
render.RenderView()```
#

Потом если тебе прям захочется несколько буфферов сделать, берешь копируешь её через copyRenderTargetToTexture, а потом клираешь (render.Clear(0, 0, 0, 0, false, false)) эту самую ртшку, (но не буффер глубины) и рисуешь заново, ибо глубина осталась. И заного рисуешь своим кастом шейдером

#

Насчёт render.SetRenderTargetEx() пиши ишью рубату или фикулу.

wispy birch
#

слушай ты по моему слишком токсичный

#

тебе помогают, а ты простым инструкциям следовать не можешь, и еще пиздишь в ответ

#

обьясни мне, какой человек в здравом уме будет писать вот это?

#

один и тот же материал использовать, т.е. ШЕЙДЕР

#

рисуя хуету для дебага на экран

#

ты явно не знаешь, что делаешь

#

идиот, я тебе дал способ проверить, ошибка в самой функции, или где то внутри

#

@calm root hey, uhh, this guy right here is being insanely toxic and egoistic for no reason, if not for now, i would want this to be on the record for future encounters with him
it seems he thinks that someone is compelled to commit to help him fully, not just provide a way to do what he wants, but also to do everything up to writing actual code for him
this and the fact that he does not seem to know what he is doing, as is evident from him failing to draw two rendertargets to screen, using his shader to do so instead (and not even linking the rendertarget to the material, bruh), makes me doubt that it is worth dealing with him

wispy birch
#

i dont want to bear with your toxicity, so i will not even respond

wispy quartz
#

Так блять сложно посмотреть википедию, тупой ты еблан?

#

Ты долбоеба кусок сам это же используешь когда проход глубины делаешь

#

Я как понял iq у тебя отрицательное, так шо пошел нахуй, хуесос

#

Хуй тебе, а не помощь

wispy quartz
wispy quartz
#

Ты взял шейдер с тоя, петух)

glossy sorrel
#

Ah, yesss, shader drama.
That's new.

wispy birch
wispy quartz
#

Please ban this ungrateful Akabenko guy pleaseeeeee

#

He answers toxic stuff in response to our help, really...
@calm root

calm root
#

yeah, that is too far, removed them. You guys can have a dedicated channel once there are enough people who have a clue on how it works and we don't ego over the knowledge

#

i cannot support people in that channel as i have no bloody clue on how this works yet

turbid crystal
#

I'm assuming there's no generic guide yet on how to get started with shader shenanigans for this sort of stuff yet?

#

I've seen people occasionally link pre-existing things but uh.

steep river
#

what happened

vapid reef
#

https://wiki.facepunch.com/gmod/Shaders/screenspace_general

check out the see also section for guides on shador authoring(the valve wiki one) and how to setup the tooling (ficool2 post)

#

the wiki page itself documents the shader

steep river
#

what did he say in english

keen coral
#

damn...

calm root
#

Roughly, your dad is raped in prison, the insults were hard to translate

steep river
#

damn

#

lol i bet he cant say that in person without a black eye

#

nerd coder toughs act in internet

finite quarry
#

didn't he leave and come back again

#

or was he kicked last time too

calm root
#

They left and returned

steep river
#

is he already banned or

finite quarry
#

yeah

steep river
#

i mean hes talented in coding and anyone can appreciate that but why have to insult

calm root
#

I prefer to use terminology like removed instead of banned, but yeah

finite quarry
#

might have just been bashing together random code snippets

#

iirc he did say the volumetric clouds code was just kinda copied from mee's video

steep river
#

i mean the fact he can put it all together

#

but yeah maybe giving him too much credit isk

finite quarry
#

well talented or not

#

was still a shidhead so

#

good riddance

calm root
glossy sorrel
#

Oh no, mesh skinning. This will be kind of tough to do without a reference from the source engine.

finite quarry
#

the current documentation and examples we have are good for just actual screenspace stuff

#

but we need some docs on vertex shaders and stuff

#

and sm3 shaders

#

since it's possible

calm root
#

Guess I should start smaller with a few basic screenwarps and effects, I have no idea how it works in practice yet

finite quarry
#

the basics are actually not that complex, i've never dabbled with C in my life but i got the basic gist of HLSL when i toyed around with some of the example shaders we have

short dirge
#

also seems like you'd only be able to modify existing vertices, which has limited use case. who knows, maybe someone can tesselate displacements to make them wiggle like you're on acid or something.

finite quarry
#

well i mean yeah vertex shaders use existing vertices provided by the module

#

generating geometry would be compute shader territory i think, and that's dx11+

#

model*

wispy quartz
short dirge
#

works fine in something like minecraft where everything is a vertex. not so much in source where most of the world is a flat plane

wispy quartz
#

basically, it's pretty the same except you have 2 additional registers, and availability to use VS_OUTPUT

vapid reef
#

just pixel value in, pixel value out

turbid crystal
#

I'm currently just trying to figure out the bare minimum stuff I'm gonna need to get started, apparently the fcool2 thing has whatever's needed to create shaders? Or am I gonna need the SCell555 compiler?

vapid reef
#

you have metadata like position and stuff tho

vapid reef
wispy quartz
#

VS_OUTPUT is your PS_INPUT stuff, you have vertex shader that gives data to pixel shader.
The pixel shader data is interpolated between several vertices data from vertex shader

calm root
#

Might want to put whatever that extension was in a zip

turbid crystal
finite quarry
#

it was a zip

calm root
#

Peacekeeper stops zips I guess, maybe there was some issue on the rust discord

finite quarry
wispy birch
wispy quartz
#

He often uses reshade's shaders, shadertoy ones, and the ones that had been implemented by someone arleady

#

His famous fxaa, ssao were taken from reshade and some source engine ssao tutorial back from 2013

#

Also, his cd disk shader was also taken from shadertoy + he took mee's volumetric clouds and then made it through workshop, while calling that as 'his' shader

finite quarry
#

the ssao is pretty bad, it doesn't even work properly with transparency

#

and it's abnormally (imo) heavy

wispy quartz
#

The problem is with bad depth buffer, since it's DepthWrite hack by Ethan

#

The best option would be involving rubat to actually fix it

#

Since default depth buffer lacks prescision + has issues with skybox, etc

finite quarry
#

ah, because the material override is overriding transparency on the non opaque models right

wispy quartz
finite quarry
#

got it

wispy quartz
#

i think rubat can just make the depth buffer a R32F image format and fix it, so it will have transparent stuff working + better prescision

finite quarry
#

hmm, wouldn't it be possible to render a custom depth buffer by just drawing the world again with fog?

wispy quartz
#

I mean, hacks are mostly temporary

finite quarry
#

hacky, but should preserve transparency

#

and not as a permanent fix ofc

wispy quartz
#

before he got depthwrite shader stuff

wispy quartz
wispy quartz
#

Until rubat will add ficool2's CustomShader
Ficool2 managed to make gpu skinning working in his shader

glossy sorrel
finite quarry
#

yeah even if we don't get all that, what we got now is still pretty big for gmod

glossy sorrel
#

Even with the crutches that we have to use now.

graceful lynx
turbid crystal
finite quarry
#

well the simplest thing would be to just turn the whole screen a certain color i suppose

#

just output a float4 of like

#

255,0,0,255

glossy sorrel
#

Also, some times called as hello-triangle or something like that.

turbid crystal
#

I'll have to wait and think on it.

dusty linden
#

The shader wars are over

turbid crystal
#

Should I create a blank addon file sorta thing for testing this or do shenanigans in garrysmod/shaders/fxc?

dusty linden
#

Now comes a time of peace and prosperity 🙏

turbid crystal
glossy sorrel
steep river
#

anyone tell me how to drugs shader? idk if it looks like a trip

turbid crystal
glossy sorrel
# turbid crystal Is there any particular resource you'd recommend? a lot of these pages are absol...

I would personally advise you to try using Raylib with any of the Lua bindings.
There are tons of examples for C, but porting them to Lua is as easy as Ctrl+C and Ctrl+V, with only minor adjustments.

Just try writing something - maybe experiment with shaders. There isn’t a significant difference between GLSL and HLSL.

Also, you can read this. https://thebookofshaders.com

graceful lynx
# turbid crystal I don't think shaders have a "Hello, World!" equivalent.

Let me rephrase: You’re going through a learning experience that I need to go through. When you understand the basics of shader creation, I’m hoping you can tell them to me (or tell me where you found them) so I can understand the basic elements of the process and begin to document them on the wiki

turbid crystal
graceful lynx
#

I highly recommend it

#

It’s a risky link to click, is it not?

turbid crystal
keen coral
#

hah

turbid crystal
#

ficool2's thing's apparently supposed to generate vmts? I don't see anything though.

finite quarry
finite quarry
turbid crystal
finite quarry
#

yeah, all you need is a shader that compiled successfully and a material that uses the shader

#

and then of course some lua if you wanna handle drawing the shader on the screen and spawnmenu entries and stuff like that

turbid crystal
#

or r_overlay or something along those lines?

finite quarry
#

yea that should work too

turbid crystal
#

Gonna try it now, I made one that, presumably, will swap red and blue around.

#

Huzzah! (I think)

finite quarry
#

yeah looks like it did exactly what you intended it to do

turbid crystal
#

IIRC unless one uses that weird workaround, there's no real way to change the shader on the fly (and thus I'd need to restart the game)?
(I don't fully know what the workaround is but I do know it involves changing the name of the shader and then reloading materials)

vapid reef
turbid crystal
vapid reef
#

not sure, @misty surge would know though

steep river
#

anyone know how to code mushroom trip in shaders?

bitter oriole
steep river
#

dont got access to them rn🤣

icy plume
#

has somebody made any attempt at making shaders for models yet? I haven't kept up with this too much yet

keen coral
#

i feel like $writedepth and $depthtest do absolutely nothing
i mean it does something, but not the way it should be

keen coral
icy plume
#

oh, that's unfortunate 😭

jovial tide
#

its an easy fix on the c++ side but i think its better to make a general purpose shader rather than hijacking screenspace_general

dusty linden
#

Oh my goodness gracious, custom shader incoming?

shadow shuttle
#

does he know

misty surge
#

Linux I think I’d have to tailor the concept but I don’t use Linux unless it’s backend related.

#

If only I knew how to trigger it when it saves, in vscode, that would be ultimately what I’d want.

turbid crystal
#

Has anyone else faced this weird sort of stuff before? I'm trying to make a basic sobel shader

misty surge
#

The realistic term is artifacting, it looks like your UVs might be messed up. If you have code I could take a look.

turbid crystal
finite quarry
#

are you converting a shadertoy/GLSL shader

#

i.uv returns normalized coordinates (between 0-1)

#

not the actual resolution

turbid crystal
turbid crystal
calm root
#

remap it to the resolution instead of 0-1 based on what they said?

turbid crystal
#

Originally I thought I had to divide it by the resolution, but it appears that was not the case, lol.

misty surge
#

Please either DM the code, both vertex and fragment shader, I’ll tell you right away.

#

I respect your right to keep it to yourself but, maybe I can help.

keen coral
misty surge
#

I was telling @turbid crystal That AI is now shader capable. I would suggest anyone who’s not using it to start.

turbid crystal
#

The solution the ai in question gave me didn't get any closer to solving the issue, though it did sorta point out a flaw in something I did, but even fixing that didn't fix the issue.

misty surge
#

Of course, you’re totally right. We have to realize that it’s a powerful tool for checking your code.

#

It’s very pragmatic to ask it the right questions, though, that’s very important

turbid crystal
#

I generally don't like using ai for anything more than information, but I wouldn't use it to code directly unless I genuinely couldn't figure something out and have no other choice.

#

That being said, I'm not sure if its my code or if gmod is just being iffy at this point, it seems to be half-working, its just that the stuff is stretching across the screen.

rain marten
#

How can I access the depth information that WriteZ provides on a custom screenspace_general shader? And should I use that same shader in the same pass where render.*MaterialOverride functions for the WriteZ material are used?

misty surge
#

Screenspace does not have “depth” so depth functions are useless.

#

FrameBuffer has depth, but that’s about it. The actual shader itself doesn’t have it.

rain marten
#

Oh well, I really only need to store depth as color, in a way that works with a orthographic view

#

I just didnt understand how to use the WriteZ shader that was suggested by papasoco to do that

#

wait I think I might have figured out how to write my own DepthWrite shader

#

it looks like it's going to need separate logic for a perspective and ortho view but it seems to work

#

almost there, it can even handle custom far plane values now

#

it does render the world geometry but some brushes and all entities do not show up

#

ig theres more to it when it comes to rendering props with a custom shader

misty surge
#

When you do renderview, you may need to also include the PVS, so the game renders the same bsp data. That part seems to be the issue.

rain marten
#

its when I use my custom shader on those entities that makes them go away

#

its basically just a issue of "I dunno how to make screenspace_general work on props"

misty surge
#

In order for this shader to run with this setup, is if you reconstruct 2D to 3D. Screenspace doesn’t have 3D (no depth) so you have to “reconstruct” to get the perspective pos.

#

Without depth, it’s very difficult to calculate it. Unless you chose a simple object like a sphere, block, etc…

#

The object should just have normal shaders, capture 2nd process. Unfortunately that’s the way we have to go.

#

You can rely on the depth buffer to offer you the 3D position which is localized but practically helpful for some complex shading.

#

Another thing I wanna add is, using the shaders with alpha channels instead of depth makes the most sense to me, and then just blend it with the frame buffer.

wispy quartz
#

You use it just like a mask

#

Basically, you can do the same stuff with no material override stuff, with using render override colorwrite

misty surge
upbeat kernel
#

how do I change the frame of one of the textures? there isn't a VMT parameter is there? and I don't imagine tex2D has a parameter for that, like the Z coordinate

neat terrace
#

materials with SpriteCard shader use a $frame var that you can change before rendering the material

upbeat kernel
#

if I'm doing this strictly in a map and foregoing a Lua environment that narrows my options

neat terrace
#

you may be able to do something with a matproxy :?

upbeat kernel
#

like AnimatedTexture?

neat terrace
#

yes

upbeat kernel
#

that's the normal approach, but it requires a variable to change like $frame

neat terrace
#

yep, you can just pass that no?

upbeat kernel
#

normally you'd use $frame or $bumpframe if you were changing a $bumpmap but I'm not changing that

#

I'm not changing my $basetexture, I'm changing my $texture2

#

I could give it a shot, idk if it really matters

neat terrace
#

wait what

upbeat kernel
#
    "$basetexture" "_rt_FullFrameFB"
//    "$texture1" "effects/3tpeyefx_"
    "$texture1" "tools/toolsblack"
    "$texture2" "effects/security_noise2"
    "$texture3" ""

need to animate $texture1* not $texture2 mb

#

yeah [as far as I can tell] AnimatedTexture uses AnimatedTextureVar to look at the texture and see how many frames it has, then it increments the AnimatedTextureFrameNumVar you supply (e.g., $frame, $bumpframe) between 0 and the max number of frames it found on AnimatedTextureVar

#

so if someone can answer whether there's a way for me to set the frame in the shader itself, I could use that to my advantage by setting one of the screenspace_general constants with AnimatedTexture and then doing the minimal side of the animation logic myself in the shader

misty surge
#

Frames or $frame controls the frame. We cannot however change from frame to frame in the shader itself, only on the CPU level with parameters.

#

If you wanna go 3D, you can put tex3D as long as it’s 3.0 shader.

#

This requires your textures to be 256x256x256, same resolution

#

If I’m not mistaken, if we could just use tex3D with 3 layers or so, that would be epic, but I haven’t honestly tried/checked if we can differ the resolution this way.

upbeat kernel
misty surge
#

I would assume, frame only acts as a direct reference to base… frame is a tool source used to interpolate frames with slices for animations.

Usually you can reference a new texture per frame, and it would work but that is a massive request to be made.

$frame is used to resolve optimizing issues by referencing it statically vs dynamically.

So only basetexture I would assume.

misty surge
#

When the new shader comes out, I assume we could go up to 8 samplers. Rn we’re stuck with 4

#

I say assume a lot, cuz I’m like either not sure or w.e. I don’t wanna steer people in the wrong direction ofc

#

I was going to say the best case scenario is to make a texture sheet if you’re looking for some more textures I suppose.

misty surge
# obsidian merlin New shader?

Ideally, like other games, utilizing the proper 3D geometry into custom shaders. This is something I believe ficool, myself and everyone else are expecting when we talk about “shader stuff”

At the moment, even with limited screenspace, shaders 2D->3D can just be 3D->3D

#

Since this discovery is relatively new, we’re all catching up to potentially one of the coolest features in gmod in my opinion in a very long time.

obsidian merlin
#

I really want to make textures for mappers but everything nowadays uses a PBR workflow

#

I know PBR is a meme but I'm hoping to see someone put together PBR and Parallax

#

Right now I'm working on procedural cracks for various materials

misty surge
obsidian merlin
#

Attempts 1 through 3

misty surge
#

At the moment, our depth in the frame buffer is relatively 192 units away from the screen, and then depth goes away.

misty surge
obsidian merlin
#

I have been looking at nothing but cracked tiles for one week

misty surge
#

Whatcha working on as a concept? Maybe I can help.

obsidian merlin
#

I'm laying down at the moment, but this was my last attempt focusing entirely on the normal and AO. I wasn't satisfied with the cracks

misty surge
#

Yeah, that’s very difficult not going to lie, I’d say just rely for now without parallax, until we’re able to write custom 3D shaders, ideally.

#

I hate using two passes for something that should be quick and painless

obsidian merlin
#

Yeah that's all normal and ao

misty surge
#

If you’re not concerned with depth, (planes) you can easily do this. Maybe simple geometry like blocks you could calculate the depth using math alone.

#

Parallax works, just needs depth ;-;

#

The moment it does, I got parallax shaders ready to go. Lol on GitHub

icy plume
shadow shuttle
upbeat kernel
#

what do I need to do to get my screenspace_general shader overlay to also render the player's viewmodel? it was working when I was using shader model 2.0b but now that I'm on 3.0 everything works great other than that. _rt_FullFrameFB doesn't include it I guess(?)

though that doesn't explain why it worked on shader model 2.0b

my only guess is it has something to do with my new VMT, which I still need to investigate. only problem is most of the parameters in the old one are a mystery to me

#

I'm not using Lua in this environment (env_screenoverlay), so hook order isn't a suitable answer.

jovial tide
#

see the examples in the shader sdk

upbeat kernel
#

I know exactly what you're talking about now, just didn't know what it did

#

isn't that just the ignorez flag?

#

oh it's a spritecard flag, interesting

obsidian merlin
#

i'm about to break the rules

#

this has NOTHING to do with gmod OR shaders

obsidian merlin
#

I think small things like cracks in tiles might not necessarily need parallax shaders or anything like that. This is specifically trying to do cracks in bathroom tiles

keen coral
misty surge
#

Dx9 vs OpenGL :/

weak egret
#

Would it be possible to make something comparable to L4D Infected gore/injuries with shaders? Or will I have to lobby for the Infected shader?

#

Doesn't have to be as extreme, sort of just want to emulate gashes and wounds better

jovial tide
#

gmod can just add the Infected shader

timid pumice
#

jokes aside, i don't think that shader can just be added, i think it can be catalogued as a stencil operation along a subset of meshes overlapped, valve really got his hand dirty

timid pumice
#

No and i have proofs it's impossible to just add those

shadow shuttle
placid stream
#

unsure of exactly what the conversation here is ATM but ill just post these random related links:
https://github.com/Facepunch/garrysmod-requests/issues/2230#issuecomment-2711742851
https://www.youtube.com/watch?v=5_G79LJ_l2Y

a capture of some of the technical content behind left 4 dead 2's wounding system.

▶ Play video
GitHub

Details I know that this is a big request but, would it be possible to add in basic support for the Infected Shader that is exclusive for the L4D2 common infected? Support for: General Parameters P...

shadow shuttle
weak egret
misty surge
#

We have the tools to begin the process of making our own. I won’t say it’ll look the same because shaders work a lot better than work arounds, but you can add more detail.

shadow shuttle
#

does he mean making our own l4d2 gore shaders or just shaders in general

misty surge
shadow shuttle
#

I see, thank you for explaining

misty surge
#

No problem. Any questions you can always ask me here.

shadow shuttle
misty surge
#

This shader discovery was made around December of last year (new).

We’re in the infancy of shaders in gmod. Rubot and everyone is only just learning about what it can do/not do. Ficool found this out, but the entire concept of shaders is a very verbose and complex system that normally requires a lot of engineering hours, prior to recently.

With AI, now it becomes easier, but ideally no one uncovered the rock but ficool.

Rubot I’m sure knows about this, and has every intention to include it, but he’s tied up.

Once we do, shader 3.0 will properly be supported.

#

I garentee you, we all want this, everyone. Just not in that phase yet. It’s probably being fast tracked

#

I really hope and understand the more we understand about this, the quicker the demand will be.

shadow shuttle
#

Okay

#

thank you

misty surge
#

For now, I agree with ficool and stick with this for now 🙂

shadow shuttle
#

Will shader 3.0 let us do more than just 3d stuff

keen coral
shadow shuttle
#

7D...

keen coral
#

or wait, what is it about? i think i missed the dialogue and are you talking about something specific?

errant nacelle
#

I am a 5D entity and I feel like gmod doesn't represent those 2 extra dimensions well enough

#

I hope shaders can fix that

timid pumice
placid stream
#

I feel like there's a lot of missing context. because I don't even know if y'all are talking about the L4D2 infected shader or the L4D2 gore system, Also I don't know if this is about screenspace_general or GMod in it's entirety

timid pumice
#

That's what I say, gore is not a shader, 4way tinted shader is indeed a shader

misty surge
#

Do we have the GitHub request for the 3.0 shader implementation? I’d like to upvote it. I’m trying to find it.

#

If we don’t, maybe we can start talking about it?

#

I don’t see one. So I guess we should make a request. Since people keep asking, maybe I can ask them to upvote said request. It’s possible, just kind of a large ask.

misty surge
#

That’s my question, if we have one can you share it?

jovial tide
#

3.0 already exists

misty surge
#

I get that, I mean support for 3.0 such as actual 3D depth supported, not just screenspace itself.

#

I’m not sure how to ask what I’m asking yet, but ideally allow us to cast meshes with depth pass and custom shaders.

#

So we can do parallax mapping without resorting to reconstruction.

#

This for example is what I mean. Our shaders don’t get called in the depth pass. So this is what we’re basically limited to.

wispy quartz
#

@misty surge Hi, i remember you were asking for $c4 and $c5 support, yeah?

#

So, jaffies (aka mikhail_svetov guy) came up with an idea to get up to more 48 additional constant values

#

without using textures, and so on.

#

Basically, he said that you can use $viewprojmat + $invviewproj keyvalues to override the default one matrices in your pixel/vertex shaders

wispy quartz
wispy birch
#

there is also the model matrix

wispy quartz
#

const float4x4 cViewProj : register(c8);

wispy quartz
wispy birch
#
enum
{
    // Standard vertex shader constants
    VERTEX_SHADER_MATH_CONSTANTS0 = 0,
    VERTEX_SHADER_MATH_CONSTANTS1 = 1,
    VERTEX_SHADER_CAMERA_POS = 2,
    VERTEX_SHADER_FLEXSCALE = 3,   // DX9 only
    VERTEX_SHADER_LIGHT_INDEX = 3, // DX8 only
    VERTEX_SHADER_MODELVIEWPROJ = 4,
    VERTEX_SHADER_VIEWPROJ = 8,
    VERTEX_SHADER_MODELVIEWPROJ_THIRD_ROW = 12,
    VERTEX_SHADER_VIEWPROJ_THIRD_ROW = 13,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_10 = 14,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_11 = 15,
    VERTEX_SHADER_FOG_PARAMS = 16,
    VERTEX_SHADER_VIEWMODEL = 17,
    VERTEX_SHADER_AMBIENT_LIGHT = 21,
    VERTEX_SHADER_LIGHTS = 27,
    VERTEX_SHADER_LIGHT0_POSITION = 29,
    VERTEX_SHADER_MODULATION_COLOR = 47,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_0 = 48,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_1 = 49,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_2 = 50,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_3 = 51,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_4 = 52,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_5 = 53,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_6 = 54,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_7 = 55,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_8 = 56,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_9 = 57,
    VERTEX_SHADER_MODEL = 58,
    //
    // We reserve up through 216 for the 53 bones supported on DX9
    //
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_13 = 217,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_14 = 218,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_15 = 219,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_16 = 220,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_17 = 221,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_18 = 222,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_19 = 223,
    VERTEX_SHADER_SHADER_SPECIFIC_CONST_12 = 224,

    // 226        ClipPlane0                |------ OpenGL will jam clip planes into these two
    // 227        ClipPlane1                |


    VERTEX_SHADER_FLEX_WEIGHTS = 1024,
    VERTEX_SHADER_MAX_FLEX_WEIGHT_COUNT = 512,
};```
wispy quartz
#

And this is for viewproj and invviewproj

const float4x4 g_viewProjMatrix : register( c11 );
const float4x4 g_invViewMatrix : register( c15 );
wispy birch
#

the whole cbuffer is not controllable as a whole, but there are things you control

misty surge
#

That’s awesome, I was just told this not too long ago. That’s pretty epic not going to lie.

#

Although this does let you modify the view matrix, I guess my request extends this by including a depth pass so the meshes drawn are properly using depth as a concept, during runtime.

wispy quartz
#

As well as with the depth thingy obviously

misty surge
#

Hmm, this could work. I gotta try it out.

wispy quartz
misty surge
#

I guess that would work for calculating the depth of the vertices but not the pixel shader right? I’d wanna know if it did

wispy quartz
#

but...l.

#

Depth func is set to always ($ignorez basically)

misty surge
#

Yikes

wispy quartz
#

That's on c++ side though, rubat can fix that

misty surge
#

Exactly so do you think we can make a request for something like this. This is what I wanted, but I appreciate shaders rather than nothing so…

jovial tide
#

like i mentioned its better to make a new general-purpose shader

wispy quartz
jovial tide
#

hijacking a screenspace shader is ugly, and the interfacing issues can be refactored rather than having backwards compatibility

misty surge
#

If we had an official request, so that we can upvote it. I 100% agree.

jovial tide
#

like $c constants should be vector4s not individual floats

wispy quartz
#

mat:SetInt('$depthfunc', DEPTHFUNC_LESSOREQUAL)

jovial tide
#

i already made such a general purpose shader

#

only thing that remains is flashlight support and making examples

misty surge
#

Got it. So that’s the missing piece?

jovial tide
#

yes

wispy quartz
#

I think having more control of a render pass that's used for depth capturing woulda solve that issue from lua side, with some hack i think

jovial tide
#

another consideration is exposing lua to control the rendering state

#

so you call pShaderDynamic and pShaderShadow methods

#

however this is potentially dangerous (and also a lot more work) so i think limiting it via vmt parameter control is the best option

wispy quartz
misty surge
#

Lol, probably never going to happen. I wish we had that but it’s very crashy

misty surge
jovial tide
#

c++

misty surge
#

Gotcha, makes total sense.

wispy birch
#

i would like to note that a pretty cool shader ide exists, and it supports hlsl

graceful lynx
wispy quartz
wispy birch
#

do note that this does not support FXC and old shader models, it compiles shaders to spir-v and uses them like that (it also has a debugger tho because of that)

snow cradle
cosmic perch
#

hey cs guy who attacked me for drawing boxes using shaders

errant nacelle
#

drawpoly > shaders :^)

cosmic perch
graceful lynx
errant nacelle
#

because in most use cases it's worse

graceful lynx
#

wait

cosmic perch
errant nacelle
#

the only time it's better is when nothing is being changed but if you're using Circles! chances are the circle is being changed every frame

graceful lynx
wispy quartz
errant nacelle
#

idk how gmod shaders work because nobody will explain it to me and there's no documentation

cosmic perch
#

read rndx loser

errant nacelle
#

no

wispy quartz
#

there was documentation but god took it from us

errant nacelle
#

all I know is where shaders should be but I've got no clue how to actually use them in-game

graceful lynx
wispy quartz
graceful lynx
#

@errant nacelle I'm pretty sure the answer is:

  1. Clone https://github.com/ficool2/sdk_screenspace_shaders/
  2. Use shadersrc/example_wave_ps2x.hlsl as a "Hello World" shader
  3. Drag example_wave_ps2x.hlsl onto build_single_shader.bat
  4. There is now a compiled shader in <cloned location>/shaders/ and a corresponding VMT in <cloned location>/materials/effects/shaders/ named after the .hlsl file that was compiled
  5. Make an addon with a addons/<addon name>/shaders/ folder containing the compiled shader and a addons/<addon name>/materials/effects/shaders/ folder containing the VMT
  6. See it in-game via r_screenoverlay effects/shaders/<shader name without an extension or "_ps2x">

I'm in the middle of debugging something so I can't test it right now, but if you have time to try it yourself and report back, that would be appreciated

wispy quartz
#

Therefore they need to be edited to use vertex's color as TEXCOORD1 (not 5) or use custom vertex shader.
Also, x360appchoser is not working right now. Use $vertexcolor and $vertextransform

cosmic perch
graceful lynx
#

That would be great

#

A very simple example would be much appreciated

cosmic perch
#

do u want me to include the python generating trick im doing?

graceful lynx
#

What's the trick?

cosmic perch
#

basically i use python to compile shaders inside lua file with a gma, to easily use them

graceful lynx
#

That sounds like something that would be cool to have as a separate thing, but not as a "Baby's first shader" example

cosmic perch
#

so i dont have to manually drag and drop or manually addcsslua

#

i can make it really simple, i think it will be more user friendly to just handle it all

graceful lynx
#

Sure

nocturne patio
wispy quartz
nocturne patio
#

I'll share the results soon. it seems there's no difference I guess, though.

cosmic perch
#

i think that is as simple as i can get, once u learn some decent stuff, u can do a pr and improve it/make it more simple

#

unfortunately, it cant be that user friendly that u expecting because shaders aint easy at all at first

graceful lynx
#

Thanks for putting this together!

nocturne patio
nocturne patio
#

thx

#

Is there any clue that we can use normal as the vertex shader input? I seefloat4 normal : NORMAL; in Srlion's common_vs.hlsl but I couldn't find it in the CS:GO shader codes (and in my disassembly).

graceful lynx
#
Compiling shaders...
Compiling 'boom_ps20b.hlsl' with version '20b'
File "boom_ps20b.hlsl" does not exist
File "boom_ps20b.hlsl" does not exist
Failed to parse boom_ps20b.hlsl
File "src" does not exist
Writing to compiled\main.lua
Processing complete.
cosmic perch
#

what is ur pwd

graceful lynx
#

D:\Projects\Garry's Mod\Shaders\basic-gmod-shader

cosmic perch
#

Create a new file in src/ eg. src/boom_psxx.hlsl.

#

_psxx

#

u select the version in compile_shader_list.txt

graceful lynx
#
Compiling shaders...
Compiling 'boom_psxx.hlsl' with version '20b'
File "boom_psxx.hlsl" does not exist
File "boom_psxx.hlsl" does not exist
Failed to parse boom_psxx.hlsl
File "src" does not exist
Writing to compiled\main.lua
Processing complete.
cosmic perch
#

are u manually running build_shaders.bat

#

or using python

#

oh thats python

graceful lynx
cosmic perch
#

oops

#

lemme git clone and test

#

it works on my end

#

moved them outside util directory

#

it should work fine now with u

#

idk why didnt work

graceful lynx
#

Hm

cosmic perch
#

why does it say file "src" does not exist wtf

graceful lynx
#

Good question

#

Okay, I moved the repo to the root of my C:\ drive and it worked

cosmic perch
#

thats even more weird

graceful lynx
#

Something to do with being on the D:\ drive, or having spaces/special characters in the folder path I assume

cosmic perch
#

im literally running it in D:\

#

has to be some character fukin it up yeah

#

-shaderpath is not smart

#

line 50 in build_shaders.bat

graceful lynx
#

Once it's compiled, the instructions just say to move the main.lua file and don't make mention of the .vcs files it produced

#

Should I be moving those somewhere?

cosmic perch
#

no, python already compiles them into main.lua

#

u just need to include serverside and clientside

#

eg.

include("main.lua")
#

no need to Addcsluafile

graceful lynx
#

Autorun should work fine, then?

cosmic perch
#

yeah

graceful lynx
#

What's the expected output?

cosmic perch
#

for the drawing?

graceful lynx
#

Looks like a black square, right?

cosmic perch
#

play with the 4 params u passed

#

from 0 to 1

#

eg. 0.5

graceful lynx
#
draw_my_shader(100, 100, 200, 200, 0, 0, 0, 1)

0, 0, 0, 1 being opaque black

cosmic perch
#

idk what opaque means, but yeah should be black

#

change first one to 1, draws red

graceful lynx
#

Opaque is the opposite of transparent

cosmic perch
#

oh, solid one

#

ok

graceful lynx
cosmic perch
#

u can use it to replace default surface.DrawRect to draw with true colors

#

the material created, i set it to disable gamma correction

graceful lynx
#

What's up with these UVs?

-0.015625, -0.015625, 1.015625, 1.015625
cosmic perch
#

shapes draw weirdly

#

kinda like drawing an image without noclamp

#

u can remove it till u hit the issue i had

graceful lynx
#

Looks normal to me?

cosmic perch
#

no, i meant, size wasnt correct as far as i recall

#

i cant remember the exact issue, but u can remove till u find that whatever ur drawing looks weird

graceful lynx
#

Thanks for putting this together! When I have more time soon I'll "dissect" it to fully understand how it works

cosmic perch
#

it will be tough at first, but later it will be easy

#

just find some simple project to learn it

#

pls update the repo once u learn to make it easier for newbies

graceful lynx
#

Definitely

#

I'll also put information on the wiki when I understand more

cosmic perch
#

ok great

nocturne patio
snow cradle
snow cradle
# steep river lol i bet he cant say that in person without a black eye

This conflict is much deeper. This group of people has been trying to provoke me for a long time. I am hot-tempered, so I fell for it. However, I am glad that the conflict is over. I will not get a black eye.

After this conflict, a group of people started to hate my works. All this is done intentionally.
However, because of my minority, I have to have a sharper tongue than my opponents. But I promise that I won’t behave so aggressively again.

wispy birch
# snow cradle This conflict is much deeper. This group of people has been trying to provoke me...

no one was trying to provoke you, especially for a "long time". And i have not even talked to you (well, almost at all) before your "explosion" back then. I would also not think the papasoco guy tried to harass you before that point, so, please, stop trying to make up an excuse for your behavior.

Wanna be here and learn/do shader stuff? Nobody is stopping you, but do not act like you are entitled. Dont stray away people from this relatively new channel, or you risk damaging the whole branch of shader development in gmod, at least, for now.

Point is -- do not be toxic here.

snow cradle
#

I'm not going to quarrel with you

cosmic perch
cosmic perch
#

and have fun with shaders

upbeat kernel
#

has anyone figured out how to recompile/restructure the PBR shaders to mount them with screenspace_general yet?

snow cradle
wispy quartz
misty surge
#

We can do basic PBR.

I had this idea to basically use framebuffer’s depth up to 192 units, then I’d take the depth RT code I posted here to account for the rest of the scene.

#

The drawback for this, is there isn’t to my knowledge to account for textures with alpha. So they appear as they would if I had covered everything with a flat material.

#

Reconstruct the data with the proper Viewmatrix and you have quite a simple PBR.

#

Surface normals can be calculated via depth call using 3 pixels .

#

Multiply by the inverse view matrix and bam. Easy one, but in my opinion I’d rather wait for standalone shaders with casted depth.

misty surge
# upbeat kernel surface normals [like this?](https://discord.com/channels/565105920414318602/132...

Not quite, unfortunately if we do vertex normals in the vertex, that’s how it should work 100% agree, but if you notice in his photo depth is broken. So honestly it’s a step forward, but we’re stuck with surface normals being slightly inaccurate. It’s tough because it will appear good on flat meshes, it’s when the mesh starts to create complex depth surface normals via clip space to world space may have precision issues. All this to account for the depth pass.

#

The only way I know of to get surface normals is to transpose and reconstruct it via depth buffer, which probably is what we’re limited to (for now)

upbeat kernel
#

eek... at least we have render.GetResolvedFullFrameDepth() (which hardly helps outside Lua contexts)

misty surge
#

Yup! I have another solution for the maximum precision for depth (16bits) if you’d like I can show you.

upbeat kernel
#

sure, though I can't guarantee my maximum attention
(for the next 30 minutes)

misty surge
#

So’k im working so im lerking on my phone

upbeat kernel
#

oh there's a shader specifically for writing the depth buffer?

#

that certainly simplifies things. just use a different image format right?

misty surge
#

Yeah, but it’s very limited

#

Correct

upbeat kernel
#

you can't really get the true benefits from a RGBA16161616f depth buffer that way though

#

or does it just write it properly automatically? I actually have no idea

misty surge
#

You get the true benefits by upping the memory per pixel. The shader will use larger differences which in turn makes your depth higher quality

upbeat kernel
#

wouldn't you use the alpha component as an exponent?

misty surge
#

You can’t do 32bit because it will ruin the stencil buffer

upbeat kernel
#

ah

misty surge
#

16 bit is great tho

#

On very big maps, it can be extremely costly so 8 bits works out too sometimes

upbeat kernel
#

trying to find a special depth screenshot I took in helldivers

misty surge
#

This uses two depth passes to create depth beyond the 192 using the same idea I posted. This is from @snow cradle but this is the concept going forward as the true depth check.

#

As you may notice DepthWrite doesn’t account for alpha. So you’ll see what I mean here

upbeat kernel
#

strange, I could have sworn my depth buffer screenshots had alpha channels

#

but they don't

misty surge
#

It does! But it’s generated via the pipeline. So in theory framebuffer uses depth that’s been “finished”. We use this to change up the shader. But our screenspace mats do not have proper depth casting

#

Without depth pass, it’s like only reconstruction basically as the only option. Which would return to us what the GPU does already in its main pass. Therefore making the GPU run twice to do the same effect.

upbeat kernel
#

I meant my EXR files

misty surge
#

It would work, but layer that with other complex systems, the frames will definitely be worse off

#

Depth only uses 1 pixel per check afaik.

#

Not RGB, rather just R

upbeat kernel
#

and not alpha as transparency, just a fourth channel to store extra exponent data to squeeze in extra information. like how Valve uses the alpha channel to "compress" their HDR sky textures

#

to get 32-bit precision in their 16-bit BGRA8888 format

misty surge
#

Ahhh! If you’d like to know more I highly recommend you lookup +mat_materialist or w.e. And highlight rendertargets you can see the formats they use.

#

I forgot the convar but it’s very useful

snow cradle
#

normals:

upbeat kernel
#

is it possible to use a vertex shader to actually move the vertices of a model

upbeat kernel
wispy quartz
#

Don't forget to set $writez to 0 on screenspace_general one

nocturne patio
#

I could partially fix the broken depth of render.RenderView. It seems helpful to use render.OverrideDepthEnable(true, true) before drawing.

Returning depth value in the pixel shader seems also helpful.

upbeat kernel
nocturne patio
# upbeat kernel does anyone have any working examples of this?

Just modify the position before multiplying the MVP matrix and that's all

VS_OUTPUT main( const VS_INPUT v ) {
    output.projPos = mul( float4( v.pos.xyz + v.normal.xyz * 10, 1.0 ), cModelViewProj );
    // ...
}

but I couldn't use material parameters in the vertex shader 🫠

snow cradle
#

$VERTEXNORMAL 1 add Normal info to brush shader (idk about models)

upbeat kernel
#

oh wait you couldn't use material parameters. that would be my problem then

#

I was multiplying by a constant from the VMT

#

still, though, what does your VMT look like to not make the model look absolutely messed up to hell and not have screwed depth?

snow cradle
#

@wispy birch gave a hint that fixing the render order might fixed using SV_Depth from the pixel shader.

I use depth like that:

//vertex shader
    float4 vProjPos = mul( float4( worldPos, 1 ), cViewProj );
    vProjPos.z = dot( float4( worldPos, 1 ), cViewProjZ );
    o.Depth = vProjPos.z;
//pixel shader
struct PS_OUT {
    float depth : SV_Depth;
    float4 color : SV_Target0; 
};

PS_OUT main(PS_IN i )
{   
    PS_OUT Out = (PS_OUT)0;
    //code
    Out.color = c;
    Out.depth = i.Depth; //There should be a formula to correctly output the depth.
    return Out;
};

But some formula is needed to calculate this depth so that it works correctly. Artem suggested that we can try using znear/zfar.

Also it works with params:

//vmt
$WRITEDEPTH 0
$DEPTHTEST 1
#

@upbeat kernel also suggested using flags2 to apply lightmaps to places in the world where brushes with a screenspace_general shader.

It is possible that this flag also affects the correction of the brush rendering order.

Also, thanks to it, I was able to overlay lightmaps on brushes as through post-processing:

//pixel shader
float2 screen_uv = i.pPos/(1/Tex3Size);
float3 lm = tex2D(LightMap, screen_uv);

I haven't figured it all out yet, but a combination of $flags2 and SV_depth solves the depth problem.

@upbeat kernel's params:

     //vmt
    $test_flags2 7 //6 or 7 

    Proxies
    {
        Equals
        {
            srcVar1    $test_flags2
            resultVar    $flags2
        }
    }

https://developer.valvesoftware.com/wiki/Material_Flags

#

i use $test_flags2 39 (32+7) (MATERIAL_VAR2_NEEDS_TANGENT_SPACES+MATERIAL_VAR2_LIGHTING_MASK)
because i wanted to get tangents but it didn't work. u can use 6 or 7

snow cradle
# snow cradle <@883393561066881065> gave a hint that fixing the render order might fixed using...

UPDATE:

--mat proxy
local view = render.GetViewSetup( true )
local znear = view.znear
local zfar = view.zfar

mat:SetFloat("$c2_w", znear)
mat:SetFloat("$c3_w", zfar)
//pixel shader
float znear = Constants2.w;
float zfar = Constants3.w;
float final_depth = (1/i.Depth- 1/znear)/(1/zfar - 1/znear);  
Out.depth = final_depth;

||https://community.khronos.org/t/when-and-how-does-opengl-calculate-f-depth-depth-value/106086/32||

#

bug #2

#

so it need other formula

snow cradle
#

mat:SetFloat("$c2_w", znear-0.1)
fix this bug. idk why -0.1

snow cradle
errant nacelle
#

that's a cool hud

snow cradle
snow cradle
#
//fog
        local fogstart, fogend = render.GetFogDistances()
        fogstart = 1/(fogstart+10)
        fogend = 1/fogend

        mat:SetFloat("$c0_w", fogend)
        mat:SetFloat("$c1_w", fogstart)

        local r_fog, g_fog, b_fog = render.GetFogColor()

        local mFog = Matrix({
            {r_fog/255, 0, 0, 0},
            {g_fog/255, 0, 0, 0},
            {b_fog/255, 0, 0, 0},
            {1/1, 0, 0, 0},
        })

        mat:SetMatrix('$VIEWPROJMAT', mFog)
#
//pixel shader
const float4x4 g_viewProjMatrix : register( c11 );


//code
int PIXELFOGTYPE = PIXEL_FOG_TYPE_RANGE;

    float fogstart = Constants1.w;
    float g_WaterZ2 = 0; //PIXEL_FOG_TYPE_HEIGHT
    float fogdesity = g_viewProjMatrix[0].w;
    float fogend = Constants0.w;

    float4 g_FogParams2 = float4(fogstart, g_WaterZ2, fogdesity, fogend);

    float3 fogColor = g_viewProjMatrix[0].rgb;
    fogColor = GammaToLinear(fogColor);

    float fogFactor = CalcPixelFogFactor( PIXELFOGTYPE, g_FogParams2, EyePosition.z, wp, i.Depth );
    color.rgb = BlendPixelFog( color.rgb, fogFactor, fogColor.rgb, PIXELFOGTYPE );
snow cradle
nocturne patio
nocturne patio
snow cradle
#

@upbeat kernel thanks!

keen coral
nocturne patio
# keen coral what steps exactly have you taken to achieve this?

effects/shaders/myshader_1.vmt

screenspace_general
{
    $pixshader "2_myshader_1_ps30"
    $vertexshader "2_myshader_1_vs30"
    $basetexture "metal6"
    $cull "1"
    $fix_fb "39"
    $softwareskin "1"

    Proxies
    {
        // Fixes the material flags
        Equals
        {
            srcVar1   $fix_fb
            resultVar $flags2
        }
    }
}

vertex shader

const float4x4 cModelViewProj : register(c4);
struct VS_INPUT {
    float4 pos    : POSITION0;
    float4 normal : NORMAL0;
    float2 uv     : TEXCOORD0;
};
struct VS_OUTPUT {
    float4 projPos : POSITION;
    float2 uv      : TEXCOORD0;
    float4 depth   : TEXCOORD1;
    float4 normal  : TEXCOORD2;
};
VS_OUTPUT main( const VS_INPUT v ) {
    VS_OUTPUT output;
    output.projPos.xyzw = mul( float4( v.pos.xyz, 1.0f ), cModelViewProj );
    output.uv = v.uv.xy;
    output.depth = output.projPos;
    output.normal = v.normal;
    return output;
}

pixel shader


sampler Tex0 : register( s0 ); // $basetexture
struct PS_INPUT {
    float2 pos    : VPOS;
    float2 uv     : TEXCOORD0;
    float4 depth  : TEXCOORD1;
    float4 normal : TEXCOORD2;
};
struct PS_OUTPUT {
    float4 color : COLOR0;
    float  depth : DEPTH0;
};
PS_OUTPUT main( const PS_INPUT i ) {
    PS_OUTPUT output;
    output.color.xyz = lerp(i.normal.xyz, tex2D(Tex0, i.uv).xyz, 0.25);
    output.color.w = 1.0;
    output.depth = i.depth.z / i.depth.w;
    return output;
}

Lua

local mat = Material "effects/shaders/myshader_1"
hook.Add("HUDPaint", "test", function()
    render.WorldMaterialOverride(mat)
    render.MaterialOverride(mat)
    render.OverrideDepthEnable(true, true)
    render.RenderView { drawviewmodel = true }
    render.OverrideDepthEnable(false, false)
    render.WorldMaterialOverride()
    render.MaterialOverride()
end)
nocturne patio
cosmic perch
#

@graceful lynx i found the issue that made me use that weird uv in surface_DrawTexturedRectUV

#

notice the weird line

graceful lynx
#

Interesting. I wonder why that is

cosmic perch
#

clamping

cosmic perch
#

i didnt know i can just do this to fix this issue lol

sampler2D TexBase : register(s0) = sampler_state
{
    Filter = MIN_MAG_LINEAR_MIP_POINT, 
    AddressU = MIRROR,  
    AddressV = MIRROR
};
#

lemme test if it actually works or not

#

rip doesnt work

jovial tide
#

thats only in sm4+

cosmic perch
#

🤬

snow cradle
#

idk but depth buffer can't read depth from brushes with screenspace_shader

#

🤔

snow cradle
#

Cloud update: Added smooth fading of cloud horizon. Parameter is adjustable.

#

I also managed to compile the shader in a quality cycle on [unroll(57)].
The parameter is also now adjustable. (You can set low settings on weak PCs)

nocturne patio
#

Does anyone know if there's any way to fetch the lightmap supplied by render.SetLightmapTexture()in the shader?

misty surge
#

Maybe if you looked into all the RenderTargets being created using +mat_material list you should be able to directly request the rendertarget

upbeat kernel
#

yeah. it's probably (virtually certainly) not possible right now to do dynamically (I've been reading source code for 2 days but reserve the right to miss things in the rat's nest that is the Source engine source code), but if you know specifically what brushes you're doing it on you could export your lightmap page(s) for those specific brushes to VTF files (LDR and/or HDR), however if there are multiple pages you'll need a new VMT for each page

#

using the $flags2 trick @snow cradle mentioned it's definitely possible to pass through the UV texcoord for the correct position on said lightmap page that correlates to each brush, but getting the texture itself won't be so easy.
if you can get the LDR and HDR lightmap pages themselves in their respective VTF image formats, you can use conditional VMT statements to load either one depending on the mode the client is using:

"ldr?$texture1" "lightmap_ldr"
"hdr?$texture1" "lightmap_hdr"
#

honestly if no one's filed a request for this on garrysmod-requests yet then someone probably should; Rubat is surprisingly responsive to these

GitHub

Feature requests for Garry's Mod. Contribute to Facepunch/garrysmod-requests development by creating an account on GitHub.

#

but I would take care in considering exactly how to phrase the request, or perhaps how it should be implemented—for ease of implementation. it would probably make more sense (or be easier/quicker) for him to implement this as a Lua-rendertarget feature than a feature of screenspace_general

wispy quartz
upbeat kernel
#

what exactly

wispy quartz
#

About the lightmap stuff

upbeat kernel
#

👀

upbeat kernel
upbeat kernel
#

so is there no code examples of this?

#

those shaders, I mean. the vast majority of them rely on data everyone else here seems to be scrambling to find a way to access

#

which is why I'm somewhat confused

wispy quartz
#

the issue is that lightmaps are possible only if you intrude the c++ side

upbeat kernel
#

that's what this whole conversation began as

wispy quartz
#

well, you can though make it via adding a second mesh with modulate/etc stuff to emulate lightmaps

upbeat kernel
#

I do appreciate you making me aware of that—I wasn't aware he was working on more improvements to it

wispy quartz
#

He's working on it rn, he's struggling with flashlight/projected textures working with custom shader rn

snow cradle
#

SSAO, SMAA, Clouds, Parallax
mb SSAO must be rendered in PostDrawTranslucentRenderables hook

nocturne patio
# upbeat kernel using the `$flags2` trick <@284864428363743233> mentioned it's definitely possib...

It seems we can get specific lightmap pages according to this comment https://github.com/Facepunch/garrysmod-requests/issues/1665#issuecomment-1000996066

"$basetexture" "\[lightmap0]"
GitHub

It would be very nice if we had way of getting/replacing of lightmaps. Also Z-buffer. We already can get it but actually it would be nice if we could also change its depth/range, as it is seen on v...

upbeat kernel
#

Interesting. I wonder why the escaped backslash is crucial

nocturne patio
#

I guess it's because material system thinks brackets as a vector value

snow cradle
#

DDOF from stalker

upbeat kernel
#

so, no way to get CurrentTime in a vertex shader right now... right?

#

constants are broken?

snow cradle
upbeat kernel
#

yes that's what I'm talking about, someone earlier said it didn't work for them and I don't think it works for me either

snow cradle
#

🤔🤔🤔

rain marten
#

Unless if I'm doing something wrong, I noticed that all the $c*/const float4 Constants* variables don't update on the vertex shader. Anyone else had that happen?

I confirmed that it was only happening on the vertex shader after successfully using the same constants (with no changes on the Lua code) on the pixel shader

upbeat kernel
#

are you replying to what we were just talking about? or is that a coincidence

#

pretty sure it doesn't work for vertex shaders

upbeat kernel
#

I think they're all zeroed out

#

actually they could just be frozen like you said

#

in the situation I was testing it wouldn't be any different

rain marten
#

Welp, rip my plans
Oh and, by "don't update" I guess I just meant that they stay all zeroed

upbeat kernel
#

were you planning to make stuff jiggle around?

rain marten
#

I needed to pass a 4x4 matrix, doing some shadowmap stuff

upbeat kernel
#

I see

#

was going to recommend a stupid but functional solution like passing data via other means such as changing the render color of the object

nocturne patio
#

I think c* constants are not transferred to the vertex shader because SetVertexShaderConstant is not called but SetPixelShaderConstant is
https://github.com/SourceSDK2013Ports/csgo-src/blob/909c38385b5903d5b7ad9b15761068f33dbe27d7/src/materialsystem/stdshaders/screenspace_general.cpp#L344

pShaderAPI->SetPixelShaderConstant( 0, c0, ARRAYSIZE(c0)/4 );
// pShaderAPI->SetVertexShaderConstant( 0, c0, ARRAYSIZE(c0)/4 ); // Probably this should be here as well
GitHub

April 22nd, 2020 leak but better. Contribute to SourceSDK2013Ports/csgo-src development by creating an account on GitHub.

rain marten
#

Kinda of a bummer, it was the only thing left to do to get it working

upbeat kernel
#

wonder if this is one of the improvements @jovial tide is making to the shader code

snow cradle
#

@rain marten Have you tried working with MRT in gmod?

#

Shadows need several render targets. And it is better to output them through MRT. Without it, we will lose a lot of fps.

rain marten
# snow cradle <@451223974781779969> Have you tried working with MRT in gmod?

Maybe after I get a single shadowmap working first (although it sounds like that would require changes on the C++ side)

Although its not my first time messing with shaders, and I managed to do a basic game engine with opengl, that was almost 6 years ago so, I'm still rediscovering shaders, especially when it comes to how directx handles things

misty surge
snow cradle
#

Does the cubemap binding (in hammer) to brush faces work if the brush has a screen space general shader?

misty surge
#

If we could that would be cool, I don’t know if that’s the case but if it was that would be awesome.

snow cradle
#

ok i will try test it

shadow shuttle
#

oh hey is there a parallax map shader now

upbeat kernel
shadow shuttle
# upbeat kernel ?

Sorry I didnt put that message in a reply I meant the screenshots from Evgeny

upbeat kernel
#

lol I thought maybe that was what you were talking about
just wanted to be sure

shadow shuttle
#

yeah

upbeat kernel
#

anyone know if there's a conditional VMT parameter or something [any other means by which I could] make screenspace_general show up in the Hammer editor (or even Hammer++ specifically)? for a model
literally anything is fine, just to get it to render and not be completely invisible and require me to use wireframe view

misty surge
#

Maybe change the texture name for development, when ur ready to publish switch it back to the correct name. I don’t think hammer utilities shaders the same way the game does. Best to replace it with a null texture or a similar demo texture, and when you are done with editing that section, switch it back.

#

I use this approach for models that require internal edits, the big meshes usually block my view, so I set them to like other textures and then put them back when I’m done with editing

#

Modeling requires everything to be like a handful of meshes, so it’s difficult to combine all the stuff and push rigging, so I sort of work around the idea.

upbeat kernel
#

yeah I could probably use postcompiler to pack a different material under the same name at compile time or something

upbeat kernel
#

I believe I've arrived at a solution for some situations, but it's very limited

#

extremely limited

#

(it's still not completely done, so give me a minute)

upbeat kernel
#

does anyone know why I might not be able to get both depth input and vertex color? is there a limit to the number of texcoords

upbeat kernel
#

no matter what I do I can't get vertex color to work with vertex normal and vertex transform

snow cradle
upbeat kernel
#

this is for a model btw

misty surge
upbeat kernel
#
    $ignorez        0
    $writedepth        1
    $writealpha        1
    $depthtest        1
    $cull            1

    $vertexcolor    1
    $vertextransform    1
    $vertexnormal        1

    $softwareskin    1

// $flags2 set to 39 through proxy means
upbeat kernel
misty surge
#

Ahh, in Vulkan, we got hardware limits that’s probably why I’d assume as such. Dx9 limits it by shader version. Gotcha

misty surge
#

Moving from vulkan to Dx9 is not hard, just very different.

upbeat kernel
#

I'm starting to realize that vertex color isn't the color set on an entity

#

I knew it wasn't, vertex color is actually in the mesh itself, but for some reason I was thinking the entity's color would be accessible through vertex color

misty surge
#

It should, if I’m not mistaken, color and normals may potentially use the same memory so, they aren’t usable for both at the same time unless you declare the mesh in lua.

#

I remember having issues attributing both, in EGSM, the pipeline the meshes are being drawn, I think they “decompile” the normals, and send them inside the shader.

upbeat kernel
#

damn

#

this shit is annoying

misty surge
#

But if you use two at the same time, one takes over

upbeat kernel
misty surge
#

What you can do, is maybe set the normal data inside a img file.

#

Or the color

upbeat kernel
#

the mesh is flat; it's going to be water

#

and it also has LOD levels

misty surge
#

Right, so if you had an extra texture buff, you could just do I.uv and maybe setup a serial system to attribute pixel to color or normal.

upbeat kernel
#

hmm

misty surge
#

Maybe not as robust but it would work

upbeat kernel
#

so with the color, it's not actually color

#

I needed to pipe CurTime() into the vertex shader, but you can't use $c0_x or any of those

#

so I got to thinking, color255 has four 8-bit components, which add up to 32 bits, and a float is 32 bits

misty surge
#

Yup

#

Now you get it

upbeat kernel
#
local band, lshift, rshift = bit.band, bit.lshift, bit.rshift

-- Converts a Lua number (assumed to be representable in 32-bit IEEE 754 format)
-- into a 32-bit unsigned integer
local function floatToBits(f)
    if f == 0 then return 0 end

    -- Determine the sign bit (0 for positive, 1 for negative)
    local sign = 0
    if f < 0 then
        sign = 1
        f = -f
    end

    -- Decompose f into mantissa and exponent so that f = mantissa * 2^exponent,
    -- with mantissa in [0.5, 1)
    local mantissa, exponent = math.frexp(f)
    -- Adjust so we have a normalized fraction:
    -- In IEEE 754, f = (1 + fraction) * 2^(exponent-1)
    exponent = exponent - 1
    -- Remove the implicit leading 1 and scale mantissa to [0,1)
    mantissa = mantissa * 2 - 1

    -- Calculate exponent bits (with bias 127)
    local exp_bits = exponent + 127
    -- NOTE: This approach does not handle all edge cases like subnormals precisely

    -- Compute 23-bit fraction from the mantissa
    local mantissa_bits = math.floor(mantissa * 8388608 --[[(2^23)]] + .5)

    -- Combine sign, exponent, and mantissa into a 32-bit value
    -- Bit layout: [sign:1 | exp:8 | mantissa:23]
    local bits = bit.bor(
        lshift(sign, 31),
        lshift(exp_bits, 23),
        mantissa_bits
    )

    return bits
end

-- Extract the four 8-bit channels (R, G, B, A) from a 32-bit number
local function bitsToRGBA(bits)
    local r = band(bits, 0xFF)
    local g = band(rshift(bits, 8), 0xFF)
    local b = band(rshift(bits, 16), 0xFF)
    local a = band(rshift(bits, 24), 0xFF)
    return r, g, b, a
end

-- Combines the two functions to pack a float into four 8-bit channels
local function packFloatToRGBA(f)
    local bits = floatToBits(f)
    return bitsToRGBA(bits)
end
#

and then I combined it into this monstrosity for lua_run:

local a,b,c=bit.band,bit.lshift,bit.rshift;local function d(e)if e==0 then return 0 end;local f=0;if e<0 then f=1;e=-e end;local g,h=math.frexp(e)h=h-1;g=g*2-1;local i=h+127;local j=math.floor(g*8388608+.5)local k=bit.bor(b(f,31),b(i,23),j)return k end;local function l(k)local m=a(k,0xFF)local n=a(c(k,8),0xFF)local o=a(c(k,16),0xFF)local p=a(c(k,24),0xFF)return m,n,o,p end;local function q(e)local k=d(e)return l(k)end;local r=[[water]]local s=.05;local t=ents.FindByName(r)local u=[[Tick]]local v=[[piqey.Water.Advance]]local w=Color(0,0,0)hook.Add(u,v,function()if#t<1 then hook.Remove(u,v)return end;w:SetUnpacked(q(s*CurTime()))for x,y in ipairs(t)do y:SetColor(w)end;print([[Set channels:]],w,w:ToVector():Dot(Vector(1/0x1000000,1/0x10000,1/0x100)))end)```
misty surge
#

If it were me, and I wanted an optimized solution I’d go with generating the texture for color via a simple texture.

For vertex Curtime situation, you can maybe pass the data using the matrix data we got. That should be passed in the vertex shader (idk)

upbeat kernel
#

so I'll probably write it to a render target that is a single pixel

#

and do the same solution

misty surge
#

This would work for color, but not CurTime. I think you can just use the inverse view matrix

upbeat kernel
#

it works for curtime using the solution I wrote

#

I think

misty surge
#

Test and see, if it does, fantastic

upbeat kernel
#

the only problem I foresee is that Shader Model 3.0 doesn't support bit shifting and asfloat (those features were added in 4.0 I think), so I have to use a 4D dot for an approximation, and I don't actually know exactly how bad the offset is

misty surge
#

Hmm, that could work, but yeah dot might have issues, if your input for the check isn’t standardized for all the verticies

upbeat kernel
#

wait I could also just use RGBA16161616f for the image format and write the float directly LOL

#

no wait

#

that's 16

misty surge
#

Honestly, you should just stick with the format with R16 maybe so it’s 1:1

upbeat kernel
#

?

#

I've already written the code to split it up into four 8-bit parts, so I'm going to at least try it with BGRA8888 first

misty surge
#

Copy

upbeat kernel
#

I just need to write a crappy mantle to mount it on client with lua_run first, but I already have one written for something else so I need to transpose it

misty surge
#

Like the depth target, one channel verses 4 is more optimized but yeah

#

You guys are provoking me to go back to shaders lol. I am nearly done modeling my space ship, with rigging. Next is to texture it. Then maybe revisit it.

upbeat kernel
#

post (or dm) pics pls

#

I am a spaceship enthusiast

misty surge
#

Sure, I’ll DM it because I want people to be surprised

upbeat kernel
#

I will show you my spaceship

misty surge
#

I will say this, rigging is probably the hardest when you gotta go inside the mesh to do it. Crazy stuff, takes days to rig it up because of how many layers it has lol

#

One mesh for an entire ship is crazy, but source freaks out if it’s not stacked into one big mesh

snow cradle
#

idk why but i have black texture using env_cubemap is screen space general.

#

if i write cubemaps like that, it works $texture2 "maps\cubemaptest_d\c0_0_32"

#

and this: $texture2 "env_cubemap"

#

u also use this: $flags2 55 (proxy - 7 + 16 + 32) MATERIAL_VAR2_LIGHTING_MASK + MATERIAL_VAR2_NEEDS_TANGENT_SPACES + MATERIAL_VAR2_USES_ENV_CUBEMAP

#

mb env_cubemap use defaultcubemap? this is black by default

misty surge
#

Maybe I’m wrong but, if it’s not showing up, I always thought that env_cubemap was actually the other env cubemaps but they were not selected during runtime, the closest env cube. It itself is not a texture or anything, rather it selects the closest cubemap.

upbeat kernel
# misty surge Maybe I’m wrong but, if it’s not showing up, I always thought that env_cubemap w...

@snow cradle I don't know exactly how it works for VertexLitGeneric, but I think when you use "env_cubemap" in a VMT it actually just inserts the closest one at runtime. with LightmappedGeneric, however, VBSP actually generates and packs into the BSP a new VMT file variant for each VMT in use that contains "env_cubemap" with the new cubemap texture string inserted in place of that old string. that's why renaming a BSP post-compile breaks cubemaps—all the brush materials reference the cubemap textures by name, which has the original BSP filename in plaintext

#

I don't know if that changes anything in this situation, I'm sort of dropping in late here.

snow cradle
#

@upbeat kernel @misty surge
we can use proxy and have fancy $tex and float names for our shaders:

my vmt:

screenspace_general
{
    $pixshader         "parallax_mapping003_ps30"
    $vertexshader         "parallax_mapping31_vs30"

    $baseTexture        "murmansk/tiles/CeramicTiles02_a"
    $bumpmap        "murmansk/tiles/CeramicTiles02_ns" 
    $envmap            "maps\cubemaptest_d\c0_0_32"//"env_cubemap"

    $parallaxmapscale        "0.01"
    $parallaxcenter        "0"

    $surfaceprop        "tile"
    $test_flags2 39

    $DEPTHTEST 1
    $translucent 1
    $softwareskin 1
    $VertexColor 1
    $VERTEXNORMAL 1

    Proxies
    {
        Equals {
            srcVar1    $test_flags2
            resultVar    $flags2
        }
        ParallaxSetup {
            resultVar $c0_y
        }
    }
}
#

result: bumps and cubemap (manual) works

#

i think we can write technical params to proxy. This is how you can make life easier for the user.
Hide everything unnecessary for future users

misty surge
#

Can we get this in GitHub format for the wiki?

#

That would be amazing for everyone

shadow shuttle
snow cradle
#

default

shadow shuttle
#

okay

hollow arrow
analog burrow
#

Omggg you need to publish it !! pepeFancy

hollow arrow
#

crazyyy

shadow shuttle
snow cradle
#

@misty surge @upbeat kernel idk why: render.GetResolvedFullFrameDepth() cant get depth from brushes (2 screen - white floor) with screenspace_general. but custom depth buffer works fine (1 screen)

maybe if need some flags or params like //$multipass 1 or //$opaquetexture 1 etc?

I just wanna use DDOF shader on default depth buffer for saving FPS,

upbeat kernel
snow cradle
# shadow shuttle 💎 good work will you publish it soon

Yes, I will publish it along with materials, test maps and settings output. I need to make sure everything works and work on stability and preserving default settings.

I will also write a guide on how to use it and all the pitfalls: manual creation of duplicates of materials for work parallax cubemap - a guide for mappers.

shadow shuttle
#

you are very good 👍

snow cradle
rain marten
#

as in, it seems like we can't use those to pass custom matrices to the vertex shader

snow cradle
#

i wanna also make _rt worldpos + depth in .a. but it have bugs with render order... hmmm......

upbeat kernel
#

I'm pretty sure literally nothing works for vertex shaders. even textures

snow cradle
#

soooo yea\

#

fixed

#

worldpos finaly

#

@nocturne patio

#

code looks like that

#

shader:

#

no grass when u use IMAGE_FORMAT_RGBA16161616F

#
RT_WPNDepth =  GetRenderTargetEx(rt_name, ScrW(), ScrH(),
    -1,
    0,
    bit.bor(16, 256, 512, 65536, 32768),
    0,
    IMAGE_FORMAT_RGBA16161616F
)
#

so a little

ionic talon
snow cradle
#

how to disable grass

#

decals

#

sprites

#

idk

#

mb i need

#

other hook

#

idk

#

i just mul znear zfar

#

then worldpos render order > grass, decals render order

#

no effects

#

on rt

#

but tranclusent props disappear when they idle

#

skybox support

hollow arrow
# snow cradle

excuse my ignorance but what's the point of doing that colors ? I'm really curious of what it is

snow cradle
#

Many post processing shaders need these rt. And also the depth buffer and world normals.

snow cradle
#

🤔🤔🤔pistol broken

blissful laurel
#

i don't undestand why screenspace shader breaks when drawing it on screen from lua but not when using r_screenoverlay. i looked at evgeny's lua and source sdk, it is nearly identical but it still results in the broken quad, what am i doing wrong?

#

here's my render code btw

local screentexture = render.GetScreenEffectTexture()
material:SetTexture( "$basetexture", render.GetScreenEffectTexture() )
local function DrawAgX()
    render.UpdateScreenEffectTexture()
        render.CopyRenderTargetToTexture(screentexture)
    render.SetMaterial( material )
    render.DrawScreenQuad()
end

hook.Add( "RenderScreenspaceEffects", "RenderAgX", function()
    if ( !pp_agx:GetBool() ) then return end
    if ( !GAMEMODE:PostProcessPermitted( "agx" ) ) then return end
    DrawAgX()
end )
snow cradle
#

this: $basetexture "_rt_FullFrameFB"

#

or
render.GetScreenEffectTexture(1)
render.UpdateScreenEffectTexture(1)

lunar folio
# blissful laurel here's my render code btw ```lua local screentexture = render.GetScreenEffectTex...
        cam.Start2D()
        surface.SetMaterial(shaderMaterial)
        surface.SetDrawColor(255, 255, 255, 255)
        surface.DrawTexturedRectUV( -1, -1, 2, 2, 0, 1, 1, 0 )
        cam.End2D()

Do that in RenderScreenspaceEffects, no need to do material:SetTexture( "$basetexture", render.GetScreenEffectTexture() ) or anything either.

Just make sure your shader vmt has this as the basetex as stated above:
$basetexture "_rt_FullFrameFB"

snow cradle
#

💀💀💀💀💀💀💀

nocturne patio
# snow cradle code looks like that

It seems correct but it didn't fix the render order issue on my end. Could you try drawing vertex normal as the color, instead of vertex coordinates?

snow cradle
snow cradle
blissful laurel
#

but why does render.DrawScreenQuad() work for everyone but me?

nocturne patio
# snow cradle

I tried myself for a while but I still can't get it to work. Could you provide the vertex shader and parameters for the RenderTarget?

graceful lynx
blissful laurel
snow cradle
#

32 bit render target ( @misty surge's tip):

local rt_name = "_rt_WPNDepth"
RT_WPNDepth =  GetRenderTargetEx(rt_name, ScrW(), ScrH(),
    RT_SIZE_NO_CHANGE,
    MATERIAL_RT_DEPTH_SHARED,
    bit.bor(2, 16, 256, 512, 65536, 32768), -- u can use your flags
    0,
    29 --32 bit rt IMAGE_FORMAT_RGBA32323232F
)
#

mb u can write like that

IMAGE_FORMAT_RGBA32323232F = 29
local rt_name = "_rt_WPNDepth"
RT_WPNDepth =  GetRenderTargetEx(rt_name, ScrW(), ScrH(),
    RT_SIZE_NO_CHANGE,
    MATERIAL_RT_DEPTH_SHARED,
    bit.bor(2, 16, 256, 512, 65536, 32768), -- u can use your flags
    0,
    IMAGE_FORMAT_RGBA32323232F
)
shadow shuttle
#

what is going on

timid pumice
#

What's balling my dudes

snow cradle
#

@exotic willow's info about IMAGE_FORMAT

Here's the modified array with sequential numbering starting from -1:

static ImageFormatInfo_t g_ImageFormatInfo[] =
{
  /* -1 */ { "UNKNOWN",          0, 0, 0, 0, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_UNKNOWN,
  /* 0 */ { "RGBA8888",          4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_RGBA8888,
  /* 1 */ { "ABGR8888",          4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_ABGR8888, 
  /* 2 */ { "RGB888",            3, 8, 8, 8, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_RGB888,
  /* 3 */ { "BGR888",            3, 8, 8, 8, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_BGR888,
  /* 4 */ { "RGB565",            2, 5, 6, 5, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_RGB565, 
  /* 5 */ { "I8",              1, 0, 0, 0, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_I8,
  /* 6 */ { "IA88",            2, 0, 0, 0, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_IA88
  /* 7 */ { "P8",              1, 0, 0, 0, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_P8
  /* 8 */ { "A8",              1, 0, 0, 0, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_A8
  /* 9 */ { "RGB888_BLUESCREEN",      3, 8, 8, 8, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_RGB888_BLUESCREEN
#
  /* 10 */ { "BGR888_BLUESCREEN",      3, 8, 8, 8, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_BGR888_BLUESCREEN
  /* 11 */ { "ARGB8888",          4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_ARGB8888
  /* 12 */ { "BGRA8888",          4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_BGRA8888
  /* 13 */ { "DXT1",            0, 0, 0, 0, 0, 0, 0, true, false, false },    // IMAGE_FORMAT_DXT1
  /* 14 */ { "DXT3",            0, 0, 0, 0, 8, 0, 0, true, false, false },    // IMAGE_FORMAT_DXT3
  /* 15 */ { "DXT5",            0, 0, 0, 0, 8, 0, 0, true, false, false },    // IMAGE_FORMAT_DXT5
  /* 16 */ { "BGRX8888",          4, 8, 8, 8, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_BGRX8888
  /* 17 */ { "BGR565",            2, 5, 6, 5, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_BGR565
  /* 18 */ { "BGRX5551",          2, 5, 5, 5, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_BGRX5551
  /* 19 */ { "BGRA4444",          2, 4, 4, 4, 4, 0, 0, false, false, false },    // IMAGE_FORMAT_BGRA4444
  /* 20 */ { "DXT1_ONEBITALPHA",      0, 0, 0, 0, 0, 0, 0, true, false, false },    // IMAGE_FORMAT_DXT1_ONEBITALPHA
  /* 21 */ { "BGRA5551",          2, 5, 5, 5, 1, 0, 0, false, false, false },    // IMAGE_FORMAT_BGRA5551
  /* 22 */ { "UV88",            2, 8, 8, 0, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_UV88
  /* 23 */ { "UVWQ8888",          4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_UVWQ8888
  /* 24 */ { "RGBA16161616F",        8, 16, 16, 16, 16, 0, 0, false, true, false },  // IMAGE_FORMAT_RGBA16161616F
  /* 25 */ { "RGBA16161616",        8, 16, 16, 16, 16, 0, 0, false, false, false },  // IMAGE_FORMAT_RGBA16161616
  /* 26 */ { "UVLX8888",          4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_UVLX8888
  /* 27 */ { "R32F",            4, 32, 0, 0, 0, 0, 0, false, true, false },    // IMAGE_FORMAT_R32F
 
#
 /* 28 */ { "RGB323232F",          12, 32, 32, 32, 0, 0, 0, false, true, false },  // IMAGE_FORMAT_RGB323232F
  /* 29 */ { "RGBA32323232F",        16, 32, 32, 32, 32, 0, 0, false, true, false },  // IMAGE_FORMAT_RGBA32323232F
  /* 30 */ { "RG1616F",          4, 16, 16, 0, 0, 0, 0, false, true, false },  // IMAGE_FORMAT_RG1616F
  /* 31 */ { "RG3232F",          8, 32, 32, 0, 0, 0, 0, false, true, false },  // IMAGE_FORMAT_RG3232F
  /* 32 */ { "RGBX8888",          4, 8, 8, 8, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_RGBX8888

  /* 33 */ { "NV_NULL",          4,  8, 8, 8, 8, 0, 0, false, false, false },  // IMAGE_FORMAT_NV_NULL
#
 // Vendor-dependent compressed formats typically used for normal map compression
  /* 34 */ { "ATI1N",            0, 0, 0, 0, 0, 0, 0, true, false, false },    // IMAGE_FORMAT_ATI1N
  /* 35 */ { "ATI2N",            0, 0, 0, 0, 0, 0, 0, true, false, false },    // IMAGE_FORMAT_ATI2N

  /* 36 */ { "RGBA1010102",        4, 10, 10, 10, 2, 0, 0, false, false, false },  // IMAGE_FORMAT_RGBA1010102
  /* 37 */ { "BGRA1010102",        4, 10, 10, 10, 2, 0, 0, false, false, false },  // IMAGE_FORMAT_BGRA1010102
  /* 38 */ { "R16F",            2, 16, 0, 0, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_R16F

  // Vendor-dependent depth formats used for shadow depth mapping
  /* 39 */ { "D16",            2, 0, 0, 0, 0, 16, 0, false, false, true },    // IMAGE_FORMAT_D16
  /* 40 */ { "D15S1",            2, 0, 0, 0, 0, 15, 1, false, false, true },    // IMAGE_FORMAT_D15S1
  /* 41 */ { "D32",            4, 0, 0, 0, 0, 32, 0, false, false, true },    // IMAGE_FORMAT_D32
#
  /* 42 */ { "D24S8",            4, 0, 0, 0, 0, 24, 8, false, false, true },    // IMAGE_FORMAT_D24S8
  /* 43 */ { "LINEAR_D24S8",        4, 0, 0, 0, 0, 24, 8, false, false, true },    // IMAGE_FORMAT_LINEAR_D24S8
  /* 44 */ { "D24X8",            4, 0, 0, 0, 0, 24, 0, false, false, true },    // IMAGE_FORMAT_D24X8
  /* 45 */ { "D24X4S4",          4, 0, 0, 0, 0, 24, 4, false, false, true },    // IMAGE_FORMAT_D24X4S4
  /* 46 */ { "D24FS8",            4, 0, 0, 0, 0, 24, 8, false, false, true },    // IMAGE_FORMAT_D24FS8
  /* 47 */ { "D16_SHADOW",          2, 0, 0, 0, 0, 16, 0, false, false, true },    // IMAGE_FORMAT_D16_SHADOW
  /* 48 */ { "D24X8_SHADOW",        4, 0, 0, 0, 0, 24, 0, false, false, true },    // IMAGE_FORMAT_D24X8_SHADOW

  /* 49 */ { "LINEAR_BGRX8888",      4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_LINEAR_BGRX8888
  /* 50 */ { "LINEAR_RGBA8888",      4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_LINEAR_RGBA8888
  /* 51 */ { "LINEAR_ABGR8888",      4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_LINEAR_ABGR8888
  /* 52 */ { "LINEAR_ARGB8888",      4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_LINEAR_ARGB8888
  /* 53 */ { "LINEAR_BGRA8888",      4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_LINEAR_BGRA8888
  /* 54 */ { "LINEAR_RGB888",        3, 8, 8, 8, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_LINEAR_RGB888
  /* 55 */ { "LINEAR_BGR888",        3, 8, 8, 8, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_LINEAR_BGR888
  /* 56 */ { "LINEAR_BGRX5551",      2, 5, 5, 5, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_LINEAR_BGRX5551
  /* 57 */ { "LINEAR_I8",          1, 0, 0, 0, 0, 0, 0, false, false, false },    // IMAGE_FORMAT_LINEAR_I8
  
#
/* 58 */ { "LINEAR_RGBA16161616",    8, 16, 16, 16, 16, 0, 0, false, false, false },  // IMAGE_FORMAT_LINEAR_RGBA16161616
  /* 59 */ { "LINEAR_A8",          1, 0, 0, 0, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_LINEAR_A8
  /* 60 */ { "LINEAR_DXT1",        0, 0, 0, 0, 0, 0, 0, true, false, false },    // IMAGE_FORMAT_LINEAR_DXT1
  /* 61 */ { "LINEAR_DXT3",        0, 0, 0, 0, 8, 0, 0, true, false, false },    // IMAGE_FORMAT_LINEAR_DXT3
  /* 62 */ { "LINEAR_DXT5",        0, 0, 0, 0, 8, 0, 0, true, false, false },    // IMAGE_FORMAT_LINEAR_DXT5

  /* 63 */ { "LE_BGRX8888",        4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_LE_BGRX8888
  /* 64 */ { "LE_BGRA8888",        4, 8, 8, 8, 8, 0, 0, false, false, false },    // IMAGE_FORMAT_LE_BGRA8888

  /* 65 */ { "DXT1_RUNTIME",        0, 0, 0, 0, 0, 0, 0, true, false, false },    // IMAGE_FORMAT_DXT1_RUNTIME
  /* 66 */ { "DXT5_RUNTIME",        0, 0, 0, 0, 8, 0, 0, true, false, false },    // IMAGE_FORMAT_DXT5_RUNTIME

  // Vendor-dependent depth formats used for resolving
  /* 67 */ { "INTZ",            4, 0, 0, 0, 0, 24, 8, false, false, true},    // IMAGE_FORMAT_INTZ
};
#

@misty surge

misty surge
#

That’s awesomeee

#

I gotta update the example when I have more time. I’d also like to get a working example of the env cubes too

wispy birch
#

why not use R32F

misty surge
#

That breaks the depth afaik. I tried that first

wispy birch
#

RGBA32323232F is veeery wasteful

snow cradle
#

For some reason, some models are not supported by the shader
but other models works

timid pumice
#

Are you guys solving the z depth being so stepped/short? I have seen you guys playing with alpha blending and image formats

#

It brings me z depth nightmares randomly occurring until I found out it was related to msaa, then the rabbit hole of rendering techniques kicked in

snow cradle
timid pumice
#

Oh noes it was a year ago, i was trying to draw bloom over an entity with z clipping, and NOTHING fucking worked if msaa was on, it was playing with depth and image formats for the RT which I see you guys managed to get 32F

#

I didn't even know that was available on source 💀

timid pumice
lime trellis
#

I always wondered if you could achieve a playermodel or something to have this cartoonish look, its like mixed media 2d into 3d model, I don't really know how fortnite or other games achieve this look, its probably some type of shader

#

keeping those outlines on different views is very cool

#

oh nvm i guess u can do this i just dont know how

#

oh i understand now kind of, they use a vmt called outline that uses the $lightwarptexture parameter

short dirge
#

$lightwarp doesn't do anything there

#

that's just to modify the way it's colored in, not the outline

lime trellis
#

oh ok

#

ty i was wondering what magic they were using

snow cradle
misty surge
#

Unrelated to shaders, I got my car back after a whole month. I ended up fixing it myself. Yay for me!!

untold hatch
#

How many print statements did it take to debug the car?

finite quarry
#

put a pixel shader on ur car

timid pumice
misty surge
calm root
snow cradle
cosmic perch
#

this looks really cool

#

have u released any of these to workshop yet?

#

would probably go viral if u did

snow cradle
#
hook.Add(PHYSICAL_SKY and "PostDrawPhysicalSky" or "PostDraw2DSkyBox", shaderName, RenderVolumetricClouds)
cosmic perch
#

damn nice

snow cradle
cosmic perch
#

would be cool if it auto runs, as gmod's AA stopped working for some unknown reason with 2d

#

not all 2d

snow cradle
snow cradle
snow cradle
shadow shuttle
#

very beautiful

snow cradle
sacred jackal
#

Are there already some shaders on the workshop?

obsidian merlin
snow cradle
#

🤔🤔🤔🤔

snow cradle
#

Does anyone have a function for rendering cubemap textures in rendertarget?

snow cradle
#

real time cubemap

local shaderName = "RealtimeCubemap"
local cubemap_size = 64
local rt_name = "_rt_RealtimeCubemap"
local rt_w,rt_h = cubemap_size*3, cubemap_size*4
local rt_RealtimeCubemap = GetRenderTargetEx(rt_name, rt_w,rt_h,
    RT_SIZE_NO_CHANGE,
    MATERIAL_RT_DEPTH_SEPARATE,
    bit.bor(32768,2,4,8,1024,512,1024), --2048 16384
    CREATERENDERTARGETFLAGS_HDR,
    IMAGE_FORMAT_RGB888
)

local angs = {
    angle_zero, --front
    Angle(0, 90, 0), --left
    Angle(0, 180, 180), --back
    Angle(0, 270, 0), --right
    Angle(-90, 0, 0), --up
    Angle(90, 0, 0)  --down
}

local poses = {
    {x = 1*cubemap_size, y = 1*cubemap_size}, --front
    {x = 0*cubemap_size, y = 1*cubemap_size}, --left
    {x = 1*cubemap_size, y = 3*cubemap_size}, --back
    {x = 2*cubemap_size, y = 1*cubemap_size}, --right
    {x = 1*cubemap_size, y = 0*cubemap_size}, --up
    {x = 1*cubemap_size, y = 2*cubemap_size}, --down
}

local w,h = cubemap_size*3, cubemap_size*4
local m = 2


local view_data = {
    origin = vector_origin,
    x = 0, y = 0,
    w = cubemap_size, h = cubemap_size,
    aspectratio = 1,
    drawhud = false,
    drawviewmodel = false,
    dopostprocess = false,
    angles = 0,
    fov = 90,
}

local RenderView = render.RenderView
local PushRenderTarget = render.PushRenderTarget
local PopRenderTarget = render.PopRenderTarget

hook.Add("RenderScreenspaceEffects", shaderName, function()
    view_data.origin = EyePos()

    for i = 1,6 do
        view_data.x, view_data.y = poses[i].x, poses[i].y
        view_data.angles = angs[i]

        PushRenderTarget(rt_RealtimeCubemap, 0, 0, cubemap_size, cubemap_size)
            RenderView(view_data)
        PopRenderTarget()
    end
end)

hook.Add("HUDPaint", shaderName, function()
    render.DrawTextureToScreenRect(rt_RealtimeCubemap, 0, 0, rt_w*m, rt_h*m)
end)    
lunar sinew
#

what, am i dreaming? is this real?

hollow arrow
snow cradle
short dirge
#

only case that wouldn't be true is if there are no materials in the scene using env_cubemap, and that's... fairly rare

#

can probably reduce the resolution of the captures if the scene's normal maps are rough/invisible enough, accounting for inverted facing direction & dot product from viewpoint

#

that's about it

#

probably not very performant to calculate minimum roughness of individual textures, but that can be cached. (or even more/less performant than just not having the resolution switch for the scene, idk)

#

if you want to be fancy, you might even smoothly transition between resolutions over time, such as based on player camera movement (or use movement to temporarily disable creating new cubemaps, but this will lag behind the view slightly)

graceful lynx
#

Can these cubemap textures be used as a replacement for pre-rendered cubemaps without requiring a custom shader?

#

I believe I recall someone saying that cubemaps cannot be replaced via lua

timid pumice
cosmic perch
#

prob to make it obvious that its using bitflags or guy's so used to it

timid pumice
#

i want my | back