Unity5 's unityshadervariables.cginc is 1kb bigger than Unity4.
Here is the unity shader most of the internal parameters, write this convenient to query their own
uniform float4 _time;
Time, x = t/20,y = T,z = T*2,w = t*3
uniform float4 _sintime;
Sin (time), x = sin (t/8), y = sin (t/4), z = sin (t/2), w = sin (t)
uniform float4 _costime;
Cos (time), x = cos (T/8), y = cos (T/4), z = cos (T/2), w = cos (t)
uniform float4 unity_deltatime;
Per frame time, x = dt,y = 1/dt,z = Smoothdt,w = 1/SMOOTHDT
uniform float3 _worldspacecamerapos;
World Space Camera coordinates
uniform float4 _projectionparams;
x = 1, if the projection is flipped x = 1
Y is the camera near clipping plane
Z is camera far clipping plane
W is 1/far clipping plane
uniform float4 _screenparams;
Screen parameters: x = screen width, y = screen height, z = 1 + 1.0/Screen width, w = 1 + 1.0/height screen height (number of pixels)
uniform float4 _zbufferparams;
For linearization of Z-buffer
x = 1-far/near
y = far/near
z = X/far
W = Y/far
Reference to the Http://www.humus.name/temp/Linearize%20depth.txt
about Z Buffer
Currently in D3D "depth" textures is single channel floating point texture, and we output linear 0..1 depth over far plan E range when rendering into it.
In OpenGL, the "depth" texture are much like a depth buffer and i.e. it has non-linear range. Usually depth buffer range in OpenGL is-1...1 range, so in humus ' text, OpenGL math would has to be used. However, OpenGL depth textures seem to actually has 0..1 range, i.e. just like depth buffer in D3D. It's not a explicitly written in the specification, but I found that off by trial and error. So since it matches D3D ' s depth buffer range, the D3D math have to be used.
The blogger also checked the third edition of Computer graphics 9-14 said:
In opengl,depth values is normalized in range from 0 to 1.0, so then the preceding initialization sets all Depth-buffer Values to the maximum value 1.0 by default.
Projection coordinates in OpenGL is normalized in range from-1.0 to 1.0,and the depth values between the near and far CL Ipping planes is further normalized to the range from 0 to 1.0.The value 0.0 corresponds to the near clipping plane (the Projection plane), and the value 1.0 corresponds to the far clipping plane.
uniform float4 unity_orthoparams;
Orthogonal camera parameters
x, the width of the orthogonal camera, the height of the Y-orthogonal camera, z is not used, W is 1.0 when the camera is orthographic, and 0.0 if it is a perspective projection.
Uniform float4 unity_cameraworldclipplanes;
Camera World clipping plane
Uniform float4x4 unity_cameraprojection;
Projection matrices of the camera. Note that this might is different from projection matrix
That's set right now, e.g and rendering shadows the matric8es below is still the projection
of original camera.
Camera's projection matrix, where the projection matrix has a number of
Uniform float4x4 unity_camerainvprojection;
Inverse matrix of the projection matrix of the camera
If it is directional light then the direction of
is the Half4 type,
If it is a point light then the location of the spot is
, which is the FLOAT4 type,
Because directional light is the direction does not need to be particularly accurate, as long as the half is enough, and the location of the point source because of the need for accurate calculation, it is necessary to be very accurate, so for the float type, this shows Unity technician optimization and meticulous.
uniform float4 _lightpositionrange;
XYZ is position position,w to 1/range
X, y, z coordinates of position of four light sources in world space
Attenuation of four light sources
Point light color, previous postUnity5 optimization of internal rendering 3: Removing the fixed functionmentioned, Unity5 can use 8 point light source.
The point light position of view space with a value of (position,1).
If directional light then its value is direction (-direction,0)
x = cos (SPOTANGLE/2) or-1 for Non-spot
y = 1/cos (SPOTANGLE/4) or 1 for Non-spot
Z = quadratic attenuation two-square attenuation
W = Range*range
Attenuation of 8 light sources
The direction of the spot light in view space, if no spot light is the value (0,0,1,0)
Spherical harmonic Illumination Parameters
half3 unity_lightcolor0, Unity_lightcolor1, Unity_lightcolor2, Unity_lightcolor3;
The Old Unity parameter (before 5), gets the color of four light sources.
Position points go from world coordinates to shadow space, which is commonly used to calculate shadow coordinates shadow coordinate
#define _world2shadow Unity_world2shadow
#define _WORLD2SHADOW1 Unity_world2shadow
#define _WORLD2SHADOW2 Unity_world2shadow
#define _WORLD2SHADOW3 Unity_world2shadow
Camera Drawing Parameters
#define UNITY_MATRIX_MVP GLSTATE_MATRIX_MVP
Model object Space->view visual space->projection projection space transformation matrix
#define UNITY_MATRIX_MV Glstate_matrix_modelview0
Spatial->view transformation matrix of model object
#define UNITY_MATRIX_IT_MV glstate_matrix_invtrans_modelview0
The inverse matrix of the spatial->view visual space matrix of model object
uniform float4x4 _object2world;
Object space to World space
uniform float4x4 _world2object;
World space to object space
uniform float4 Unity_lodfade;
Lod in Unity5 can be selected fade mode, smoothing the LOD level. X is the fade value, within the [0,1] range. Y is x quantized to 16 levels, depending on the official documentation
From Unity 5, you can choose Fade Mode for each LOD level. The fading is used to "blend" and the neighboring lods to achieve a smooth transition effect. However Unity doesn ' t provide a default built-in technique to blend LOD geometries. You need to implement your own technique according to your game type and asset production pipeline. Unity calculates a "blend factor" from the object's screen size and passes it to your shader.
One of two ways to calculate blend factor blend factor
The blend factor
is accessed as the unity_lodfade.x uniform variable in your shader program. Either keyword Lod_fade_percentage Orlod_fade_crossfade would be chosen to objects rendered with LOD fading.
Unity5 is more than 4 fade mode, which is to let Lod series change more smoothly, related to the above parameters
About LOD Group in the Component->rendering->lod group, you need to establish several different details of the grid, distance adjustable, specific: http://blog.csdn.net/mfc11/article/ details/9146625
Bo Master tried, effect tension pile
#define UNITY_MATRIX_T_MV Glstate_matrix_transpose_modelview0
UNITY_MATRIX_T_MV macro Essence is OpenGL State (glstate_matrix_transpose_modelview0), the inverse matrix of the model object space->view apparent space transformation matrix
camera per frame parameters
#define UNITY_MATRIX_P Glstate_matrix_projection
UNITY_MATRIX_P macro Essence is OpenGL State (glstate_matrix_projection), model object space--Projection projection space transformation matrix
#define Unity_lightmodel_ambient (Glstate_lightmodel_ambient * 2)
Ambient light color, for glstate_lightmodel_ambient * 2
#define UNITY_MATRIX_V UNITY_MATRIXV
Spatial->view transformation matrix of model object
#define UNITY_MATRIX_VP UNITY_MATRIXVP
View view space-projection projection space transformation matrix
Explanations on the Unity wiki:
In Unity, a uniform ambient light was specified by choosing Windows > Lighting > Scene from the main menu, setting AMB Ient Source to color and specifying the Ambient color. In a Cg shader in Unity, this color was then available as unity_lightmodel_ambient, which is one of the pre-defined uniform s mentioned in sections "shading in the world Space". (If you choose Gradient instead of color then unity_lightmodel_ambient and Unity_ambientsky Specify the Sky Color, while T He Equator color and the Ground color is specified by Unity_ambientequator and Unity_ambientground.)
As shown in Unity's default environment light from Skybox, can be set to gradient gradient, divided into Sky sky; Equator Horizon; Ground, three color gradients, the above parameters get this color. Another kind of ambient light is fixed color, the old version of the untiy is a fixed color of the ambient light
Note: Only the fog of unity is valid, and the post prossing that you add is not valid.
uniform fixed4 unity_fogcolor;
Uniform FLOAT4 unity_fogparams;
Fog parameter, x = density/sqrt (ln (2)), valid for EXP2 mode (fog panel parameter adjustable mode)
y = density/ln (2), valid for exp mode
z = -1/(end-to-end), valid for linear mode
W = end/(end-to-end), valid for linear mode
Dual or directional lightmap (always used with unity_lightmap, so can share sampler)
Dynamic GI Lightmap
two parameters for reflection probes
Matrix class Parameters
#define UNITY_MATRIX_TEXTURE0 float4x4 (1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)
#define UNITY_MATRIX_TEXTURE1 float4x4 (1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)
#define UNITY_MATRIX_TEXTURE2 float4x4 (1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)
#define UNITY_MATRIX_TEXTURE3 float4x4 (1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1)
It's obsolete, but you can use it.
There used to be fixed function-like texture matrices, defined as Unity_matrix_texturen. These is gone now; and is just defined to identity.
Another blogger in the first half of next year will be internship,, and seek work + guidance. Thank you very much O (∩_∩) o
After that, we will write other internal cginc.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Spy on Unity5 rendering internal parsing unityshadervariables.cginc