Change Light map value

Change Light map value

Discuss maps & map creation - from concept to execution to the ever elusive release.

Moderator: Moderators

User avatar
daryl
Posts: 195
Joined: 08 Oct 2006, 10:33

Change Light map value

Post by daryl »

Hi to All,
I have a question:

Can I change the lightmap intensity ?
for example: In my map I use light line (for example airport lights). I would like shut off this lights during the game. Can i change maplight value or i need to swap the lightmap with other image?

I found this on wiki:
Spring.UpdateMapLight

(number lightHandle, table lightParams) -> boolean success

but I don't know how use commands...
can you help me?
Thx!
User avatar
daryl
Posts: 195
Joined: 08 Oct 2006, 10:33

Re: Change Light map value

Post by daryl »

Anyone can help me please? Thx
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Change Light map value

Post by Beherith »

Could you please post more information on what visual you would like to achieve? Its not apparent to me from your post..
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Change Light map value

Post by code_man »

Sorry for late reply.

Have a look at this viewtopic.php?f=13&t=35373, i think it should be self explaining pretty much.

I hope this will help you.
User avatar
daryl
Posts: 195
Joined: 08 Oct 2006, 10:33

Re: Change Light map value

Post by daryl »

Beherith wrote:Could you please post more information on what visual you would like to achieve? Its not apparent to me from your post..
code_man wrote:Sorry for late reply.

Have a look at this viewtopic.php?f=13&t=35373, i think it should be self explaining pretty much.

I hope this will help you.
hi guys! thx for interest, but i don't need to change enviromental ligh, but i need to change lights of the map . So, I will post as soon as possible more info as asked by beherith. Thx again! see you soon
User avatar
daryl
Posts: 195
Joined: 08 Oct 2006, 10:33

Re: Change Light map value

Post by daryl »

code_man wrote:Sorry for late reply.

Have a look at this viewtopic.php?f=13&t=35373, i think it should be self explaining pretty much.

I hope this will help you.
Beherith wrote:Could you please post more information on what visual you would like to achieve? Its not apparent to me from your post..

hello, as promise I post more detail about my question:

1) for "lightmap intensity" I mean "light_emission" intensity.

2) the question is: Can I change light_emission image of the map during the play?

For example :
I would like change light emission map from light_emissionA.png to light_emissionB.png when a "x" power generator explode.

Image

Is this possible?
Thx a lot!
Bye
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Change Light map value

Post by Kloot »

Code: Select all

if (gl.Texture("emissionTexture.png")) then
  Spring.SetMapShadingTexture("$ssmf_emission", "emissionTexture.png")
end
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: Change Light map value

Post by PicassoCT »

Let there be light - Yagami
Inb4 funny timelapse light challenge

If you want to alter the sun direction - /dynamic sun
is needed.

To any dev passing by... does this
Image

accuratly depict how the rotation sun is setup?

The direction vector is perpendicular to the orbital plane, which is always a circle. The distance equals the radius of the circle.
The total time equals the circumference of the circle?
Attachments
8fb78a09-6868-437e-bfe0-f3185790cec0.png
(130.58 KiB) Not downloaded yet
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: Change Light map value

Post by PicassoCT »

Toyed around with it- made this:

Drag and Drop into gadget repo- be amazed:

Code: Select all


function gadget:GetInfo()
	return {
		name = "jw_suncontroller",
		desc = "controlls the sun rising and sinking",
		author = "PicassoCT",
		date = "12.02.2083",
		version = "v0.1",
		license = "GPL v3.0 or later",
		layer = -1, 
		enabled = true,
	}
end


