Dinamic Blob Shadows! - Page 3

Dinamic Blob Shadows!

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
panzeriv2
Posts: 208
Joined: 12 Aug 2008, 12:02

Re: Dinamic Blob Shadows!

Post by panzeriv2 »

lol that sepia filter is done using a a image editing program.
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Dinamic Blob Shadows!

Post by very_bad_soldier »

Kixxe wrote:Yea i got it now but i don't see the widget when i load up 1944. Can't someone just upload it so it's avalible without downloading a full mod?
Hm, where do you got it from? In CA-SVN I can only find "unit_blobshadow.lua" which is not "dynamic blob shadows" AFAIK. Has this thingie ever been finished actually?
[Krogoth86]
Posts: 1176
Joined: 23 Aug 2007, 19:46

Re: Dinamic Blob Shadows!

Post by [Krogoth86] »

Is this widget flawed for anyone else since the latest version of Spring? For me it gives shadows that are too narrow:
Image
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Dinamic Blob Shadows!

Post by very_bad_soldier »

I tell you if you tell me where to download. 8)
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Dinamic Blob Shadows!

Post by Argh »

Sorry, didn't realize that this was a source request, would have dropped this off earlier. Here's my current version of this Widget, I've had it in World Builder for quite some time.

I've been maintaining a version since User disappeared. That bug that was mentioned is fixed in this version.

Code: Select all

function widget:GetInfo()
  return {
	name	  = "Dynamic Blob Shadows",
	desc	  = "Creates shadow projections from the sun position that wrap around the unit size",
	author	= "user, speedups by Argh",
	date	  = "March 3, 2008",
	license   = "GNU GPL, v2",
	layer	 = -1,
	enabled   = true  
  }
end

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
local side = 0
local xmul = 0
local zmu = 0
local ShadowList = {}
local sunx,suny,sunz = gl.GetSun()
local shadowdens = gl.GetSun("shadowdensity","unit")
local SR, SG, SB = gl.GetSun("ambient","unit")
local noshadow = 0 
local shadowsareon = 0 
local sundist = 0
local realdist = 0
local greater  = 0
local sunscale = 0   
local sunangle = 0  
local cangle = 0
									  
local ShadowsOn			= Spring.HaveShadows 
local list	
local UnitIDList
local height, diff, fx, fy, x, y, z, cx, cy, cz, id
local ShadowTex = 'LuaUI/Images/shadow.tga'


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- sun calculations,for projection----------------------------------------------
--------------------------------------------------------------------------------
sunangle = Spring.GetHeadingFromVector(sunx,sunz)/182.0444445 --exact number to convert a short integer to a 0 to 360 number.  
sunangle = sunangle + (360+90)								--when it is 65536, divide it by 182,0444445 you get 360.  
if (sunangle > 360) then
   sunangle = sunangle - 360
end
if (suny < 0 )then
   noshadow = 1
else
   sunscale = math.abs(suny + 0.1)* 200
   sunscale = math.abs(sunscale - 200) * 100
end
sundist = math.pow(sunx,2) + math.pow(sunz,2)
sundist = math.sqrt(sundist)
realdist = sundist * 50
sunscale = sunscale / 1876

local glTexture = gl.Texture
local glDepthMask = gl.DepthMask
local glDepthTest = gl.DepthTest
local glColor = gl.Color
local SpringGetUnitDefID = Spring.GetUnitDefID
local SpringGetUnitViewPosition = Spring.GetUnitViewPosition
local SpringGetGroundHeight = Spring.GetGroundHeight
local glPushMatrix = gl.PushMatrix
local glDrawListAtUnit = gl.DrawListAtUnit
local glPopMatrix = gl.PopMatrix
local glCreateList = gl.CreateList
local  glBeginEnd =  gl.BeginEnd
local GLQUAD_STRIP = GL.QUAD_STRIP
local glTexCoord = gl.TexCoord
local glVertex = gl.Vertex
local SpringGetCameraPosition = Spring.GetCameraPosition
local SpringGetVisibleUnits = Spring.GetVisibleUnits
local cx,cy,cz = 0,0,0

if SR > 1.0 then SR = 0.5 end
if SG > 1.0 then SG = 0.5 end
if SB > 1.0 then SB = 0.5 end
if shadowdens == nil or shadowdens > 1.0 then shadowdens = 0.5 end

function widget:DrawWorldPreUnit()
	cx,cy,cz = SpringGetCameraPosition()

	glTexture(ShadowTex)
	glDepthMask(false)
	glDepthTest(false)
	glColor(SR,SG,SB,shadowdens)

	unitIDList = SpringGetVisibleUnits(-1,3000,false)

	if unitIDList[1] == nil then 
		return false 
	else
		if (ShadowsOn()) then
			return false
		else
			if cy < 25 or cy > 4000 then 
				return false 
			else			
				for _,unitID in ipairs(unitIDList) do
					id = SpringGetUnitDefID(unitID) 
					x,y,z = SpringGetUnitViewPosition(unitID)
					height = SpringGetGroundHeight(x,z)
					diff = height-y+5
					if ShadowList[id] then
						fx = UnitDefs[id].xsize
						fy = UnitDefs[id].zsize
						glPushMatrix()
						glDrawListAtUnit(unitID,list,false,fx,1.0,fy,sunangle,0,1.0,0)
						glPopMatrix()
					end																																																		
				end
			end
		end
	end
	glDepthMask(true)
	glDepthTest(true)
	glColor(1,1,1,1)	
