Lua UnitRendering: Difference between revisions
Add Spring.UnitRendering.SetProjectileLuaDraw |
|||
| (15 intermediate revisions by 7 users not shown) | |||
| Line 1: | Line 1: | ||
==Unit Rendering== | [[Engine_Development|Development]] < [[Lua_Scripting|Lua Scripting]] < {{FULLPAGENAME}} | ||
==Unit & Feature Rendering== | |||
{{new|101.0}} These functions are now also duplicated for features i.e. {{name|Spring.FeatureRendering.X}} | |||
'''Spring.UnitRendering.SetLODCount''' | '''Spring.UnitRendering.SetLODCount''' | ||
( number unitID, int lodCount ) -> nil | ( number unitID, int lodCount ) -> nil | ||
'''Spring.UnitRendering.SetLODLength''' <font color= | '''Spring.UnitRendering.SetLODLength''' <font color=#55ee99>(`lod` is 1-indexed)</font> | ||
( number unitID, int lod, number lodLength ) -> nil | ( number unitID, int lod, number lodLength ) -> nil | ||
'''Spring.UnitRendering.SetLODDistance''' <font color= | '''Spring.UnitRendering.SetLODDistance''' <font color=#55ee99>(same as SetLODLength(), but adjusted for 45deg FOV + 1024x768)</font> | ||
(number unitID, int lod, number lodDistance ) -> nil | (number unitID, int lod, number lodDistance ) -> nil | ||
'''Spring.UnitRendering.SetPieceList''' <font color= | '''Spring.UnitRendering.SetPieceList''' <font color=#55ee99>(displayList=nil reset to default)</font> | ||
( number unitID, int lod, int piece [, number displayList = nil ] ) -> nil | ( number unitID, int lod, int piece [, number displayList = nil ] ) -> nil | ||
'''Spring.UnitRendering.GetMaterial''' <font color= | '''Spring.UnitRendering.GetMaterial''' <font color=#55ee99>(creates a material userdata)</font> | ||
( [[Lua_UnitRendering# | ( [[Lua_UnitRendering#MaterialTypes|string MaterialType]], [[Lua_UnitRendering#Material_Table|table Material]] ) -> [[Lua_UnitRendering#Material_UserData|userdata Material]] | ||
'''Spring.UnitRendering.SetMaterial''' | '''Spring.UnitRendering.SetMaterial''' | ||
( number unitID, int lod, [[Lua_UnitRendering# | ( number unitID, int lod, [[Lua_UnitRendering#MaterialTypes|string MaterialType]], [[Lua_UnitRendering#Material_UserData|userdata Material]] | [[Lua_UnitRendering#Material_Table|table Material]] ) -> nil | ||
'''Spring.UnitRendering.SetMaterialLastLOD''' | '''Spring.UnitRendering.SetMaterialLastLOD''' | ||
( number unitID, | ( number unitID, [[Lua_UnitRendering#MaterialTypes|string MaterialType]], int lastLOD ) -> nil | ||
'''Spring.UnitRendering.SetMaterialDisplayLists''' | '''Spring.UnitRendering.SetMaterialDisplayLists''' | ||
( number unitID, [[Lua_UnitRendering# | ( number unitID, int lod, [[Lua_UnitRendering#MaterialTypes|string MaterialType]], [[Lua_OpenGL_Api#Display_Lists|preDisplayList]], [[Lua_OpenGL_Api#Display_Lists|postDisplayList]] ) -> nil | ||
'''Spring.UnitRendering.SetUnitUniform''' <font color=red>(unfinished)</font> | '''Spring.UnitRendering.SetUnitUniform''' <font color=red>(unfinished)</font> | ||
( number unitID, [[Lua_UnitRendering# | ( number unitID, [[Lua_UnitRendering#MaterialTypes|string MaterialType]], int lod, arg1, arg2, ... ) -> nil | ||
'''Spring.UnitRendering.SetUnitLuaDraw''' < | ==Debug== | ||
'''Spring.UnitRendering.Debug''' <span class="note">(prints some usefull debug informations)</span> | |||
( [ number unitID ] ) -> nil | |||
==Lua's DrawXYZ-Callin== | |||
'''Spring.UnitRendering.SetUnitLuaDraw''' <span class="note">(enables the LuaRules' DrawUnit callin)</span> | |||
( number unitID, boolean enabled ) -> nil | ( number unitID, boolean enabled ) -> nil | ||
'''Spring. | '''Spring.FeatureRendering.SetFeatureLuaDraw''' <span class="note">(enables the LuaRules' DrawFeature callin)</span> | ||
( | ( number featureID, boolean enabled ) -> nil | ||
'''Spring.UnitRendering.SetProjectileLuaDraw''' <span class="note">(enables the LuaRules' DrawProjectile callin)</span> | |||
( number projectileID, boolean enabled ) -> nil | |||
==MaterialTypes== | |||
"alpha" | "alpha" | ||
"opaque" | "opaque" | ||
"alpha_reflect" | "alpha_reflect" | ||
"opaque_reflect" | "opaque_reflect" | ||
"shadow" | "shadow" | ||
==Material UserData== | ==Material UserData== | ||
| Line 45: | Line 56: | ||
==Material Table== | ==Material Table== | ||
Prior to 102.0: | |||
material = { | material = { | ||
["order" = number ,] | ["order" = number ,] | ||
["culling" = [[Lua_ConstGL#Culling|number face]] ,] | |||
["shader" = [[Lua_GLSL_Api|lua_shader]] | string "3do" | string "s3o" ,] | ["shader" = [[Lua_GLSL_Api|lua_shader]] | string "3do" | string "s3o" ,] | ||
<span class=note>(95.0: alias standard_shader)</span> | |||
["deferred_shader" = { vertex = ..., ... } ,] | |||
<span class=note>(new in 95.0, alias deferred. Deferred fragment shaders must *ONLY* write to gl_FragData[i] where | |||
i = {0 = normals, 1 = diffuse, 2 = specular, 3 = emissive, 4 = misc})</span> | |||
["texunits" = { | ["texunits" = { | ||
[ [0] = { ["tex" = <font color= | [ [0] = { ["tex" = <font color=#55ee99>[[Lua_OpenGL_Api#Textures|see gl.Texture]]</font> ,] | ||
["enable" = boolean true ] }, ] | ["enable" = boolean true ] }, ] | ||
[ [3] = <font color= | [ [3] = <font color=#55ee99>[[Lua_OpenGL_Api#Textures|see gl.Texture]]</font>, ] | ||
< | <span class=note>(upto [15] and supports holes in it)</span> | ||
} ,] | } ,] | ||
["texunit0" = <font color= | ["texunit0" = <font color=#55ee99>[[Lua_OpenGL_Api#Textures|see gl.Texture]]</font> ,] | ||
... | ... | ||
["texunit7" = <font color= | ["texunit7" = <font color=#55ee99>[[Lua_OpenGL_Api#Textures|see gl.Texture]]</font> ,] | ||
["prelist" = [[Lua_OpenGL_Api#Display_Lists|lua_displaylist]] ,] | ["prelist" = [[Lua_OpenGL_Api#Display_Lists|lua_displaylist]] ,] | ||
["postlist" = [[Lua_OpenGL_Api#Display_Lists|lua_displaylist]] ,] | ["postlist" = [[Lua_OpenGL_Api#Display_Lists|lua_displaylist]] ,] | ||
["usecamera" = boolean ,] | ["usecamera" = boolean ,] | ||
["cameraloc" = number ,] | ["cameraloc" = number uniformLocation,] | ||
["cameraposloc" = number uniformLocation,] | |||
["camerainvloc" = number uniformLocation,] | |||
["sunposloc" = number uniformLocation,] <span class=note>(new in 0.83)</span> | |||
["shadowloc" = number uniformLocation,] | |||
["shadowparamsloc" = number uniformLocation,] | |||
} | } | ||
Post 102.0: | |||
Material tables are now expected to contain subtables defining the uniforms; instead of | |||
material = {shader = ..., cameraposloc = 123, texunits = ..., ...} | |||
say | |||
material = {shader = ..., uniforms = {cameraposloc = 123, ...}, texunits = ..., ...} | |||
For a material that has both types of shader, supply "standardshader", "deferredshader", "standarduniforms", and "deferreduniforms" as keys i.e: | |||
material = {standardshader = ..., standarduniforms = {...}, deferredshader = ..., deferredunifroms = { ... }, texunits = ..., ...} | |||
New keys for these uniform subtables can be | |||
"viewmatrixloc" // synonym for "cameraloc" | |||
"projmatrixloc" // camera projection | |||
"viprmatrixloc" // camera view-projection | |||
"viewmatrixinvloc" // synonym for "camerainvloc" | |||
"projmatrixinvloc" // camera inverse projection | |||
"viprmatrixinvloc" // camera inverse view-projection | |||
"shadowmatrixloc" // synonym for "shadowloc" | |||
"cameradirloc" // camera forward direction | |||
"sundirloc" // synonym for "sunposloc" | |||
"rndvecloc" // random 3-vector with length in [0, 1) | |||
"simframeloc" // current simulation frame | |||
"visframeloc" // current renderer frame | |||
[[category: Lua]] | |||
Latest revision as of 02:11, 17 September 2021
Development < Lua Scripting < Lua UnitRendering
Unit & Feature Rendering
New in version 101.0 These functions are now also duplicated for features i.e. Spring.FeatureRendering.X
Spring.UnitRendering.SetLODCount
( number unitID, int lodCount ) -> nil
Spring.UnitRendering.SetLODLength (`lod` is 1-indexed)
( number unitID, int lod, number lodLength ) -> nil
Spring.UnitRendering.SetLODDistance (same as SetLODLength(), but adjusted for 45deg FOV + 1024x768)
(number unitID, int lod, number lodDistance ) -> nil
Spring.UnitRendering.SetPieceList (displayList=nil reset to default)
( number unitID, int lod, int piece [, number displayList = nil ] ) -> nil
Spring.UnitRendering.GetMaterial (creates a material userdata)
( string MaterialType, table Material ) -> userdata Material
Spring.UnitRendering.SetMaterial
( number unitID, int lod, string MaterialType, userdata Material | table Material ) -> nil
Spring.UnitRendering.SetMaterialLastLOD
( number unitID, string MaterialType, int lastLOD ) -> nil
Spring.UnitRendering.SetMaterialDisplayLists
( number unitID, int lod, string MaterialType, preDisplayList, postDisplayList ) -> nil
Spring.UnitRendering.SetUnitUniform (unfinished)
( number unitID, string MaterialType, int lod, arg1, arg2, ... ) -> nil
Debug
Spring.UnitRendering.Debug (prints some usefull debug informations)
( [ number unitID ] ) -> nil
Lua's DrawXYZ-Callin
Spring.UnitRendering.SetUnitLuaDraw (enables the LuaRules' DrawUnit callin)
( number unitID, boolean enabled ) -> nil
Spring.FeatureRendering.SetFeatureLuaDraw (enables the LuaRules' DrawFeature callin)
( number featureID, boolean enabled ) -> nil
Spring.UnitRendering.SetProjectileLuaDraw (enables the LuaRules' DrawProjectile callin)
( number projectileID, boolean enabled ) -> nil
MaterialTypes
"alpha" "opaque" "alpha_reflect" "opaque_reflect" "shadow"
Material UserData
none user accessible methods (yet)
Material Table
Prior to 102.0:
material = {
["order" = number ,]
["culling" = number face ,]
["shader" = lua_shader | string "3do" | string "s3o" ,]
(95.0: alias standard_shader)
["deferred_shader" = { vertex = ..., ... } ,]
(new in 95.0, alias deferred. Deferred fragment shaders must *ONLY* write to gl_FragData[i] where
i = {0 = normals, 1 = diffuse, 2 = specular, 3 = emissive, 4 = misc})
["texunits" = {
[ [0] = { ["tex" = see gl.Texture ,]
["enable" = boolean true ] }, ]
[ [3] = see gl.Texture, ]
(upto [15] and supports holes in it)
} ,]
["texunit0" = see gl.Texture ,] ... ["texunit7" = see gl.Texture ,]
["prelist" = lua_displaylist ,] ["postlist" = lua_displaylist ,] ["usecamera" = boolean ,] ["cameraloc" = number uniformLocation,] ["cameraposloc" = number uniformLocation,] ["camerainvloc" = number uniformLocation,] ["sunposloc" = number uniformLocation,] (new in 0.83) ["shadowloc" = number uniformLocation,] ["shadowparamsloc" = number uniformLocation,] }
Post 102.0:
Material tables are now expected to contain subtables defining the uniforms; instead of
material = {shader = ..., cameraposloc = 123, texunits = ..., ...}
say
material = {shader = ..., uniforms = {cameraposloc = 123, ...}, texunits = ..., ...}
For a material that has both types of shader, supply "standardshader", "deferredshader", "standarduniforms", and "deferreduniforms" as keys i.e:
material = {standardshader = ..., standarduniforms = {...}, deferredshader = ..., deferredunifroms = { ... }, texunits = ..., ...}
New keys for these uniform subtables can be
"viewmatrixloc" // synonym for "cameraloc"
"projmatrixloc" // camera projection
"viprmatrixloc" // camera view-projection
"viewmatrixinvloc" // synonym for "camerainvloc"
"projmatrixinvloc" // camera inverse projection
"viprmatrixinvloc" // camera inverse view-projection
"shadowmatrixloc" // synonym for "shadowloc"
"cameradirloc" // camera forward direction
"sundirloc" // synonym for "sunposloc"
"rndvecloc" // random 3-vector with length in [0, 1)
"simframeloc" // current simulation frame
"visframeloc" // current renderer frame