Pour un besoin spécifique, je cherche à créer un shader assez simple, qui allie couleur diffuse, texture diffuse, lightmapping et réflexion cubemap.
J'y suis presque, il ne me manque 'que' le 2e set d'UV pour appliquer correctement ma lightmap.
Code : Tout sélectionner
// Unlit lightmapped reflective shader
// Diffuse texture (UV1)* Lightmap texture (UV2) + Reflection * ReflectionColor
Shader "MyCustomShaders/LightMap/Reflective" {
Properties {
_DiffuseColor ("Diffuse Color", Color) = (1, 1, 1, 1)
_MainTex ("Base (RGB)", 2D) = "white" {}
_LightMapTex ("Lightmap (RGB)", 2D) = "white" {}
_Cube ("Reflection Cubemap", CUBE) = "_Skybox" {}
_ReflectColor ("Reflection Color", Color) = (0.25, 0.25, 0.25, 1)
}
SubShader {
Lighting Off //Pas de gestion de lumière
Tags { "RenderType"="Opaque" }
LOD 100
CGPROGRAM
#pragma surface surf NoLighting
fixed4 LightingNoLighting (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed4 c;
c.rgb = s.Albedo;
c.a = s.Alpha;
return c;
}
sampler2D _MainTex;
sampler2D _LightMapTex;
samplerCUBE _Cube;
fixed4 _ReflectColor;
fixed4 _DiffuseColor;
struct Input {
half2 uv_MainTex : TEXCOORD0;
half2 uv_LightMapTex : TEXCOORD1; //C'est ça marrez vous! ;)
half3 worldRefl;
half3 viewDir;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 tex = tex2D(_MainTex, IN.uv_MainTex);
fixed4 lm = tex2D(_LightMapTex, IN.uv_LightMapTex);
fixed3 reflcol = texCUBE (_Cube, IN.worldRefl);
fixed rim = 1.1 - dot (IN.viewDir, o.Normal); //faux fresnel
o.Albedo = _DiffuseColor.rgb * tex.rgb * lm.rgb; //Diffuse * couleur Diffuse * lightmap
o.Emission = reflcol.rgb * rim * _ReflectColor.rgb; //couleur réflexion * réflexion * faux fresnel
}
ENDCG
}
}
Merci.