Sign in to follow this  

[Tutorial] How To Create A Custom Shader

Recommended Posts

Hornete    15569
2 hours ago, IronHunter said:

How does one extract shader code from existing shader files?
As that would be really helpful as reference material.

Aah! I can't believe I forgot to mention how to find the existing shader code haha.

You can find all of the game's shader files in this directory.

C:\Program Files (x86)\Steam\steamapps\common\Don't Starve Together\data\databundles\\shaders


You should see something like this. 

The first half-ish of the file is the vertex shader.

And the 2nd half-ish of the file is the pixel shader!(As indicated by "" at the top there

Hope that helps


3 hours ago, Cunning fox said:

Will it work for UI? I'd want to make something similar to summer shader that distorts the image, will it work for images too?

Yup! It should work for ui. You can check out the overheat shader to see how they did the vertex and pixel shaders for that.

Looking at the heatover widget the shader is applied to the image with SetEffect.

And something cool that widgets over entities when using shaders, you can actually pass parameters for the shader from the lua side.
You can see SetEffectParams being used and being passed effectTime, effectSize, and effectFrequency variables.


And I believe those become these AMPLITUDE, FREQUENCY and VELOCITY variables. It's too bad AnimState doesn't have a SetEffectParams function too, but thats a cool thing you can do for UI.

You can also use this SetAlphaRange function to set alpha values and that becomes these variables in the overheat shader



Edited by Hornete
  • Thanks 3

Share this post

Link to post
Share on other sites
ADM    11472

Super dapper, I haven't used basic shaders much before but that just makes it more interesting to me then ! :encouragement:

  • Like 1

Share this post

Link to post
Share on other sites
poolcool2    6

Any idea of how one would port a shader from DS to DST and how to set the shader's variables?
I am using these to add one and it seems to work fine by which I mean it adds the shader and it can be enabled but it crashes when enabled due to what I assume is it missing it's varaibles.


Looking in postprocesseffects.lua I found where it builds and enables shaders and all that and it looks like it sets up variables like this, but I don't understand how it works and it isn't exactly helping.

local function VisionBlurBuild()
	local BLUR_PARAMS = PostProcessor:AddUniformVariable("BLUR_PARAMS", 4)
	PostProcessorEffects.VisionBlur = PostProcessor:AddPostProcessEffect(resolvefilepath("shaders/postprocess_blur.ksh"))
	PostProcessor:SetEffectUniformVariables(PostProcessorEffects.VisionBlur, BLUR_PARAMS)

The part that annoys me most about this issue is that I keep seeing it reference "PostProcessor" But I can't find any "PostProcessor.lua" or anything else that might contain the code of it in DS or DST and without having the whole picture of the variables are set and used I can't figure out how to set them for myself.

Share this post

Link to post
Share on other sites
kila    55

Dear hornete, is this work on hat? i really want to make a hat, which can change color like your evergreen. (^q^)

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this