Jump to content

BSLightingShaderProperty Basics


ImsumDave

Recommended Posts

BSLightingShaderProperty Basics



Introductory Information
Diffuse

Environment/Reflection
Specular and Glossiness
Glow/Emissive
Alpha/Transparency/Opacity

Normal Mapping

Refraction
Parallax
MultiLayer Parallax

Notes and Miscellaneous Information


INTRODUCTORY INFORMATION

I've uploaded some files that may be helpful, including a shader showcase nif, and blending and testing nif. They can be found at this link.

 

Nifskope
Nifskope is a program that can open, view, and save nif files. The nif file format is the model, or mesh, data storage format used in games that utilize the Gamebryo Engine, formerly Netimmerse, and spin-offs of that, which include all games made by Bethesda Game Studios (BGS), Morrowind on - starting with Skyrim, BGS redubbed their engine Creation Engine. Nif files also commonly contain animation data in various forms, shader and material data, collision information, and other miscellaneous data, such as inventory model preview rotation and zoom.

Nifskope includes:

  • an interactive model viewer
  • ability to view and edit nif data blocks/nodes via an expandable hierarchy view
  • animation preview
  • bsa archive browser
  • ability to edit data (grouped in related blocks) stored in the nif, via the block list and block details menus
  • game-accurate viewport shaders
  • a viewport that changes in realtime to changes made in the nif data
  • ability to view and edit collision information
  • and more.................... ... .. .​

