For a brief tutorial on shaders see: https://github.com/mtijanic/nwnee-shader-tutorials
These lists may be incomplete for the latest version of the game and needs reformatting into a better resource list.
Uniforms
* int screenWidth, int screenHeight
Viewport size.
* float nearClip, float farClip
Render clipping cutoff.
* int sceneCurrentFrame
The current render frame. No guarantees to limits or wrapping behaviour.
* int worldtimerTimeOfDay
The current time of day as seen from the game world, in milliseconds. This value will pause when the game pauses.
(MerricksDad: this value is the number of ticks since the client was started. The value is equal to 1444000 ticks per day divided by the number of moduleMinutesPerHour. The additional value appears to be a multi-hour error value related to the number in moduleMinutesPerHour, )
* int windPointSourcesCount (max: 128)
A wind point source is a "explosion" source. You can see this with some spells that bend grass around you.
This is the number of wind point sources for the current frame; you need this to walk the following vectors:
* float windPointSourcesPosition[windPointSourcesCount*3]
A vector of X, Y, Z positions for each windPointSource.
* float windPointSourcesRadius[windPointSourcesCount]
The radius for each windPointSource.
* float windPointSourcesIntensity[windPointSourcesCount]
The intensity for each windPointSource.
* float windPointSourcesTimeRemaining[windPointSourcesCount]
The time remaining for each windPointSource.
* int moduleDawnHour
The module dawn hour (usually something like 8).
* int moduleDuskHour
The module dusk hour (usually something like 16).
* int moduleMinutesPerHour
Minutes per hour. You can use this to calculate the dawn/dusk progression.
* vec3 areaGlobalWind
The global wind vector for the current area (including magnitude).
* int areaWeatherType
The weather type: 0 = clear, 1 = rain, 2 = snow.
* float areaWeatherDensity
The weather density as determined by the engine.
* int areaFlags
A mask of area flags: 1 = interior, 2 = underground, 4 = natural
* int moduleYear
(MerricksDad: testing of moduleYear has shown that it does not always get sent to the shader with correct value. Using this value for any purpose can result in counted effects being misrendered.)
* int moduleMonth
* int moduleDay
* int moduleHour
The module time as seen by the player.
(MerricksDad: moduleHour is the integer value of the true module time. Being converted from a float originally, this value will have loss. Testing has shown the offset in module hour to be multiple seconds forward or backward, meaning this value cannot be used as an exact match for the true moduleHour. The lower moduleMinutesPerHour is, the larger the error will appear.)
* float moduleTimeIntoTransition
(MerricksDad: This value counts up from the last transition, such as moduleDuskHour or moduleDawnHour. It has a few issues. The first issue is that it resets to 0 at multiple points: moduleDawnHour, moduleDawnHour+1, moduleDuskHour, and moduleDuskHour+1. It also resets to 0 when the client enters the game, so its initial value is not useful before the first transition it reached.)
* float moduleTransitionTime
This describes the day/dusk/dawn/night transition animations for areas.
* ivec2 userinputMousePosition
Mouse coordinates.
* int userinputMouseButtons
A mask of mouse buttons currently down: 1 = left, 2 = right, 4 = middle.
* int fogEnabled
1 if fog is enabled.
* int fogMode
Fog mode (0 = linear, 1 = exp, 2 = exp2).
* float fogStart, float fogEnd
Fog render distances.
* vec4 fogColor
The current fog colour.
* int numLights
The number of dynamic lights currently in the scene.
* vec4 globalColor
The global/world colour.
* vec4 frontLightModelProductSceneColor
The scene colour (ambient light).
* vec4 materialFrontAmbient
* vec4 materialFrontDiffuse
* vec4 materialFrontSpecular
* vec4 materialFrontEmissive
* float materialFrontShininess
Material source components.
* vec4 lightAmbient
* vec4 lightDiffuse
* vec4 lightSpecular
* vec4 lightPosition
* vec4 lightHalfVector
* float lightConstantAtten
* float lightLinearAtten
* float lightQuadraticAtten
Light source parameters.
* int texUnitXX (where 0 <= XX < 14)
* int texUnitEnv
* int textureXXBound (where 0 <= XX < 14)
Bound textures.
* vec4 texCoordOffset0, vec4 texCoordOffset1
* float texCoordRot0, float texCoordRot1
Bound textures position and rotation.
* mat4 m_m
* mat4 m_mv
* mat4 m_mvp
Model, ModelView and ModelViewProjection matrices for vertex transformations.
* mat3 m_normal
Matrix for vertex normal transformations.
In addition to the uniforms, the following vertex attributes are exposed:
* vec4 vPos
Vertex position in object space.
* vec2 vTcIn
Texture coordinates for current texture.
* vec4 vColor
Active colour for the vertex.
* vec3 vNormal
Current vertex untransformed normal.
UPDATE: info posted by Sherincall on the nwvault #custom-content Discord channel on Monday 17 Feb, 2020:
📎 uniforms available to all shaders:
sceneCurrentFrame
worldtimerTimeOfDay
windPointSourcesCount
windPointSourcesPosition
windPointSourcesRadius
windPointSourcesIntensity
windPointSourcesTimeRemaining
moduleDawnHour
moduleDuskHour
moduleMinutesPerHour
moduleYear
moduleMonth
moduleDay
moduleHour
moduleTimeIntoTransition
moduleTransitionTime
areaGlobalWind
areaWeatherType
areaWeatherDensity
areaFlags
userinputMousePosition
userinputMouseButtons
m_mvp
m_mv
m_m
m_normal
m_texture
m_view
m_proj
m_vp
m_view_inv
m_proj_inv
m_vp_inv
m_bones[128]
idxmap[128]
lightAmbient[8]
lightDiffuse[8]
lightPosition[8]
lightQuadraticAtten[8]
numLights
FragmentLighting
GammaCorrection
materialFrontAmbient
materialFrontDiffuse
materialFrontSpecular
materialFrontEmissive
materialFrontShininess
frontLightModelProductSceneColor
globalColor
texUnit{0..14}
texUnitEnv
texture{0..15}Bound
fSchemeRow{0..14}
fogEnd
fogMode
fogStart
fogColor
fogEnabled
cameraPitch
cameraYaw
cameraPosition
cameraViewAngle
cameraDialogState
startFadePitch
keyholeCanDissolve
keyholeRadius
nearClip
farClip
screenWidth
screenHeight
AORadius
AOIntensity
AOColor
blackPoint
whitePoint
Vibrance
RGBBalance
DOFAmount
Gamma
playerPosition
playerOrientation
playerInCutscene
playerCameraDist
(plus whatever MTR+nwscript pass, for individual objects)
Standard Uniforms Available to Shaders
Updated List 2022/03/10 --Merricksdad
Uniform | Type | Located In | Purpose | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
texFBColor | sampler2D | inc_common | Frame buffer (screen pixel color) | ||||||||||||||||||||||
texFBDepth | sampler2D | inc_common | Depth Buffer | ||||||||||||||||||||||
fogParams | vec4 | inc_common | Contains XYZW =Â [fogEnabled, fogStart, FogEnd, fogInvEndMinusStart]. In older shaders these values were separate uniforms. | ||||||||||||||||||||||
playerPosition | vec3 | inc_common | player position in world coordinates | ||||||||||||||||||||||
playerCameraDist | float | inc_common | distance between player and camera position | ||||||||||||||||||||||
playerInCutscene | int | inc_common | flag denoting if player is in cutscene camera mode | ||||||||||||||||||||||
cameraPosition | vec3 | inc_common | position of the camera in world coordinates | ||||||||||||||||||||||
cameraPitch | float | inc_common | |||||||||||||||||||||||
cameraYaw | float | inc_common | |||||||||||||||||||||||
cameraFocus | vec3 | inc_common | the vector the camera is focused toward (ie. camera facing) | ||||||||||||||||||||||
cameraViewAngle | float | inc_common | |||||||||||||||||||||||
cameraDialogState | int | inc_common | |||||||||||||||||||||||
userinputMousePosition | ivec2 | inc_common | screenspace coordinates of mouse pointer | ||||||||||||||||||||||
screenParams | vec2 | inc_common | contains XY = [screenWidth, screenHeight]. In older shaders these values were separate uniforms. | ||||||||||||||||||||||
pixelParams | vec3 | inc_common | contains XYZ = [invScreenWidth, invScreenHeight, fAspectRatio] In older shaders these values were separate uniforms. | ||||||||||||||||||||||
clipParams | vec3 | inc_common | contains XYZ = [nearClip, farClip, fDepthToLinearModifier] In older shaders these values were separate uniforms. | ||||||||||||||||||||||
m_proj | mat4 | inc_common | matrix for converting from view to screen projection | ||||||||||||||||||||||
m_proj_inv | mat4 | inc_common | matrix for converting from screen projection to view | ||||||||||||||||||||||
m_vp_inv | mat4 | inc_common | matrix for converting from screen projection to world | ||||||||||||||||||||||
m_view_inv | mat4 | inc_common | matrix for converting from view to world | ||||||||||||||||||||||
m_view | mat4 | inc_common | matrix for converting from world to view | ||||||||||||||||||||||
m_texture | mat4 | inc_common | matrix for applying uv orientation | ||||||||||||||||||||||
m_mv | mat4 | inc_common | matrix for converting from model to view | ||||||||||||||||||||||
m_mvp | mat4 | inc_common | matrix for converting from model to screen projection | ||||||||||||||||||||||
texNoiseBound | int | inc_common | Equals 1 if noise texture was bound | ||||||||||||||||||||||
texture<n>Bound | int | inc_common | 11 separate uniforms identifying if texture n is bound, where <n> = 0 to 10 | ||||||||||||||||||||||
texEnvCubeBound | int | inc_common | Equals 1 if an environment cubemap is bound | ||||||||||||||||||||||
texEnvBound | int | inc_common | Equals 1 if an environment flatmap is bound | ||||||||||||||||||||||
m_boneRotations[] | vec4 | inc_common | Contains orientations of bones at the current frame for use with Mobile version | ||||||||||||||||||||||
m_bonePositions[] | vec4 | inc_common | Contains positions of bones at the current frame for use with Mobile version | ||||||||||||||||||||||
m_bones | mat4 | inc_common | Contains matrix transforms for bones (both position and rotation) for use with non-Mobile versions | ||||||||||||||||||||||
texUnit<n> | sampler2D | inc_common | 11 separate uniforms containing the texture sampler for texture n, where <n> = 0 to 10 | ||||||||||||||||||||||
DisplacementOffset | float | inc_common | Defines the offset from which height map displacement will begin. Can be modified in the material file using "parameter" lines | ||||||||||||||||||||||
texUnitEnv | sampler2D | inc_common | contains the texture sampler for the environment map | ||||||||||||||||||||||
texUnitEnvCube | samplerCube | inc_common | contains the cubemap sampler for a cubemap environment | ||||||||||||||||||||||
texUnitNoise | sampler2D | inc_common | contains the noise texture sampler | ||||||||||||||||||||||
envMapCube | int | inc_common | Equals 1 if environment map type is cubemap, otherwise type is flatmap | ||||||||||||||||||||||
fAlphaDiscardValue | float | inc_common | Contains the minimum alpha level to draw. Any value below this will be dropped, greatly speeding up rendering of transparent objects as they stack up over distance. | ||||||||||||||||||||||
skinmesh | int | inc_common | Equals 1 if the mesh type is a skinmesh | ||||||||||||||||||||||
Specularity | float | inc_material | Contains a specularity override value, as passed in from a material file. If not provided, specularity will be imported from texUnit2 red channel, or in the case that specularity is based on the environment map, it will be calculated from there. Positive values only. | ||||||||||||||||||||||
Roughness | float | inc_material | Contains a roughness override value, as passed in from a material file. If not provided, roughness will be imported from texUnit3 red channel, or in the case that roughness is also included in the spec map, it will be read from texUnit2 green channel. Positive values only. Use flag MATERIAL_READ_ROUGHNESS_FROM_SPECULAR_MAP = 1 to force reading from texUnit2 green channel. | ||||||||||||||||||||||
Metallicness | float | inc_material | Contains a metallicness override value, as passed in from a material file. If not provided, metallicness will be calculated from specularity. Positive values only. | ||||||||||||||||||||||
CustomSpecularColor | vec4 | inc_material | Contains a specular color override value, as passed in from a material file. Prevents specular color from being derived from albedo, height, and metallicness. | ||||||||||||||||||||||
lightColor[] | vec4 | inc_lighting | Contains the light color for each light passed to the shader for the scene. Used if gamma correction is enabled. | ||||||||||||||||||||||
lightMaxIntensityInv | float | inc_lighting | |||||||||||||||||||||||
lightFalloffFactor | float | inc_lighting | |||||||||||||||||||||||
lightAmbient[] | vec4 | inc_lighting | Contains the ambient light color for each light passed to the shader for the scene. Used if gamma correction is not enabled. | ||||||||||||||||||||||
lightDiffuse[] | vec4 | inc_lighting | Contains the diffuse light color for each light passed to the shader for the scene. Used if gamma correction is not enabled. | ||||||||||||||||||||||
lightQuadraticAtten[] | float | inc_lighting | Contains the light light falloff calculation for each light in the scene. | ||||||||||||||||||||||
lightPosition[] | vec4 | inc_lighting | Contains the position of each light in the scene in world coordinates. | ||||||||||||||||||||||
numLights | int | inc_lighting | Number of lights passed to the shader for the scene. | ||||||||||||||||||||||
staticLighting | int | inc_lighting | |||||||||||||||||||||||
lightAreaAmbient | vec3 | inc_lighting | The color of the area ambient lighting at this fragment | ||||||||||||||||||||||
lightAreaDiffuse | vec3 | inc_lighting | The color of the area diffuse lighting at this fragment | ||||||||||||||||||||||
lightAreaDiffuseDirection | vec3 | inc_lighting | Effectively the sun angle for the diffuse light from the sun | ||||||||||||||||||||||
materialFrontAmbient | vec4 | inc_lighting | The ambient light color of the fragment based on vertex color | ||||||||||||||||||||||
materialFrontDiffuse | vec4 | inc_lighting | The diffuse light color of the fragment based on vertex color | ||||||||||||||||||||||
materialFrontEmissive | vec4 | inc_lighting | The self illumination color of the fragment based on the self illumination value of the mesh. Added to total light of that fragment. | ||||||||||||||||||||||
frontLightModelProductSceneColor | vec4 | inc_lighting | Used mostly for GUI elements. Used to calculate constant light for those elements. | ||||||||||||||||||||||
keyholeCanDissolve | int | inc_keyhole | Equals 1 if keyholing is enabled and the material can be dissolved | ||||||||||||||||||||||
keyholeDiameterMax | float | inc_keyhole | |||||||||||||||||||||||
keyholeDiameterMin | float | inc_keyhole | |||||||||||||||||||||||
sceneCurrentFrame | int | inc_water | |||||||||||||||||||||||
worldtimerTimeOfDay | int | inc_water | MerricksDad: Note the pattern in the additional hours column. The decimal value is related to 1.0/moduleMinutesPerHour +/- 1.0 or 0.5 hours.
Daz (from Discord chat): "it's initialized with a default date/time and a default of 5mins/hour and when it gets the module's min/hour it'll set it to that and the current time will change the default datetime: year: 1340 month: 6 day: 1 hour: 23 minute: 59 second: 56 millisecond: 0. I guess going from 5min/h to 1min/h gets the hour changed to 7am." | ||||||||||||||||||||||
moduleYear | int | inc_water | MerricksDad: Testing of moduleYear has shown that it does not always get sent to the shader with correct value. Using this value for any purpose can result in counted effects being misrendered. | ||||||||||||||||||||||
moduleMonth | int | inc_water | Integer value of module month. Setting module time with NWScript or debug functions will also not update this value correctly. | ||||||||||||||||||||||
moduleDay | int | inc_water | Integer value of module day. Setting module time with NWScript or debug functions will also not update this value correctly. | ||||||||||||||||||||||
moduleHour | int | inc_water | Integer value of the module time. | ||||||||||||||||||||||
windPointSourcesCount | int | inc_water | Number of wind point sources in the scene | ||||||||||||||||||||||
windPointSourcesPosition[] | vec3 | inc_water | Contains the position of all wind sources in the scene | ||||||||||||||||||||||
windPointSourcesRadius[] | float | inc_water | Contains the radius of all wind sources in the scene | ||||||||||||||||||||||
windPointSourcesDuration[] | float | inc_water | Contains the expected duration of each wind source in the scene | ||||||||||||||||||||||
windPointSourcesIntensity[] | float | inc_water | Contains the wind intensity of each wind source in the scene | ||||||||||||||||||||||
windPointSourcesTimeRemaining[] | float | inc_water | Contains the remaining time allowed to each wind source in the scene | ||||||||||||||||||||||
moduleDawnHour | int | inc_water | The hour at which Dawn-related sky mixing occurs. Sent over to shader from module properties. | ||||||||||||||||||||||
moduleDuskHour | int | inc_water | The hour at which Dusk-related sky mixing occurs. Sent over to shader from module properties. | ||||||||||||||||||||||
moduleMinutesPerHour | int | inc_water | Time scale of the module. Also directly related to transition timers. Sent over to shader from module properties. | ||||||||||||||||||||||
moduleTimeIntoTransition | float | ??? | MerricksDad: It has a few issues. Otherwise, we can say that the following formula can match the module time since the last transition began or ended. | ||||||||||||||||||||||
moduleTransitionTime | float | ??? | MerricksDad: The scale of the transition time. For example, 1 hour is 60 units when moduleMinutesPerHour = 1. | ||||||||||||||||||||||
areaGlobalWind | vec3 | inc_water | Contains the global wind vector for the area | ||||||||||||||||||||||
areaWeatherDensity | float | inc_water | Contains the intensity of current weather | ||||||||||||||||||||||
areaFlags | int | inc_water | 1=Interior, 2=Underground, 4=Natural | ||||||||||||||||||||||
areaWeatherType | int | inc_water | 0=Clear/none, 2=Rain, 3=Snow | ||||||||||||||||||||||
m_m | mat4 | various / post processing | Matrix for converting from model to world coordinates | ||||||||||||||||||||||
projectionSource | vec4 | vs_beamvol vs_shadowvol | |||||||||||||||||||||||
projectionWorldZClip | float | vs_beamvol vs_shadowvol | |||||||||||||||||||||||
particleSizeMax | float | vsparticle | |||||||||||||||||||||||
particleSoften | int | vsparticle | Used for non-Mobile version when equals 1. | ||||||||||||||||||||||
DOFAmount | float | inc_postpr_dof | |||||||||||||||||||||||
DOFDeadZone | float | inc_postpr_dof | |||||||||||||||||||||||
DOFVignette | float | inc_postpr_dof | edge of screen blur | ||||||||||||||||||||||
DOFFocusType | int | inc_postpr_dof | set to camera pitch by default | ||||||||||||||||||||||
DynamicContrastMidpoint | float | inc_postpr_dyn_c | |||||||||||||||||||||||
DynamicContrastIntensity | float | inc_postpr_dyn_c | |||||||||||||||||||||||
Gamma | float | inc_postpr_gam | |||||||||||||||||||||||
Vibrance | float | inc_postpr_vibr | |||||||||||||||||||||||
globalColor | vec4 | fs vsfbdof vsfblvls vsfbshrp vsfbvib | The default color when one is otherwise not supplied | ||||||||||||||||||||||
PLTScheme[15] | float | fs_pltgen | The PLT color scheme info PLT based diffuse is a composite of a grayscale value from the PLT red channel and a color by number value from the green channel of the PLT, which is passed via texUnit0. The actual color picked is the XY vector equal to RG color vector, and is picked from the gradient map provided in texUnit1. First step is converting the texUnit0 green value through the PLT scheme info, thereby converting it to the proper Y coordinate (gradient row) in texUnit1. | ||||||||||||||||||||||
AOIntensity | float | fsfbssao |