You've probably all seen this thing, its still really incomplete but I felt a lot of people probably want to mess around with it
[b]Samplers are currently broken and crash the game, this might be because I'm using Source 2007 interfaces, in any case, this means no textures untill I figure it out[/b]
[b]Also note that this is massivly incomplete, I'm gonna add new features soon[/b]
To business:
Source: [url]https://dl.dropbox.com/u/4838268/gmcl_shader.zip[/url]
Bin: [url]https://dl.dropbox.com/u/4838268/gmcl_shader_win32.dll[/url]
The only function is shader.Create, takes a table with
[lua]
Name = "Shader Name Here", Params = {
{"$example", SHADER_PARAM_TYPE_FLOAT, "0"},
},
Passes = {
{ -- First pass
VSH = "gmodscreenspace_vs20",
PSH = "pixelshader",
PSHConsts = {
[1] = "$example",
}
VSHConsts = {
[1] = "$example",
}
},
{ -- Second pass
VSH = "gmodscreenspace_vs20",
PSH = "anotherpixelshader",
}
}
[/lua]
Additionally, these enums exist for material parameters
SHADER_PARAM_TYPE_TEXTURE
SHADER_PARAM_TYPE_INTEGER
SHADER_PARAM_TYPE_COLOR
SHADER_PARAM_TYPE_VEC2
SHADER_PARAM_TYPE_VEC3
SHADER_PARAM_TYPE_VEC4
SHADER_PARAM_TYPE_FLOAT
SHADER_PARAM_TYPE_BOOL
SHADER_PARAM_TYPE_MATRIX
SHADER_PARAM_TYPE_MATERIAL
SHADER_PARAM_TYPE_STRING
Example:
(Lua code)
[lua]
require"shader"
shader.Create{
Name = "JuliaSet",
Params = {
{"$seed", SHADER_PARAM_TYPE_VEC2, "[0, 0]"},
},
Passes = {
{
VSH = "gmodscreenspace_vs20",
PSH = "juliaset",
PSHConsts = {
[1] = "$seed",
}
}
}
}
mat = CreateMaterial("JuliaSet", "JuliaSet", {
["$seed"] = "[0 0]",
})
hook.Add("HUDPaint", "test", function()
mat:SetVector("$seed", Vector(math.cos(CurTime() * 0.5), math.sin(CurTime() * 0.3), 0))
surface.SetMaterial(mat)
surface.SetDrawColor(Color(255, 255, 255))
surface.DrawTexturedRect(0, 0, 500, 500)
end)
[/lua]
(HLSL, totally not shamelessly stolen)
[code]struct PS_INPUT
{
float2 texCoord : TEXCOORD0;
};
float2 seed : register (c0);
float4 main(PS_INPUT i) : COLOR
{
float2 v = (i.texCoord - 0.5) * 3.0;
float m = 0;
const float r = 5;
for (int n = 0; n < 15; n++)
{
v = float2(v.x * v.x - v.y * v.y, v.x * v.y * 2) + seed;
if (dot(v, v) < (r*r - 1))
m++;
v = clamp(v, -r, r);
}
if (m == 15)
return 0;
else
return float4(sin(m/4), sin(m/5), sin(m/7), 1) / 4 + 0.75;
}[/code]
(Result)
[vid]https://dl.dropbox.com/u/4838268/gm_flatgrass%202012-11-10%2015-57-01.webm[/vid]
To compile your own shader, you need fxc.exe from the DirectX SDK, for convinience, heres a direct download for it:
[url]https://dl.dropbox.com/u/4838268/fxc.exe[/url]
Additionally, you need to pack the compiled shaders into a .VCS file, you can use my vcspack utility for this:
[url]https://dl.dropbox.com/u/4838268/vcspack.exe[/url]
Compiling a pixel shader and packing it:
[code]fxc.exe /Emain /Fojuliaset.fxo /Tps_2_b juliaset.fx
vcspack.exe juliaset.fxo
move out.vcs psh\juliaset.vcs[/code]
[b]Note: I havent properly tested vertex shaders yet, but the difference between a vertex shader and a pixel shader in my code is miniscule[/b]
[b]Note: Vertex shader constants start at constant register 48[/b]
This is totally awesome.
I did consider doing something similar - with automatically compiling HLSL.. but the shader system is so mammoth, and I didn't wnat features to not work on OSX.. I am impressed you've managed to do anything!
I'm fairly sure this should work on OSX if the developer bothers to compile the shaders for it
It uses GLSL right? Not totally sure how that goes into the container format (I'm guessing that the VCS files just contain the shader source or something)
Maybe if you just made it look for x_mac.vcs files you could do something like this with OSX support
GLSL yeah, but then coders would have to make shaders for both shaderlangs.
You could just use this, its based on something ATi made
[url]https://github.com/aras-p/hlsl2glslfork[/url]
[editline]10th November 2012[/editline]
This is actually apparently what Unity uses for its mobile/Linux support
That's pretty cool.
I'm gonna look into shaders from source now, with that possibly built in as a test thing
I'm really hoping for this to be eventually implemented into GMod, the possibilities are endless
Now if only we had a OpenCL module!
That would be really useless but really cool
This is completely useless :frown:
[QUOTE=Map in a box;38397733]This is completely useless :frown:[/QUOTE]
You must have no idea of the shit you can do with this once I get samplers working, I think I need to get a hold of the source 2009 headers for that though
[QUOTE=Map in a box;38397733]This is completely useless :frown:[/QUOTE]
My collection of post process effect shaders disagrees.
[QUOTE=Legend286;38398187]My collection of post process effect shaders disagrees.[/QUOTE]
And my collection of OpenCL scripts disagrees too :(
What would you use OpenCL for in gmod tho?
[QUOTE=garry;38396931]This is totally awesome.
I did consider doing something similar - with automatically compiling HLSL.. but the shader system is so mammoth, and I didn't wnat features to not work on OSX.. I am impressed you've managed to do anything![/QUOTE]
Tobba was talking about the shaders and the limitless possibilities with me a couple days ago. You should totally add them to Gmod!!
He's a fucking genius.
[QUOTE=Lexic;38398335]What would you use OpenCL for in gmod tho?[/QUOTE]
The same reason you'd use opencl everywhere else
[QUOTE=Map in a box;38397462]Now if only we had a OpenCL module![/QUOTE]
I'm giving my babies for this (bear in mind I have no children).
With the OSX/Linux versions it automatically converts the compiled hlsl into glsl (it uses the same shader files as the pc).
Thats pretty awesome, if thats the case, just using precompiled HLSL would be portable wouldent it?
Does that mean this can actually happen?
Assuming that the texture crashing is a header issue, which it appears to be, then this being intergrated into GMod would be absolutely fantastic, right now its really limited due to the lack of textures
Pre-compiled HLSL would work. It seems like it'd hit issues with transporting the shader bytecode (would it be encoded in the lua files??).
Kind of seems in the long run that it'd be better/cleaner to have a system that lets you download the shader files, then a safe api to create the shader class - instead of having to distribute a shader dll alongside it.
That is assuming that there's absolutely no kind of security risk in servers ending shader files to clients and then running them - which I can't imagine there would be - because it's running on the GPU?
Theres pretty much no security risk in allowing custom shaders to be loaded, they're just bytecode thats uploaded to the GPU
There's only really a risk of graphics "corruption" if you do some nasty ASM stuff, but I doubt the majority of server owners are smart enough to do that.
[QUOTE=Legend286;38399483]There's only really a risk of graphics "corruption" if you do some nasty ASM stuff, but I doubt the majority of server owners are smart enough to do that.[/QUOTE]
render.StartBeam()
[IMG]http://dl.dropbox.com/u/4838268/ZScreen/2012-11/Screenshot-2012-11-10_23.36.34.png[/IMG]
[QUOTE=garry;38399356]Pre-compiled HLSL would work. It seems like it'd hit issues with transporting the shader bytecode (would it be encoded in the lua files??).
Kind of seems in the long run that it'd be better/cleaner to have a system that lets you download the shader files, then a safe api to create the shader class - instead of having to distribute a shader dll alongside it.
That is assuming that there's absolutely no kind of security risk in servers ending shader files to clients and then running them - which I can't imagine there would be - because it's running on the GPU?[/QUOTE]
It would still be better if you could compile the shaders in game, would
a) motivate more people to create shaders
b) Allow faster development
c) Easier to use
[QUOTE=Wizard of Ass;38400341]It would still be better if you could compile the shaders in game, would
a) motivate more people to create shaders
b) Allow faster development
c) Easier to use[/QUOTE]
You have no idea how hard it is to do this
It would have to do some really blatant hacking into the shader system, it would be an even bigger soup on OSX
Can you make a shader editor with this?
[editline]10th November 2012[/editline]
As in, you should embed a compiler
[QUOTE=Map in a box;38398659]The same reason you'd use opencl everywhere else[/QUOTE]
Bitcoin mining? Calculating PI? Rasterisation toys?
I can't think of anything that would be easier to do in GMod w/ OpenCL than it would outside which is why I asked. You clearly have some kind of use-case in mind since you asked for it.
Tobba is my hero now to even get garry to mention the word shader! I hope you guys can work together to get something like this native into garrysmod.
[QUOTE=Lexic;38409812]Bitcoin mining? Calculating PI? Rasterisation toys?
I can't think of anything that would be easier to do in GMod w/ OpenCL than it would outside which is why I asked. You clearly have some kind of use-case in mind since you asked for it.[/QUOTE]
Since you don't get it, for intensive calculations. This module could technically be a rasterization toy
Sorry, you need to Log In to post a reply to this thread.