Get Nifskope - Github Niftools/Niskope Releases Page
(a more recent dev build can also be found here: https://github.com/jonwd7/nifskope/releases)

Learn about niftools here on the Niftools About

Shaders
In the context of 3d graphics, a shader is a set or sets of predetermined calculations that utilize multiple inputs to generate specific visual outputs to aid in rendering a desired image. The term is general and can cover a range of things. Specific to the case at hand, shaders are used to aid rendering by simulating various materials upon the surfaces of 3d models.

BSLightShaderProperty
You might be asking what a BSLightingShaderProperty is. It is a data block, or grouping of related data, that exists within a nif file. It contains data that the in-game shaders use to define how the surfaces of a model are rendered (shaded). It is used in Skyrim LE and Skyrim SE. The niftools team, as well as other contributors from the community, have decoded and translated that data so that it can be displayed, understood, and edited in Nifskope, and elsewhere.

A quick tip: It is not necessary to build your own BSLightingShaderProperty from scratch. Things are made much easier by copying and pasting a BSLightingShaderProperty from elsewhere before modifying it for your needs.

Textures
What is a texture?
In the context of 3D art, a texture is an image stored in some digital format. These images are a means of storing information that is used in calculations related to a models surface shading. They are inputs to a shader.

Digital images come in a variety of forms and formats. In their most basic form they are linear uncompressed grayscale. That is a two-dimensional array of values - a single image channel - each value lying at or between some minimum and maximum. These values will eventually be interpreted and displayed to you as an array of pixels, also know as an image. Typically, the maximum will be displayed as white and the minimum will be displayed as black; any value lying between them will be some shade of gray. In the case of a color image, three separate grayscale images - called image channels - are used to reconstruct the color information. The three image channels store values of red, green, and blue intensity. For this reason, a color image can be called an RGB image, as short-hand. A color image can also have an additional image channel tacked on, called an alpha channel - such an image could be called an RGBA image. This likely first became common place as a means of describing transparent areas of an image, which is how it is sometimes used in 3d graphics, however, this additional information can be used for various purposes, determined by how a particular shader is programmed

At their most basic level, computers utilize binary information. Any information that will be interpreted by a computer will exist as ones and zeros, in some form - on the harddrive, ssd, cache, ram, et cetera. This information is stored as bits, each bit representing a one or a zero. However, a single bit of information is not useful for much by itself, so bits are often packaged together in sets of eight, called bytes. When you see an integer value in decimal displayed on your screen, it exists in the computer, at some level, as a set of binary information. For example, the decimal value 255 is 11111111 in binary, which can be stored in one byte. This brings me to the most common image bit-depth you will encounter, which is 8-bit. When an uncompressed image has an 8-bit bit-depth, it means that each image channel value of each pixel is stored as one byte, with some binary value at or between 0 and 11111111, or decimal value 0 to 255.

A linear image is one whose image channel values are interpreted and displayed linearly, in a linear color space. That means that, in the case of an 8-bit grayscale image, a value of 127 will be displayed as midway between black and white; it being the mid point (also sometimes 128) between 0 and 255. In the case of an RGB color image, mid gray is red value 127, blue value 127, and green value 127; this can be written as the 8-bit color value 127, 127, 127.


Direct Draw Surface Image Format

Many games utilize the direct draw surface (dds) image format as their texture image format of choice - Skyrim is among those games. The dds format supports storing images in both compressed or uncompressed forms, of which there are various types. Supported types depend on the graphics hardware and its supported DirectX version, as well as the games supported DirectX version. The compressed form uses BCn compression of some type, which type is denoted by the labels BC1 through BC7. More infomation about BCn compression can be found here, in this well written article by Nathan Reed.

Shader Inputs
A shader will typically utilize more than one texture, as well as other more simply defined inputs, in order to control the resulting output. Utilizing nifskope, we can see and edit these inputs, both in the block details of the BSLightShaderProperty (more simply defined inputs), and by changing the texture paths in the BSShaderTexture set block - which point to textures that can be edited using some other software.

The following image shows the block details of a BSLightingShaderProperty, in this case with an Environment Map shader setup, and BSShaderTextureSet, with labeled texture slots. The [RGB] label means red, green, and blue color image channels. The [A] label means alpha image channel. The [bC4] label means high quality grayscale BCn compression type, grayscale image.
qk5tcMx.jpg

 

 

 

 

DIFFUSE

 

What is it?

The base color of the models surface.

 

Requirements

BSLightingShaderProperty

Shader Flags 2 ~ Vertex_Colors ENABLED *only required if you are using vertex colors

 

Appearance Controllers
NiTriShapeData / BSTriShape

Vertex Colors

BSShaderTextureSet

Diffuse [RGB] [TEXTURE SLOT 1]

 

 

 

 

ENVIRONMENT / REFLECTION

 

What is it?
Simulates the general reflection of the surrounding environment on the models surface. The simulated environment reflections are not necessarily mirror like, although they can be with the right settings and cubemap (environment map). Cubemaps are bre-baked images,
six sides of a cubic environment projection stored in one color image. Another common environment map type is a spherical environment map, although I do not believe it is supported in Skyrim. Some games have dynamic cubemap switching, in combination with in-editor area-based auto-baked cubemaps, to enable better accuracy of the reflections to actual in-game environments. Skyrim does not support such a thing, as far as I am aware.

Requirements
BSLightingShaderProperty

Skyrim Shader Type ~ 1 or Environment Map SET

Shader Flags 1 ~ Environment_Mapping ENABLED

Shader Flags 2 ~ Glow_Map DISABLED

​BSShaderTextureSet

Cubemap aka Environment Map [RGB] [TEXTURE SLOT 5]


Appearance Controllers
BSLightingShaderProperty

Environmental Map Scale, unclamped float ​

1.0 is normal intensity

0.0 is generally lowest intensity, aka off
greater than 1.0 is higher intensity, brighter

​BSShaderTextureSet

Cubemap aka Environment Map [RGB] [TEXTURE SLOT 5]

is generally 6 sides of a cubic environment projection stored in one color image

a black pixel is minimum intensity, environment/cube map has no effect in these areas

a white pixel is maximum intensity

intensity / brightness of cubemap increases as shade approaches white

Environment / Reflection Mask [bC4] [TEXTURE SLOT 6]

a black pixel is minimum intensity, environment/cube map has no effect in these areas

a white pixel is maximum intensity

intensity / brightness of cubemap increases as shade approaches white


Environment Map Scale Environment/cube map Environment/reflection mask
http://i.imgur.com/RX74xjJ.png

 

 

 

 

SPECULAR AND GLOSSINESS

What is it?
Dynamically simulates highlights from in-game light sources on the models surface. Specular is not required for your model to receive lighting, only (specular) highlights. In Skyrim's case, in-game lights include: the sun, moonlight, torches, fires, lanterns, magical auras, and natural light sources in interiors - in some cases, things that seem like they should emit light do not and are actually just visual effect fakery.

Requirements
BSLightingShaderProperty

Shader Flags 1 ~ Specular ENABLED

Appearance Controllers
BSLightingShaderProperty

Specular Strength

1.0 is normal intensity

0.0 is minimum intensity
greater than 1.0 is higher than normal intensity, brighter

Specular Color

color of the specular highlight

Glossiness

width of the specular highlight

10 is a wide specular highlight

50 is a thinner specular highlight
100 is an even thinner specular highlight

value ranges from 0 to 999

BSShaderTextureSet

Grayscale Specular Map [A] [TEXTURE SLOT 2]

alpha image channel stored with normal map [RGB]

black pixel is minimum intensity, no specular highlight

white pixel is maximum intensity, maximum defined by BSLightingShaderProporty "Specular Strength"
intensity / brightness increases as shade approaches white


Specular strength Specular color Specular map
http://i.imgur.com/ovqWo5F.png

Glossiness
http://i.imgur.com/UCRj5ih.png


 

 

GLOW / EMISSIVE

What is it?
Simulates a glowing surface. Does not emit light, simply fakes the look of light emission.

Requirements
BSLightingShaderProperty

Skyrim Shader Type ~ 2 or Glow Shader SET
Shader Flags 2 ~ Glow_Map ENABLED
Shader Flags 1 ~ Environment_Mapping DISABLED

Appearance Controllers
BSLightingShaderProperty

Emissive Multiple

1.0 is normal intensity

0.0 is minimum intensity, no glow
greater than 1.0 is higher than normal intensity, brighter

Emissive Color

color of glow, color also influenced by emissive / glow map color

BSShaderTextureSet

Emissive / Glow Map [RGB] [TEXTURE SLOT 3]

glow map is generally a color [RGB] image, or can be grayscale

black pixel is minimum intensity, no glow

white pixel is maximum intensity, maximum defined by BSLightingShaderProporty "Emissive Multiple"


Emissive multiple Emissive color Emissive/glow map
http://i.imgur.com/vNOVwrY.png

 

 

 

ALPHA / TRANSPARENCY / OPACITY

What is it?

Simulates model surface opacity or transparency - either via on off testing or blending. Testing and blending can be used together or alone. Testing is used in situations where the model's surface is either fully visible or invisible, with no in-between. Blending is most commonly used for surfaces requiring transparency or semi-opacity.

 

Requirements
NiAlphaProperty

ATTACHED to NiTriShape

Flags ~ Enable Blending ENABLED *optional can use testing, blending, or both

Source Blend Mode ~ Src Alpha SET

Destination Blend Mode ~ Inv Src Alpha SET

Flags ~ Enable Testing ENABLED *optional can use testing, blending, or both

Alpha Test Function ~ Greater or Equal SET

Alpha Test Threshold ~ Some Value Between 0 and 255 SET

BSLightingShaderProperty

Shader Flags 1 ~ Vertex_Alpha ENABLED *only required if you are using vertex color alphas

Shader Flags 2 ~ Vertex_Colors ENABLED *only required if you are using vertex color alphas

 

Appearance Controllers
NiAlphaProperty

Flags ~ Alpha Test Threshold

a setting of 0 results in testing not hiding any area of the model's surface

a setting of 127 results in any area of the model's surface that has an alpha value below 127 being invisible

a setting of 255 results in any area of the model's surface that has an alpha value below 255 being invisible

BSLightingShaderProperty

Alpha

1.0 is fully visible, opaque

0.0 is fully transparent, invisible

BSShaderTextureSet

Alpha / Transparency / Opacity [A] [TEXTURE SLOT 1]

black is fully transparent, invisible

white is fully visible, opaque
visibility decrease as shade approaches black

NiTriShapeData

Vertex Colors Alpha

only alpha channel has an effect

Alpha Transparency map
http://i.imgur.com/ZrT7mVO.png

 

Blend Modes and NiAlphaProperty Settings

The NiAlphaProperty node allows for more blending techniques than just transparency, such as additive, multiplicative, and overlay (combination of additive multiplicative). These blend modes may or may not make use of the alpha channel of the model. Some use the destination (background) alpha. Some use the destination color. Some use the source (model's surface) alpha. Some use the source color.

 

NiAlphaProperty Settings - in the below image "2x Multiplicative" is the term used for overlay blending
http://i.imgur.com/QlE7LgX.png


Color Blending

Color Blending Equation
(Source * SourceBlendFactor) + (Destination * DestinationBlendFactor) ::
applied per channel (red, green, blue), per pixel

for each channel (red, green, blue)
"Source" is the normalized channel value of the model surface materials in that pixel
"SourceBlendFactor" is the normalized multiplication factor applied to the source value

"Destination"
is the normalized channel value of the background in that pixel
"DestinationBlendFactor" is the normalized multiplication factor applied to the destination value

Blend Factors
One - multiply by one
Zero - multiply by zero
Src Color - multiply by "Source" color value
Inv Src Color - multiply by inverse "Source"
color value
Dst Color - multiply by "Destination" color value
Inv Dst Color - multiply by inverse "Destination" color value
Src Alpha - multiply by value of the model's (Source) alpha channels (diffuse and vertex colors) present at that pixel
Inv Src Alpha - multiply by inverse value of the model's
(Source) alpha channels (diffuses and vertex colors) present at that pixel
Dst Alpha - multiply by value of the background's combined alpha channels (diffuse and vertex colors) present at that pixel
Inv Dst Alpha - multiply by inverse value of the background's combined alpha channels (diffuse and vertex colors) present at that pixel

 

 

 

 

NORMAL MAP

 

What is it?

A texture in which data is encoded that is used to bias the lighting on, or shading of, the model's surface. It is used to fake the shape and complexity of a models surface. There are a few types, the type used in Skyrim is tangent-space normal mapping.

 

Requirements

NiTriShapeData / BSTriShape

BS Vector Flags ~ Has_UV *in some versions of nifskope this does not exist, instead set BS Data Flags to 4097

BS Vector Flags ~ Has_Tangents *in some versions of nifskope this does not exist, instead set BS Data Flags to 4097

Has Normals ~ YES

BSShaderTextureSet

Normal Map [RGB] [TEXTURE SLOT 2]

 

Appearance Controllers
NiTriShapeData / BSTriShape

Model's Surface Normals

BSShaderTextureSet

Normal Map [RGB] [TEXTURE SLOT 2]

 

 

 


REFRACTION

What is it?
Simulates image distortion due to refraction of light through a surface. Objects behind the model will be distorted depending on the shader settings used.

Requirements
BSLightingShaderProperty

Shader Flags 1 ~ Refraction ENABLED


Appearance Controllers
NiTriShapeData / BSTriShape

Model's Surface Normals

Vertex Colors Alpha

Alpha channel of vertex colors controls transparency without the need for a NiAlphaProperty

BSLightingShaderProperty

Refraction Strength

1.0 is maximum intensity, most extreme distortion

0.0 is minimum intensity, no distortion

BSShaderTextureSet

Normal Map [RGB] [TEXTURE SLOT 2]

 

 

 

PARALLAX

What is it?

Simulates height variation on the model's surface. Fairly resource intensive, but also more realistic than normal mapping. Parallax mapping fakes surface deformation.

Requirements
ENB required to function properly!
BSLightingShaderProperty

Skyrim Shader Type ~ 3 or Heightmap SET
Shader Flags 1 ~ Parallax ENABLED

Appearance Controllers
BSShaderTextureSet

Height / Parallax [bC4] [TEXTURE SLOT 4]

height / parallax map is a grayscale image

mid gray (RGB, 127, 127, 127) is zero depth and height
black pixel is maximum depth
white pixel is maximum height

 

 

MULTILAYER PARALLAX

What is it?
Simulates an inner layer under the model's surface, optionally simulates refraction of that inner layer as well.


Requirements

MultiLayer Parallax Shader Does Not Require NiAlphaProperty!

BSLightingShaderProperty

Skyrim Shader Type ~ 11 or MultiLayer Parallax SET
Shader Flags 2 ~ Multi_Layer_Parallax ENABLED

Appearance Controllers
Environment map and specular / glossiness have no effect on the inner layer!
BSLightingShaderProperty

Parallax Inner Layer Thickness

controls inner layer max depth

depth increases as value increases

Parallax Refraction Scale

deforms the inner layer based on outer layer normal map detail, viewing angle, and inner layer depth

refraction intensity increases as value increases
(maybe?) max is 1

Parallax Inner Layer Texture Scale

inner layer diffuse tiling

density of tiling increases as values increase (x and y)
x and y control the axis of tiling

Parallax Envmap Strength

outer layer environment map intensity increases as value increases

BSShaderTextureSet

Diffuse [RGB] [TEXTURE SLOT 1]

Alpha / Transparency / Opacity [A] [TEXTURE SLOT 1]

viewing angle affects transparency

viewing the surface at a steeper angle increases opacity
black is almost completely transparent (see above)
white is opaque

Subsurface Color [RGB] [TEXTURE SLOT 3]

used to fake subsurface scattering

Inner Layer Diffuse [RGB] [TEXTURE SLOT 7]

inner layer diffuse is the diffuse texture of the inner layer

Inner Layer Depth [A] [TEXTURE SLOT 7]

inner layer depth is a grayscale image

controls the depth of the inner layer from the outer layer
black is minimum depth (inner layer distance from outer layer is 0)
white is maximum depth (inner layer distance from outer layer is max)

 

 

 


NOTES AND MISCELANEOUS INFORMATION

DDS image format as it pertains to Skyrim

MIP Mapping
Always generate MIP maps when saving a DDS image for use in Skyrim. Saving a DDS image without MIP maps has been known to cause lag on asset load (ex. pause when swapping weapons). Google MIP mapping if you'd like the details about what it is and what it does.

DXT compression (DXT1, DXT3, DXT5) - Alternate BCn Compression Labels
DXT1, DXT3, and DXT5 all use the same compression method for the RGB image channels. The difference between them comes from how the alpha image channel is compressed. DXT compression can (will) cause artifacts in the texture, especially in areas with gradients. The benefit of compressed textures is the smaller size on disk and in RAM.

DXT1 – no alpha
DXT3 – explicit alpha
DXT5 – interpolated alpha

Uncompressed (8.8.8.8 ARGB, 8.8.8 RGB)
Uncompressed dds images are quite large (space on disk and in RAM) compared to those saved with DXT compression. The benefit of uncompressed textures is the lack of compression artifacts. This can be important when artifacts are noticeable in-game.

**if textures are too large, this can cause lag on asset load, especially with slower computers

http://i.imgur.com/9i73dwu.gif
(ignore gif compression, small specks in RGB images)


Layering

Incompatibility between some effects can be worked around by layering meshes (NiTriShape). For example, for glow shader and environment map, one NiTriShape will have a BSLightingShaderProperty set up for environment mapping, while another will be set up for glow. The glow NiTriShape will use alpha transparency to hide all areas that do not have the glow effect. The glow map can be used for the transparency map in diffuse alpha image channel. This workaround can be used in many different ways, be creative.

Edited by ImsumDave
Link to comment
Share on other sites

No problem. I made this quite a while ago. I posted it with an incorrect name. This information can be quite hard to find and even harder to figure out for a beginner. I made this as a quick reference. There is quite a bit of information missing. I only included what I know to be correct (ignoring the height map slot). I might add refraction, normal mapping, and parallax mapping information in the future.

Link to comment
Share on other sites

No, I haven't used BSEffectShaderProperty at all up to this point. As for shader property controllers, I was playing around with them a bit in the past. I was trying to make a pulsing glow effect. In fact, the head in my Longclaw mod uses that exact effect. You could take a look at that if you need an example. I can't really explain any of it off the top of my head atm. It's been quite a while since I played around with them. This niftools thread has some useful info.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...