Difference between revisions of "Mapping:HowTo:Adding light to models"

From Custom Map Makers Wiki
Jump to: navigation, search
(Created page with "fucking lazy")
 
(First version of adding light to the models. Article covers md3 - .ase is needed.)
Line 1: Line 1:
fucking lazy
+
Adding light to models is fairly easy. All You have to do is write a shader for part, that will be emitting light.
 +
 
 +
 
 +
 
 +
== Working with model<br/> ==
 +
 
 +
Every good model has obvious light parts textures separated. We will use Suburbs streetlight model as an example. You can get it [http://www.blackrayne.net/downloads/br_suburbs.zip here], from Black Rayne Studios for free. These are md3 models, the native format for Q3 engine which Urban Terror uses. When You unpack it, You will find inside many textures, md3 files (these are models itself) and .qc files. You need to open in simple text editor (like notepad for example) .qc file with the name corresponding to model you want to make shine - in our case - br_streetlight1.qc .
 +
<pre>// Quake III Arena MD3 control file, generated by MilkShape 3D
 +
//
 +
$model "models/mapobjects/br_suburbs/br_streetlight1.md3"
 +
// reference frame
 +
//$frames -1 -1
 +
// frame 1-30
 +
$frames 1 30
 +
$flags 0
 +
$numskins 0
 +
 +
// you can have one or no parent tag
 +
 +
// tags
 +
 +
// meshes (surfaces)
 +
$mesh "br_cement"
 +
$skin "models/mapobjects/br_suburbs/br_cement.jpg"
 +
$flags 0
 +
 +
$mesh "br_bulb1"
 +
$skin "models/mapobjects/br_suburbs/br_bulb1.jpg"
 +
$flags 0
 +
 +
$mesh "br_lightpost1"
 +
$skin "models/mapobjects/br_suburbs/br_lightpost1.jpg"
 +
$flags 0
 +
</pre>
 +
<br/>What is important for you are 'skins' line containing names of the textures used. You can easily identify the texture that is supposed to be the light emiter - in our case - br_bulb1.jpg .
 +
 
 +
 
 +
 
 +
== Working with shader<br/> ==
 +
 
 +
Now we can write a shader in order to emit light by one particular texture. I suggest that shader:
 +
<pre>models/mapobjects/br_suburbs/br_bulb1
 +
{
 +
  qer_editorimage models/mapobjects/br_suburbs/br_bulb1.jpg
 +
  q3map_surfacelight 70000
 +
  //same colour light as the sky
 +
  q3map_lightImage textures/ut4_workshops/chmury1niebo.jpg
 +
  surfaceparm nomarks
 +
  {
 +
    map $lightmap
 +
    rgbGen identity
 +
  }
 +
  {
 +
    map models/mapobjects/br_suburbs/br_bulb1.jpg
 +
    blendFunc GL_DST_COLOR GL_ZERO
 +
    rgbGen identity
 +
  }
 +
  {
 +
    map models/mapobjects/br_suburbs/br_bulb1.jpg
 +
    blendfunc GL_ONE GL_ONE
 +
  }
 +
}</pre>
 +
<br/>When you make .pk3 with .md3 model, You don't&nbsp; include .md3 and .qc files - they are "baked" into compiled map. But you have to copy textures to proper folders in mapobjects directory. That's why paths to the texture in shader is different then rest of your textures. The two most important parts of the shader are:
 +
<pre>  q3map_surfacelight 70000</pre>
 +
<br/>This will add light itself - the value means the light intensity. There is no "proper" value - you have to modify it, compile map every time, until You are satisfied with final effect.
 +
<pre>  q3map_lightImage textures/ut4_workshops/chmury1niebo.jpg</pre>
 +
This will modify light color to match sky's one. You need to add path to your sky texture. This is optional. Default light color is white.
 +
 
 +
 
 +
 
 +
 
 +
 
 +
== Let there be light!<br/> ==
 +
 
 +
Final effect in game will look like this:
 +
 
 +
[[File:Addinglighttothemodel.jpg|frame|none]]

Revision as of 08:50, 24 August 2011

Adding light to models is fairly easy. All You have to do is write a shader for part, that will be emitting light.


Working with model

Every good model has obvious light parts textures separated. We will use Suburbs streetlight model as an example. You can get it here, from Black Rayne Studios for free. These are md3 models, the native format for Q3 engine which Urban Terror uses. When You unpack it, You will find inside many textures, md3 files (these are models itself) and .qc files. You need to open in simple text editor (like notepad for example) .qc file with the name corresponding to model you want to make shine - in our case - br_streetlight1.qc .

// Quake III Arena MD3 control file, generated by MilkShape 3D
//
$model "models/mapobjects/br_suburbs/br_streetlight1.md3"
// reference frame
//$frames -1 -1
// frame 1-30
$frames 1 30
$flags 0
$numskins 0
 
// you can have one or no parent tag
 
// tags
 
// meshes (surfaces)
$mesh "br_cement"
$skin "models/mapobjects/br_suburbs/br_cement.jpg"
$flags 0
 
$mesh "br_bulb1"
$skin "models/mapobjects/br_suburbs/br_bulb1.jpg"
$flags 0
 
$mesh "br_lightpost1"
$skin "models/mapobjects/br_suburbs/br_lightpost1.jpg"
$flags 0


What is important for you are 'skins' line containing names of the textures used. You can easily identify the texture that is supposed to be the light emiter - in our case - br_bulb1.jpg .


Working with shader

Now we can write a shader in order to emit light by one particular texture. I suggest that shader:

models/mapobjects/br_suburbs/br_bulb1
{
   qer_editorimage models/mapobjects/br_suburbs/br_bulb1.jpg
   q3map_surfacelight 70000
   //same colour light as the sky
   q3map_lightImage textures/ut4_workshops/chmury1niebo.jpg
   surfaceparm nomarks
   {
     map $lightmap
     rgbGen identity
   }
   {
     map models/mapobjects/br_suburbs/br_bulb1.jpg
     blendFunc GL_DST_COLOR GL_ZERO
     rgbGen identity
   }
   {
     map models/mapobjects/br_suburbs/br_bulb1.jpg
     blendfunc GL_ONE GL_ONE
   }
}


When you make .pk3 with .md3 model, You don't  include .md3 and .qc files - they are "baked" into compiled map. But you have to copy textures to proper folders in mapobjects directory. That's why paths to the texture in shader is different then rest of your textures. The two most important parts of the shader are:

   q3map_surfacelight 70000


This will add light itself - the value means the light intensity. There is no "proper" value - you have to modify it, compile map every time, until You are satisfied with final effect.

   q3map_lightImage textures/ut4_workshops/chmury1niebo.jpg

This will modify light color to match sky's one. You need to add path to your sky texture. This is optional. Default light color is white.



Let there be light!

Final effect in game will look like this:

Addinglighttothemodel.jpg