Jump to content

Having trouble with a custom shader.


Recommended Posts

After the past few days of work, learning how shaders work and trying various things to get mine to work I finally managed to get it to not crash when building it, but when the shader is enabled it just turns the entire screen except the HUD black. I am trying to port over Wagstaff's blurry vision to DST but so far I have not made much progress.

In the modmain I have this and this part seems to work just fine.

Assets =
{
	Asset( "SHADER", "shaders/vision_blur.ksh" ),
}

local PostProcessorEffects = GLOBAL.PostProcessorEffects
local SamplerEffects = GLOBAL.SamplerEffects
local resolvefilepath = GLOBAL.resolvefilepath
local SamplerSizes = GLOBAL.SamplerSizes
local SamplerColourMode = GLOBAL.SamplerColourMode
local SamplerEffectBase = GLOBAL.SamplerEffectBase
local UniformVariables = GLOBAL.UniformVariables
local FILTER_MODE = GLOBAL.FILTER_MODE
local MIP_FILTER_MODE = GLOBAL.MIP_FILTER_MODE

local function BuildVisionShader()
	local PostProcessor = GLOBAL.PostProcessor
	local PostProcessorEffects = GLOBAL.PostProcessorEffects
	print("Building vision shader")
	print("  Adding blurH")
	PostProcessor:SetBloomSamplerParams(SamplerSizes.Relative, 0.25, 0.25, SamplerColourMode.RGB)
    SamplerEffects.BlurH = PostProcessor:AddSamplerEffect("shaders/blurh.ksh", SamplerSizes.Relative, 0.25, 0.25, SamplerColourMode.RGB, SamplerEffectBase.BloomSampler)
    PostProcessor:SetEffectUniformVariables(SamplerEffects.BlurH, UniformVariables.SAMPLER_PARAMS)

    print("  Adding blurV")
    SamplerEffects.BlurV = PostProcessor:AddSamplerEffect("shaders/blurv.ksh", SamplerSizes.Relative, 0.25, 0.25, SamplerColourMode.RGB, SamplerEffectBase.Shader, SamplerEffects.BlurH)
    PostProcessor:SetEffectUniformVariables(SamplerEffects.BlurV, UniformVariables.SAMPLER_PARAMS)

    print("  Adding uniform variables")
    PostProcessorEffects.VISION_BLUR_PARAMS = PostProcessor:AddUniformVariable("BLUR_PARAMS", 4)

    print("  Setting sampler effect filter")
    PostProcessor:SetSamplerEffectFilter(SamplerEffects.BlurV, FILTER_MODE.LINEAR, FILTER_MODE.LINEAR, MIP_FILTER_MODE.NONE)

    print("  Adding vision blur shader")
    PostProcessorEffects.Vision_Blur = PostProcessor:AddPostProcessEffect(resolvefilepath("shaders/vision_blur.ksh"))
    PostProcessor:AddSampler(PostProcessorEffects.Vision_Blur, SamplerEffectBase.Shader, SamplerEffects.BlurV)

    print("  Setting uniform variables")
    PostProcessor:SetUniformVariable(PostProcessorEffects.VISION_BLUR_PARAMS, 0.0, 1.0, 1.0, 2.0)    -- Placeholder variables
    print("Done building vision shader")
end

local function SortAndEnableShaders()
	local PostProcessor = GLOBAL.PostProcessor
	PostProcessor:SetPostProcessEffectAfter(PostProcessorEffects.Vision_Blur, PostProcessorEffects.Bloom)

	PostProcessor:EnablePostProcessEffect(PostProcessorEffects.Vision_Blur, true) --Temp
end

AddModShadersInit(BuildVisionShader)
AddModShadersSortAndEnable(SortAndEnableShaders)

I am not sure if the blurv and blurh are working properly, but I think they are.

I took the shader itself from Hamlet and I trimmed all the extra stuff because it looked like DS handled all of it's shaders in duplicate copies of the same/similar shader file just with variables tweaked to turn on/off various shaders. I still don't understand GLSL too well so I don't know how to properly port it over and this was my best attempt and I have ran out of ideas to try.

vision_blur.ksh

Link to comment
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
 Share

×
  • Create New...