Jump to content

Need help porting Wagstaff's poor vision to DST


Recommended Posts

I have been trying to port Wagstaff's nearsightedness to DST for the past week with little to no results and I have reached a point to where all my efforts of the past 5 days have made no progress. I decided to ask here if anyone smarter then me knows what I am doing wrong or maybe could help by doing this for me. Any information I have been able to find about GLSL just does not make sense to me in the same ways that lua does and I am having great difficulties understanding how exactly the game interacts with the shaders and how they interact with it.

My best attempts have resulted in a black screen, a white screen, a rainbow screen, no changes to the screen at all, or a client crash with the errors "Shader uniform is undefined." and "Assert failure 'src_data != NULL' at ..\source\renderlib\OpenGL\HWEffect.cpp(467): Trace follows..."

modmain.lua vision_blur.ksh

  • Like 2
Link to comment
Share on other sites

(I'm completely guessing here, just started modding so I'm learning to go through files to find stuff to use...and..)

I noticed in your file you don't have the one line in Wagstaff's lua file from DS that would probably do it. I'd start there.

	inst.components.vision.nearsighted = true

If you now look in the "goggles.lua", since those turn off his nearsightedness...there's one line:

		inst:AddTag("nearsighted_glasses")

Just need to find whatever code "components.vision.nearsighted" is in so you can see what it does when someone has that and transport the lua that's doing the shader stuff. The goggles.lua file also has info on the Heat-Vision goggles (makes the screen red) so that might help too

Edited by Astralite
typo
Link to comment
Share on other sites

ahh, duh...data\databundles\scripts.zip\components\vision.lua.

 

local easing = require("easing")

local Vision = Class(function(self, inst)
	self.nearsighted = false
    self.inst = inst   
	self.focused = true
	self:SetFocused()
	self.inst:DoTaskInTime(0, function()
		if self.nearsighted then			
			local headgear = self.inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
    		if not headgear or not headgear:HasTag("nearsighted_glasses") then 			    			
				self:SetUnfocused()
			end
		end
	end)
    inst:ListenForEvent("equip", function() self:CheckForGlasses() end )
    inst:ListenForEvent("unequip", function() self:CheckForGlasses() end)    
    self.inst:StartUpdatingComponent(self)
end)

function Vision:OnUpdate(dt)
	local hx, hy, hz = self.inst.AnimState:GetSymbolPosition("head", 0, 0, 0)

	local px, py = TheSim:GetScreenPos(hx,hy,hz)
	local w,h = TheSim:GetScreenSize()
	PostProcessor:SetBlurCenter(px/w, py/h)
end

function Vision:SetFocused()
	if not self.focused then
		self.focused = true
		PostProcessor:SetBlurEnabled(false)
	end
end

function Vision:SetUnfocused()
	if self.focused then 
		self.focused = false
		PostProcessor:SetBlurEnabled(true)
		PostProcessor:SetBlurParams(TUNING.NEARSIGHTED_BLUR_START_RADIUS, TUNING.NEARSIGHTED_BLUR_STRENGTH)
	end
end

function Vision:CheckForGlasses()
    local headgear = self.inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD)
    if headgear and headgear:HasTag("nearsighted_glasses") then  
    	if self.nearsighted then    		
    		self:SetFocused()    		
    	else
    		self:SetUnfocused()			
		end
    else
    	if self.nearsighted then
    		self:SetUnfocused()
    	else
    		self:SetFocused()			
		end
    end
	-- but...headgear can override this again
	if headgear and headgear.CustomFocus then
		headgear:CustomFocus(self.inst)
	end
end

function Vision:testsight(item)
	if not item:IsValid() then
		return false
	end
	-- LIMBO gets things in inventory. Maybe it needs to be more robust than just that, but works for now		
	return item:GetDistanceSqToInst(GetPlayer()) < TUNING.NEARSIGHTED_ACTION_RANGE*TUNING.NEARSIGHTED_ACTION_RANGE or item:HasTag("INLIMBO")
end


return Vision

This might be what you need...

function Vision:SetFocused()
    if not self.focused then
        self.focused = true
        PostProcessor:SetBlurEnabled(false)
    end
end

function Vision:SetUnfocused()
    if self.focused then 
        self.focused = false
        PostProcessor:SetBlurEnabled(true)
        PostProcessor:SetBlurParams(TUNING.NEARSIGHTED_BLUR_START_RADIUS, TUNING.NEARSIGHTED_BLUR_STRENGTH)
    end
end

 

 

DST doesn't have a vision.lua file in its components, though. Maybe the PostProcessor code will work.

In the Dontstarve\data\shaders folder there is a postprocess_blur.ksh file. Could check that.

 

again, just guessing stuff.

Link to comment
Share on other sites

The issue isn't that I can't get it to activate the issue is that I am having trouble porting the shader to DST.

 

21 hours ago, Astralite said:

In the Dontstarve\data\shaders folder there is a postprocess_blur.ksh file. Could check that.

.I did, it uses a much different format than shaders in DST and the problem I am having is in replacing those differences. The file I shared vision_blur.ksh was a modification of postprocess_blur.ksh, but I just can't get it to work. In the modmain I have code that applies that shader and enables it and as mentioned in my post I have not been able to make any progress in about a week of effort of trying to understand GLSL and changing things in hopes of it working. All I need is to get the shader working and I can do the rest, that is why I made this post.
Thanks for trying to help though.

  • Like 1
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...