4. Standard Shader
Avant
Un Shader différent par « type » de rendu
Par exemple :
Main texture Diffuse
Main texture + Normal map Bumped Diffuse
Main texture + Normal map + Height map Parallax Diffuse
7. Les Bases
Un shader est un programme exécuté par la carte graphique pour paramétrer une
partie du processus de rendu.
Un shader est un mini programme
sampler2D _MainTex;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * _Color;
}
8. sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
void surf (Input IN, inout SurfaceOutput o)
{
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * _Color;
}
Les Bases
Son temps d’exécution dépend de sa complexité.
Un shader est un mini programme
9. Les Bases
Il est donc conseillé de bien choisir le shader utilisé pour ne pas exécuter des
instructions inutiles.
Un shader est un mini programme
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _ParallaxMap;
fixed4 _Color;
float _Parallax;
void surf (Input IN, inout SurfaceOutput o)
{
half h = tex2D (_ParallaxMap, IN.uv_BumpMap).w;
float2 offset = ParallaxOffset (h, _Parallax, IN.viewDir);
IN.uv_MainTex += offset;
IN.uv_BumpMap += offset;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * _Color;
}
10. Les bases
Un shader est un mini programme
sampler2D _MainTex;
sampler2D _BumpMap;
sampler2D _ParallaxMap;
fixed4 _Color;
float _Parallax;
void surf (Input IN, inout SurfaceOutput o)
{
half h = tex2D (_ParallaxMap, IN.uv_BumpMap).w;
float2 offset = ParallaxOffset (h, _Parallax, IN.viewDir);
IN.uv_MainTex += offset;
IN.uv_BumpMap += offset;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb * _Color;
}
Diffuse
Bump diffuse
Parallax diffuse
14. Comment ca marche alors ?
CustomEditor
public class MyStandardShaderGUI : ShaderGUI
{
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
{
Material targetMat = materialEditor.target as Material;
base.OnGUI(materialEditor, properties);
if (targetMat.GetTexture("_BumpMap"))
targetMat.EnableKeyword("_BUMP");
else
targetMat.DisableKeyword("_BUMP");
}
}
15. Comment ca marche alors ?
Et voila
_NO_BUMP _NO_PARALLAX _BUMP _NO_PARALLAX _BUMP _PARALLAX