Jump to content

Recommended Posts

Posted

I've got it working now. Here's what it looks like:

require("scripts/class")

local class=CreateClass(...)

function class:InitDialog(grid)
self.super:InitDialog(grid)
group=grid:AddGroup("Light")
group:AddProperty("Resolution",PROPERTY_CHOICE,"256,512,1024,2048")
group:AddProperty("linearoffset",PROPERTY_VEC3,"0,1,2","Linear offset" )
group:AddProperty("shadowdistance",PROPERTY_VEC3,"","Shadow distance" )
group:AddProperty("Range",PROPERTY_FLOAT)
group:Expand(1)		
end

function class:Spawn(model)
local object=self.super:Spawn(model)
object.model:SetKey("resolution","2")
object.light=CreateDirectionalLight(object.model)		

function object:SetKey(key,value)
	if key=="resolution" then
		if value=="0" then
			self.light:SetShadowmapSize(256)
		elseif value=="1" then
			self.light:SetShadowmapSize(512)
		elseif value=="2" then
			self.light:SetShadowmapSize(1024)
		elseif value=="3" then
			self.light:SetShadowmapSize(2048)
		end
	elseif key=="range" then
		self.light:SetRange(value)
	elseif key=="shadowdistance" then
		local offset=string.Explode(value,",")
		x=tonumber(offset[1])
		y=tonumber(offset[2])
		z=tonumber(offset[3])
		if x==nil then x=0 end
		if y==nil then y=0 end
		if z==nil then z=0 end
		self.light:SetShadowDistance(x,0)
		self.light:SetShadowDistance(y,1)
		self.light:SetShadowDistance(z,2)	
	elseif key=="linearoffset" then
		local offset=string.Explode(value,",")
		x=tonumber(offset[1])
		y=tonumber(offset[2])
		z=tonumber(offset[3])
		if x==nil then x=0 end
		if y==nil then y=0 end
		if z==nil then z=0 end
		self.light:SetShadowOffset(x,1.0,0)
		self.light:SetShadowOffset(y,1.0,1)
		self.light:SetShadowOffset(z,1.0,2)
	else
		return self.super:SetKey(key,value)
	end
end

function object:GetKey(key,value)
	if key=="linearoffset" then
		return self.light:GetShadowOffset(0,0)..","..self.light:GetShadowOffset(0,1)..","..self.light:GetShadowOffset(0,2)
	elseif key=="shadowdistance" then
		return self.light:GetShadowDistance(0)..","..self.light:GetShadowDistance(1)..","..self.light:GetShadowDistance(2)
	elseif key=="range" then
		return self.light:GetRange()
	elseif key=="shadowresolution" then
		resolution=self.light:GetShadowmapSize()
		if resolution==256 then
			return 0
		elseif resolution==512 then
			return 1
		elseif resolution==1024 then
			return 2	
		elseif resolution==2048 then
			return 3
		else
			return -1
		end
	else
		return self.super:GetKey(key,value)
	end
end

function object:Kill(model)
	if self.light~=nil then
		self.light:Free()
		self.light=nil
	end
	self.super:Kill()
end

return object
end

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

This seems reasonable.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...