end

function widget:Initialize()

	for ud,_ in pairs(UnitDefs) do
		if UnitDefs[ud].customParams.draw_shadow == 'yes' then
			table.insert(ShadowList,ud,1)
		end
	end

list = glCreateList(function() 
	 glBeginEnd(GLQUAD_STRIP,function()  
	   --point1
	   glTexCoord(0,0)
	   glVertex(-4,0,-4)
	   --point2								 
	   glTexCoord(0,1)						   
	   glVertex(4*sunscale,0,-4)				   
	   --point3
	   glTexCoord(1,0)
	   glVertex(-4,0,4)
	   --point4
	   glTexCoord(1,1)
	   glVertex(4*sunscale,0,4)
	 end)
   end)
end   
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Dinamic Blob Shadows!

Post by very_bad_soldier »

Thanks Argh! I will add it to SpringDownloader soon if you dont mind.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Dinamic Blob Shadows!

Post by Argh »

No problem at all, please feel free to use it for whatever you'd like.

Just bear in mind that my version makes use of customParams, so you'd probably want to alter that before distribution, I deliberately made it that way to get along better with P.U.R.E. / World Builder.
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Dinamic Blob Shadows!

Post by very_bad_soldier »

Great! Thanks again!
But one more request, I think "LuaUI/Images/shadow.tga" is missing too, would be great if you could provide it somewhere.
[Krogoth86]
Posts: 1176
Joined: 23 Aug 2007, 19:46

Re: Dinamic Blob Shadows!

Post by [Krogoth86] »

Well that's no problem - it's just the image user included in his version. I'll attach it to this posting...
Attachments
shadow.zip
shadow.tga
(8.5 KiB) Downloaded 22 times
user
Posts: 452
Joined: 22 Jan 2008, 16:33

Re: Dinamic Blob Shadows!

Post by user »

this new version still makes flying units shadows look bad, the shadow will stay exactly below the unit.

and the unit height transformation is still not good, both are things i have tried to fix.

and feature (rocks,plants,trees, these stuff) shadows, i remember that those are possible, but anyone wants it?
[Krogoth86]
Posts: 1176
Joined: 23 Aug 2007, 19:46

Re: Dinamic Blob Shadows!

Post by [Krogoth86] »

Well it's still better than no shadows at all... :P

I think I've also fixed the issue with the too narrow shadows with the new Spring versions. Maybe Argh can confirm it but I guess it was just about a one letter change (ysize turning into zsize or something like that)... :wink:

Maybe someone can try this too - it works for me now...
Attachments
dynamic_blob_shadows.zip
(1.36 KiB) Downloaded 457 times
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Dinamic Blob Shadows!

Post by very_bad_soldier »

Nice1! WidgetDownloader'd
User avatar
manolo_
Posts: 1370
Joined: 01 Jul 2008, 00:08

Re: Dinamic Blob Shadows!

Post by manolo_ »

got a problem with the shadows

system:

amd64, ati 9700 (old driver, coz of compatibility)
Attachments
screen008.jpg
dumdidum
(114.83 KiB) Downloaded 18 times
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: Dinamic Blob Shadows!

Post by very_bad_soldier »

Missing shadow.tga? Oops, I forgot it in the downloader too...

EDIT: fixed
User avatar
manolo_
Posts: 1370
Joined: 01 Jul 2008, 00:08

Re: Dinamic Blob Shadows!

Post by manolo_ »

now its better, but not satisifying
Attachments
screen009.jpg
(181.51 KiB) Downloaded 39 times
User avatar
MidKnight
Posts: 2652
Joined: 10 Sep 2008, 03:11

Re: Dinamic Blob Shadows!

Post by MidKnight »

Teamplatter: blob-y edition! :P
[Krogoth86]
Posts: 1176
Joined: 23 Aug 2007, 19:46

Re: Dinamic Blob Shadows!

Post by [Krogoth86] »

manolo_ wrote:now its better, but not satisifying
It always depends on the map and where the sunlight was put. After my experience especially older maps suck at this point and you often have this "top-down" shadows right below the units. Still better than none at all imo...
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Dinamic Blob Shadows!

Post by Pxtl »

Hmm. Hadn't noticed this thread before. My cheap little Intel onboard video can't render Spring shadows, so I'll have to give this a try.
User avatar
manolo_
Posts: 1370
Joined: 01 Jul 2008, 00:08

Re: Dinamic Blob Shadows!

Post by manolo_ »

[Krogoth86] wrote:
manolo_ wrote:now its better, but not satisifying
It always depends on the map and where the sunlight was put. After my experience especially older maps suck at this point and you often have this "top-down" shadows right below the units. Still better than none at all imo...
k, ru right, tested it on an other map and it worked, but i thought/hoped that it could do "real" shadows
Post Reply

Return to “Lua Scripts”