if gadgetHandler:IsSyncedCode() then
	-------------------------------------
	----------------SYNCED---------------
	function makeVector(x,y,z)
		return {x=x,y=y,z=z}
	end
	
	
	local boolDebug=false
	--==========================WhereTheSunDontShines============================
	--Initialses the sun control and sets the inital arc
	function gadget:GameStart ()
		Spring.SetSunManualControl(true)
		setSunArc()
	end
	
	function clamp(val,low,up)
		if val > up 	then return up end
		if val < low 	then return low end
		return val
	end
	
	
	
	--multiplies all members of a table by a factor
	function factor(value,fac)
		for key,val in pairs(value) do
			value[key]=value[key]*fac
		end
		
		return value
	end
	
	--if you want diffrent colours for your day, modify this table
	sunCol={}
	--night
	sunCol[#sunCol+1]=makeVector(54,106,144)
	sunCol[#sunCol+1]=makeVector(49,95,125)
	sunCol[#sunCol+1]=makeVector(41,72,120)
	sunCol[#sunCol+1]=makeVector(27,37,100)
	sunCol[#sunCol+1]=makeVector(24,50,80)
	sunCol[#sunCol+1]=makeVector(50,20,30)
	sunCol[#sunCol+1]=makeVector(75,18,25)
	--sunrise
	sunCol[#sunCol+1]=makeVector(88,28,0)
	sunCol[#sunCol+1]=makeVector(120,39,0)
	sunCol[#sunCol+1]=makeVector(156,51,0)
	sunCol[#sunCol+1]=makeVector(175,57,0)
	sunCol[#sunCol+1]=makeVector(223,73,0)
	sunCol[#sunCol+1]=makeVector(246,66,0)
	sunCol[#sunCol+1]=makeVector(255,128,0)
	sunCol[#sunCol+1]=makeVector(255,199,0)
	--noon
	sunCol[#sunCol+1]=makeVector(188,193,210)
	sunCol[#sunCol+1]=makeVector(203,175,167)
	sunCol[#sunCol+1]=makeVector(229,232,235)
	sunCol[#sunCol+1]=makeVector(229,232,235)
	sunCol[#sunCol+1]=makeVector(229,232,235)
	--zenit
	--mirrored sunrise
	for i=1,20 do
		sunCol[#sunCol+1]= sunCol[20-i]
	end
	--factor to divide the rgb values
	divFactor=255
	-- Calculates the suns color depending on daytime
	function getsunColor (percent)
		percent=clamp(percent,0,1)
		pMin=math.floor(percent * (#sunCol))
		pMax=math.min(pMin+1,#sunCol)
		--clamp
		pMax=math.max(2,math.min(pMax,#sunCol))
		pMin = math.min(pMax-1,math.max(1,pMin))
		
		onePart= 1/#sunCol
		diff= math.abs( percent -(pMin*onePart))/onePart
		
		
		return {
			r=math.abs(math.mix(sunCol[pMin].x,sunCol[pMax].x, diff))/divFactor,
			g=math.abs(math.mix(sunCol[pMin].y,sunCol[pMax].y, diff))/divFactor,			
			b=math.abs(math.mix(sunCol[pMin].z,sunCol[pMax].z, diff))/divFactor,
			a=0.5
		}
	end 
	--Various Atmosphere and Sun setting getters
	function getDefaultConfg(rgba)
		confg={
			groundAmbientColor = {rgba.r, rgba.r, rgba.r},
			groundDiffuseColor = {rgba.r, rgba.r, rgba.r},
			groundSpecularColor = {rgba.r, rgba.r, rgba.r},
			unitAmbientColor = {rgba.r, rgba.r, rgba.r},
			unitDiffuseColor = {rgba.r, rgba.r, rgba.r},
			unitSpecularColor = {rgba.r, rgba.r, rgba.r},
			specularExponent = 0.007,
			sunColor = {rgba.r, rgba.r, rgba.r, rgba.r},
			skyColor = {rgba.r, rgba.r, rgba.r, rgba.r},
			cloudColor = {rgba.r, rgba.r, rgba.r, rgba.r},
			fogStart = 0.25,
			fogEnd = 0.75,
			fogColor = {1.0, 1.0, 1.0, 0.5}
		}
		
		return confg
	end
	function getgroundAmbientColor(percent)
		return factor(getsunColor(percent),0.66)
	end 
	function getgroundDiffuseColor(percent)
		return factor(getsunColor(percent),0.75)
	end 
	function getgroundSpecularColor(percent)
		return factor(getsunColor(percent),0.95)
	end 
	function getunitAmbientColor(percent)
		return factor(getsunColor(percent),0.9)
	end 
	function getunitDiffuseColor(percent)
		return factor(getsunColor(percent),0.98)
	end 
	function getunitSpecularColor(percent)
		rgba= getsunColor(percent)
		rgba.r= math.min(rgba.r,rgba.r*0.8)
		return rgba
	end 
	function getspecularExponent(percent)
		return {r=0,g=0,b=0,a=percent*100}
	end 
	function getFogColor(percent)
		return factor(getsunColor(percent),0.9)
	end
	function getskyColor (percent)
		rgba=getsunColor(percent)
		rgba=factor(rgba,0.6)
		rgba.b=rgba.b+0.05
		return rgba
	end 
	function getcloudColor (percent)
		return factor(getsunColor(percent),0.3)
	end 
	
	function setSunArc()
		local resultVec=makeVector(0.5,0.4,0.3)
		Spring.SetSunParameters(resultVec.x, resultVec.y,resultVec.z, 250, 0, 32400)
	end
	-- calculates a fog curve with peak at midnight and zero at dawn and dusk
	function getFogFactor(percent)
		cosFac=(percent*2*math.pi)-math.pi
		invCosRes=math.cos(cosFac)*-1
		if invCosRes < 0 then invCosRes=0 end
		return invCosRes
	end
	--sets the sunconfiguration given to it
	function setSun(c, totalPercent)
		
		
		
		
		
		
		Spring.SetSunLighting ({groundAmbientColor = {c.groundAmbientColor[1], c.groundAmbientColor[2], c.groundAmbientColor[3], c.groundAmbientColor[4]}})
		Spring.SetSunLighting ({groundDiffuseColor = {c.groundDiffuseColor[1], c.groundDiffuseColor[2], c.groundDiffuseColor[3], c.groundDiffuseColor[4]}})
		Spring.SetSunLighting ({groundSpecularColor = {c.groundSpecularColor[1], c.groundSpecularColor[2], c.groundSpecularColor[3], c.groundSpecularColor[4]}})
		Spring.SetSunLighting ({unitAmbientColor = {c.unitAmbientColor[1], c.unitAmbientColor[2], c.unitAmbientColor[3], c.unitAmbientColor[4]}})
		Spring.SetSunLighting ({unitDiffuseColor ={c.unitDiffuseColor[1], c.unitDiffuseColor[2], c.unitDiffuseColor[3], c.unitDiffuseColor[4]}})
		Spring.SetSunLighting ({unitSpecularColor = {c.unitSpecularColor[1], c.unitSpecularColor[2], c.unitSpecularColor[3], c.unitSpecularColor[4]}})
		Spring.SetSunLighting ({specularExponent = c.specularExponent})
		
		Spring.SetAtmosphere ({sunColor = {c.sunColor[1], c.sunColor[2], c.sunColor[3], c.sunColor[4] }})	--c.sunColor[4]
		Spring.SetAtmosphere ({skyColor ={c.skyColor[1], c.skyColor[2], c.skyColor[3],c.skyColor[4] }})
		Spring.SetAtmosphere ({cloudColor = {c.cloudColor[1], c.cloudColor[2], c.cloudColor[3], c.cloudColor[4]}})
		--Spring.SetAtmosphere ({fogStart = c.fogStart, fogEnd =c.fogEnd, fogColor = {c.fogColor[1], c.fogColor[2], c.fogColor[3], c.fogColor[4]}}) 
		
	end
	--Creates a DayString
	function getDayTime(now,total)
		hours=math.floor((now/total)*24)
		minutes=math.ceil((((now/total)*24)-hours)*60)
		return hours..":"..minutes
	end
	
	--gets a config and sets the time of day as sun
	function aDay(timeFrame,WholeDay)
		if boolDebug == true then
			Spring.Echo("sunGadget::"..getDayTime(timeFrame%(WholeDay),WholeDay))
		end
		percent=((timeFrame%(WholeDay))/(WholeDay))
		
		
		config= getDefaultConfg({r=0.5,g=0.5,b=0.5,a=0.5})	
		rgba=getgroundAmbientColor(percent)
		
		config.groundAmbientColor = {rgba.r, rgba.g, rgba.b}
		rgba=getgroundDiffuseColor(percent)
		config.groundDiffuseColor = {rgba.r, rgba.g, rgba.b}
		rgba=getgroundSpecularColor(percent)
		config.groundSpecularColor = {rgba.r, rgba.g, rgba.b}
		rgba=getunitAmbientColor(percent)
		config.unitAmbientColor = {rgba.r, rgba.g, rgba.b}
		rgba=getunitDiffuseColor(percent)
		config.unitDiffuseColor = {rgba.r, rgba.g, rgba.b}
		rgba=getunitSpecularColor(percent)
		
		config.unitSpecularColor = {rgba.r, rgba.g, rgba.b}
		rgba=getspecularExponent(percent)
		config.specularExponent = rgba.a
		rgba=getsunColor (percent)
		config.sunColor = {rgba.r, rgba.g, rgba.b, rgba.a}
		rgba=getskyColor (percent)
		config.skyColor = {rgba.r, rgba.g, rgba.b, rgba.a}
		rgba=getcloudColor (percent)
		config.cloudColor = {rgba.r, rgba.g, rgba.b, rgba.a}
		
		config.fogStart = 2048* (1.001-getFogFactor(percent))
		config.fogEnd = 8192* (1.001-getFogFactor(percent))
		rgba=getFogColor(percent)
		config.fogColor = {rgba.r, rgba.g, rgba.b, rgba.a}
		
		setSun(config,percent)	
		
	end
	
	--set the sun
	function gadget:GameFrame(n)		
		if n % 32 == 0 then
			aDay(n,28800)		
		end	
		if n % 28800 == 0 then 
			setSunArc()
		end
	end
end
Image
Image
Image

Stay clear of opium and infected cunts sailors!
Attachments
screen00087.jpg
(181.25 KiB) Not downloaded yet
screen00100.jpg
(264.84 KiB) Not downloaded yet
screen00099.jpg
(278.54 KiB) Not downloaded yet
User avatar
daryl
Posts: 195
Joined: 08 Oct 2006, 10:33

Re: Change Light map value

Post by daryl »

Thx to all for informations!
Kloot wrote:

Code: Select all

if (gl.Texture("emissionTexture.png")) then
  Spring.SetMapShadingTexture("$ssmf_emission", "emissionTexture.png")
end
Hi kloot, i tried but probably i wrong something:
where i need to save .png file?
I used this code only for test:

Code: Select all

function gadget:GetInfo()
   return {
      name = "unita_iniziali",
      desc = "Aggiunge unità all'inizio del gioco.",
      author = "daryl - ",  -- thx to http://springrts.com community,  knorke,  smoth,  Beherith,  jK .
      date = "September 19st,  2010",
      license = "GPL,  v.2,  2008",
      layer = 1,
      enabled = true,
   }
end
 
local gaiaTeamId        = Spring.GetGaiaTeamID()

-- change  the emitting texture 
  Spring.SetMapShadingTexture("$ssmf_emission", "light_emission_bocciata.png")


        end
but at start of game emission map is the original setted in "namemap/maps/namemap.sdm".
what I wrong?
User avatar
daryl
Posts: 195
Joined: 08 Oct 2006, 10:33

Re: Change Light map value

Post by daryl »

Kloot wrote:

Code: Select all

if (gl.Texture("emissionTexture.png")) then
  Spring.SetMapShadingTexture("$ssmf_emission", "emissionTexture.png")
end

sorry, i'm not a coder...
- this code set the new emitting texture?:

Code: Select all

  Spring.SetMapShadingTexture("$ssmf_emission", "newemissionTex.png")
- the "newemissiontex.png" file must be saved at the same place of original "emissiontex.png"?

I tried to use this code but emitting light don't change...

please, if the job is simple, can you make for me a code/sample:

when the "X" unit is destroyed -> change emitting map using "newemissiontex.png"...

thankyou
User avatar
daryl
Posts: 195
Joined: 08 Oct 2006, 10:33

Re: Change Light map value

Post by daryl »

daryl wrote:

sorry, i'm not a coder...
- this code set the new emitting texture?:

Code: Select all

  Spring.SetMapShadingTexture("$ssmf_emission", "newemissionTex.png")
- the "newemissiontex.png" file must be saved at the same place of original "emissiontex.png"?

I tried to use this code but emitting light don't change...

please, if the job is simple, can you make for me a code/sample:

when the "X" unit is destroyed -> change emitting map using "newemissiontex.png"...

thankyou
up!
sorry,
anyone can help me with code??
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Change Light map value

Post by Forboding Angel »

$ssmf_emission

What is this? If it's a variable, drop the $.

The problem is, I don't think any of us understand what you want?

To me it almost sounds like you are talking about specular?
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Change Light map value

Post by gajop »

Don't listen to forb.

$ssmf_* are various SSMF textures, and they can be set with the code Kloot provided.

If you plan to change them *per* unit, you probably want to use a Lua texture. Set it *once* and then do all changes to the Lua texture (this is how springboard implements SSMF editing).

Unless things changed, the main requirement for this to work is for there to be an *existing* SSMF texture that you're trying to modify. Therefore, your map needs to have the SSMF texture already specified.

PS: I still don't fully understand what this is supposed to explain: http://www.warmachinesrts.com/altri_sit ... ission.jpg . Can you elaborate further?
User avatar
daryl
Posts: 195
Joined: 08 Oct 2006, 10:33

Re: Change Light map value

Post by daryl »

gajop wrote:Don't listen to forb.

$ssmf_* are various SSMF textures, and they can be set with the code Kloot provided.

If you plan to change them *per* unit, you probably want to use a Lua texture. Set it *once* and then do all changes to the Lua texture (this is how springboard implements SSMF editing).

Unless things changed, the main requirement for this to work is for there to be an *existing* SSMF texture that you're trying to modify. Therefore, your map needs to have the SSMF texture already specified.

PS: I still don't fully understand what this is supposed to explain: http://www.warmachinesrts.com/altri_sit ... ission.jpg . Can you elaborate further?
ok I try to explain what i'm trying to do:
In the map there is an Auto Emit texture that light some lines around the roads.
I would like create an event, during the game, in which If I destroy a "X unit" (for example a GaIA power plant), these light lines shut off.

So, Can I change Auto_emit texture during the game? For example, initial Auto emit texture is the file "Ae_on.png" setted into the map.lua.
Its possible to change this autoemit texture during the game, using a second file named "Ae_off.png" ?
If this is possible i need some help to do this:
when "X_unit" is destroyed -> change auto emit texture map with this one from Ae_off.png file.

this is the auto emit texture from spring wiki https://springrts.com/wiki/Mapdev:lightemission
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

Re: Change Light map value

Post by Forboding Angel »

gajop wrote:Don't listen to forb.

$ssmf_* are various SSMF textures, and they can be set with the code Kloot provided.
What kloot wrote was ambiguous. Let me clarify his post:
Wiki wrote: Spring.SetMapShadingTexture ( string texType, string texName ) -> boolean success

For Example:

Code: Select all

if (gl.Texture("emissionTexture.png")) then
	Spring.SetMapShadingTexture("$ssmf_emission", "emissionTexture.png")
end

To be fair, I didn't even notice kloot's post, so I thought that:

Code: Select all

Spring.SetMapShadingTexture("$ssmf_emission", "emissionTexture.png")
Was just something he came up with. and I didn't even bother looking up Spring.SetMapShadingTexture

Protip, @daryl. When you want someone on this forum to help you out, make a statement about something, but make sure that your statement is either nonsensical or just outright wrong. You will have tons of posters correcting you, in which case you get your answer, as opposed to asking a legit question and being completely ignored.
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Change Light map value

Post by ivand »

A bit of the necro. But the topic/content is appropriate.

I'm playing with Spring.SetMapShadingTexture and seem to have stuck in the mud. In particular I can't assign $ssmf_emission texture to be a texture, generated with gl.CreateTexture. I want to modify the texture values dynamically, therefore the use of in-memory texture is mandatory. See the code snippet:

Code: Select all

	local ssmfTexInfo = gl.TextureInfo("$ssmf_emission")
	ssmfEmissionTexNew = gl.CreateTexture(ssmfTexInfo.xsize, ssmfTexInfo.ysize, {
							border = false,
							min_filter = GL.NEAREST,
							mag_filter = GL.NEAREST,
							wrap_s = GL.CLAMP_TO_EDGE,
							wrap_t = GL.CLAMP_TO_EDGE,
						})
	
	Spring.SetMapShadingTexture("$ssmf_emission", "some_image_file.png")
	-- WORKS ^^^^^^^^
	
	Spring.SetMapShadingTexture("$ssmf_emission", ssmfEmissionTexNew)
	-- DOES NOTHING ^^^^^^^^
Is this by design or just an oversight? If former, then how do I change emission map texture in the real time?
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Change Light map value

Post by gajop »

Try adding fbo = true, like
ivand wrote:

Code: Select all

	local ssmfTexInfo = gl.TextureInfo("$ssmf_emission")
	ssmfEmissionTexNew = gl.CreateTexture(ssmfTexInfo.xsize, ssmfTexInfo.ysize, {
							border = false,
							min_filter = GL.NEAREST,
							mag_filter = GL.NEAREST,
							wrap_s = GL.CLAMP_TO_EDGE,
							wrap_t = GL.CLAMP_TO_EDGE,
							fbo = true,
						})
	Spring.SetMapShadingTexture("$ssmf_emission", ssmfEmissionTexNew)
Haven't used emission textures, but should work.
ivand
Posts: 310
Joined: 27 Jun 2007, 17:05

Re: Change Light map value

Post by ivand »

I pasted only part of the code. Texture is attached to FBO a few lines later:

Code: Select all

fbo = gl.CreateFBO({color0 = ssmfEmissionTexOrig, color1 = ssmfEmissionTexNew})
fbo.drawbuffers = {GL_COLOR_ATTACHMENT0_EXT, GL_COLOR_ATTACHMENT1_EXT}
I also tried

Code: Select all

fbo = true
right in the texture definition. Doesn't make any difference.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Change Light map value

Post by Kloot »

Is [DOES NOTHING] by design or just an oversight?
Neither, gajop's copypasta snippet visibly kills the default emission texture (as it should) for me on Core Platform.

Which map(s) are you using to test this?
Post Reply

Return to “Map Creation”