Jump to content

Changing Shadow Resolution

Recommended Posts



I would like to know if it is possible to change the shadow resolution in Lua. Or is this something that can only be done through C++?


My SetLightQuality() is at 2 which I believe is the maximum.

Share this post

Link to post

You can change the shadow quality via lua by World:SetLightQuality() but the issue shown in your previous posts is due to the shadow offset at different shadow stages/ranges. Back in the LE2 and 3DWS days, you could overcome this by putting a chamfer on the edges of enclosed box, making the walls & ceiling thicker, and worse case changing the directional light stage's shadow offset.


You can still do all the above in LE3 though they are not really documented. You have to figure out which stage is causing the problem and adjust it's linear offset value. Use the range value as a way to determine which stage where the light leaks through. The directional light has 4 stages with the following ranges and offsets:

- Stage0: Range: 6m Offset: 0.100000, 1.000000 (linear offset, exponential offset)

- Stage1 Range: 15m Offset: 0.200000, 1.000000

- Stage2 Range: 30m Offset: 0.500000, 1.000000

- Stage3 Range: 80m Offset: 0.750000, 1.000000


I would suggest only changing these values as a last attempt if you cannot resolve the issue via modeling as changing these could cause other artifacts and lighting problems in the rest of your scene.


Example script to attach to the directional light for determining which stage needs to be adjust and to what value:

function Script:Start()
  	self.stage = 0
	self.offset = {}
	self.range = {}
	for i = 0, 3 do
		self.offset = self.entity:GetShadowOffset(i)
		System:Print("Stage"..i.." Offset: "..self.offset:ToString())
		self.range = self.entity.shadowstagerange
		System:Print("Stage"..i.." Range: "..self.range)

function Script:UpdateWorld()
	window = Window:GetCurrent()
	if window:KeyHit(Key.Right) then self.stage = self.stage + 1 end
	if window:KeyHit(Key.Left) then self.stage = self.stage - 1 end
	self.stage = math.max(self.stage, 0)
	self.stage = math.min(self.stage, 3)
	if window:KeyHit(Key.Up) then self.offset[self.stage].x = self.offset[self.stage].x + 0.1 end
	if window:KeyHit(Key.Down) then self.offset[self.stage].x = self.offset[self.stage].x - 0.1 end
	self.entity:SetShadowOffset(self.offset[self.stage].x, self.offset[self.stage].y, self.stage)

function Script:PostRender(context)
	context:DrawText("Hit Left/Right Arrow Keys To Change Stages",2,22)
	context:DrawText("Hit Up/Down Arrow Keys To Change Stage's Linear Offset",2,42)
	context:DrawText("Stage: "..self.stage,2,62)
	context:DrawText("Range: "..self.range[self.stage],2,82)
	context:DrawText("Offset: "..self.offset[self.stage]:ToString(),2,102)


Share this post

Link to post

As far as shadow map resolutions, you used to be able to change that in LE2 in lua but it doesn't appeared to be exposed to lua for LE3/4. I assume its tied to the light quality now but thats just a guess on my part. If its an option in c++, then you will have to change the shadow map size there.

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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...