Shaderlab Syntax: color, material, Lighting
Shaderlab Syntax: color, material, light
The material and lighting parameters are used to control the built-in vertex lighting. vertex lighting is the standard direct3d/OpenGL lighting model that is computed for each vertex. lighting on turns
It On. lighting is affected by material block, colormaterial and separatespecular commands.
The material and lighting parameters are used to control the built-in vertex illumination. Vertex illumination is the standard illumination model of direct3d/OpenGL, which computes each vertex. Open the lighting on command. Illumination is affected by the material block, colormaterial, and separatespecular commands.
Per-pixel lights are usually implemented with custom vertex/fragment programs and don't use vertex lighting. for these you don't use any of the commands described here, instead you define your own Vertex
And fragment programs where you do all lighting, texturing and anything else yourself.
Pixel-by-pixel illumination is usually used to implement custom vertex/fragment programs, which do not use vertex illumination. Any commands described in this article will not be used to operate pixel-by-pixel illumination. You can implement this effect by programming your own vertex and fragment.
Vertex coloring & Lighting is the first effect to gets calculated for any rendered geometry. It operates on the vertex level, and calculates the base color that is used before textures are applied.
When rendering any geometric image, the vertex color and illumination are 1st calculated results. Before applying a texture, it first operates the vertex level and then calculates the base color.
Syntax
The top level commands control whether to use fixed function lighting or not, and some configuration options. The main setup is inMaterial Block, Detailed further below.
The top-level command controls whether fixed function lighting is used and some configuration options. Mainly inSet in material blockFor more information, see the following section.
ColorColor
-
Sets the object to a solid color. A color is either four rgba values in parenthesis, or a color property name in square brackets.
-
Set the solid color of the object. It can be an rgba color value (in brackets) or a color attribute name (in square brackets ).
-
-
Material {Material Block
} Material
-
The material block is used to define the material properties of the object.
-
A material block is used to define the material performance of an object.
-
-
LightingOn | off
-
For the settings defined in the material block to have any effect, you must enable lighting with the lighting on command. If lighting is off instead,
The color is taken straight from the color command.
-
To make the settings defined in the material block valid, you must enable the lighting on command to enable illumination. If the light is off, you can use the color command to obtain the color.
-
-
SeparatespecularOn | off
-
This command makes specular lighting be added to the end of the shader pass, so specular lighting is unaffected by texturing. only has effect whenlighting
On is used.
-
This command adds the mirror light to the end of the shader channel, so that the mirror light is not affected by the texture. This effect is only valid when the illumination is enabled.
-
-
ColormaterialAmbientanddiffuse | emission color material environment diffuse reflection light and radiation light
-
Makes per-vertex color be used instead of the colors set in the material. ambientanddiffuse replaces ambient and diffuse values of
Material; Emission replaces emission value of the material.
-
Use the color of each vertex to replace the color set in the material. Ambientanddiffuse replaces the value of the environment diffuse light. Emission replaces the radiation value.
-
Emission can be understood as self-emitting objects.
-
Material block material block
This contains settings for how the material reacts to the light. Any of these properties can be left out, in which case they default to Black (I. e. Have no effect ).
These are used to set how the material affects the illumination. Any of these attributes can be excluded. In this case, they are considered black by default (not effective ).
DiffuseColor diffuse color
-
The diffuse color component. This is an object's base color.
-
This is the most basic color of an object.
-
-
AmbientColor environment color
-
The ambient color component. This is the color the object has when it's hit by the ambient light set in the rendersettings.
-
Set the color of an object when it is affected by ambient light, depending on the Environmental color set in rendersettings.
-
-
SpecularColor reflected light
-
The color of the object's specular highlight.
-
Set the high-gloss color of an object.
-
-
ShininessNumber Definition
-
The sharpness of the highlight, between 0 and 1. At 0 you get a huge highlight that looks a lot like diffuse lighting, at 1 you get a tiny speck.
-
Highlight resolution. The value ranges from 0 to 1. When it is 0, you get a huge highlight that looks like a lot of diffuse light; when it is 1, you get a small spot.
-
-
EmissionColor self-luminous color
-
The color of the object when it is not hit by any light.
-
The self-luminous color of the object itself when it is not affected by other light.
The full color of lights hitting the object is:
The formula for calculating the color of an object when it is illuminated by all rays is as follows:
Ambient * RenderSettings ambient setting + (Light Color * Diffuse + Light Color * Specular) + Emission
The light parts of the equation (within parenthesis) is repeated for all lights that hit the object.
The part of the light in brackets is used to calculate all the light emitted to an object.
Typically you want to keep the diffuse and ambient colors the same (all builtin unity shaders do this ).
Generally, you need to keep the color of the diffuse reflection and environment the same (this applies to all built-in unity3d shader ).
Examples example:
Always render object in pure red:
Rendering objects in pure red
Shader "Solid Red" { SubShader { Pass { Color (1,0,0,0) } }}
Basic shader that colors the object white and applies vertex lighting:
The basic shader sets the material diffuse reflection and Environment Color of the object to white, and enables vertex illumination at the same time.
Shader "VertexLit White" { SubShader { Pass { Material { Diffuse (1,1,1,1) Ambient (1,1,1,1) } Lighting On } }}
An extended version that adds Material color as a property visible in material INSPECTOR:
Shder of an extended version. Set the main color of the material to an attribute that can be seen in the material searcher.
Shader "VertexLit Simple" { Properties { _Color ("Main Color", COLOR) = (1,1,1,1) } SubShader { Pass { Material { Diffuse [_Color] Ambient [_Color] } Lighting On } }}
And finally, a full fledged vertex-shortshader (see also settexture reference
Page ):
Finally, it is a complete and mature illumination vertex shader (referred to as settexture reference)
Shader "VertexLit" { Properties { _Color ("Main Color", Color) = (1,1,1,0) _SpecColor ("Spec Color", Color) = (1,1,1,1) _Emission ("Emmisive Color", Color) = (0,0,0,0) _Shininess ("Shininess", Range (0.01, 1)) = 0.7 _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Pass { Material { Diffuse [_Color] Ambient [_Color] Shininess [_Shininess] Specular [_SpecColor] Emission [_Emission] } Lighting On SeparateSpecular On SetTexture [_MainTex] { Combine texture * primary DOUBLE, texture * primary } } }}
Original at www.j2megame.com. For more information, see.