- Home /
Question by
Pixeldamage · Jul 31, 2013 at 09:29 AM ·
shaderlightmappinguvdecal
BumpedSpecProbed + decal UV2
Is there a BumpedSpecProbed that combines the diffuse (UV1) with a decal (UV2)? Can anyone help with this please?
I gave it a go using (http://forum.unity3d.com/threads/116497-Light-Probes-Questions-Feedback/page5) but couldn't get the UV2 channel data into/out of the vertex shader properly withouth taking out the #pragma vertex:vert - which then destroys the specular info.
Please note i'm a 3D artist not a shader writer (though i'm trying) so appologies for glaring errors.
Shader "BumpSpecProbedDecalUV2"
{
Properties
{
// shaderlab nodes
_diffuse("_diffuse", 2D) = "black" {}
_decal("_decal", 2D) = "black" {}
_BumpMap("Normalmap", 2D) = "bump" {}
_Shininess("Shininess", Range(0.03,1) ) = 0.1
_SpecularColor("Specular Color", Color) = (0.4552239,0.4552239,0.4552239,1)
_ProbeShininess("Probe Spec Pow", Range(1,20) ) = 2
_ProbeSpecStr("Probe Spec Multiply", Range(0,2) ) = 0.5
_ProbeSpecSub("Probe Spec Subtrator", Range(0,4) ) = 2
}
SubShader
{
Tags
{
"Queue"="Geometry"
"IgnoreProjector"="False"
"RenderType"="Opaque"
"LightMode"="ForwardBase"
}
Cull Back
ZWrite On
ZTest LEqual
ColorMask RGBA
Fog{
}
CGPROGRAM
#include "UnityCG.cginc"
#include "HLSLSupport.cginc"
//removed #pragma vertex:vert novertexlights
#pragma surface surf BlinnPhongEditor
#pragma debug
#pragma target 3.0
// Definitions
sampler2D _diffuse;
sampler2D _decal;
sampler2D _BumpMap;
float4 _SpecularColor;
float _Shininess;
float _ProbeShininess;
float _ProbeSpecStr;
float _ProbeSpecSub;
struct EditorSurfaceOutput
{
half3 Albedo;
half3 Normal;
half3 Emission;
half3 Gloss;
half Specular;
half Alpha;
half4 Custom;
};
inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
{
half3 spec = light.a * s.Gloss;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha;
return c;
}
inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot ( lightDir, s.Normal ));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular*128.0);
half4 res;
res.rgb = _LightColor0.rgb * diff;
res.w = spec * Luminance (_LightColor0.rgb);
res *= atten * 2.0;
return LightingBlinnPhongEditor_PrePass( s, res );
}
struct Input {
float3 viewDir;
float2 uv_diffuse;
float4 meshUV;
float2 uv_BumpMap;
float3 worldNormal;
float3 worldRefl;
INTERNAL_DATA
};
void vert (inout appdata_full v, out Input o)
{
//UNITY_INITIALIZE_OUTPUT(Input, o);
//o.meshUV.xy = v.texcoord.xy;
//o.meshUV.zw = v.texcoord1.xy;
}
void surf (Input IN, inout EditorSurfaceOutput o) {
o.Normal = float3(0.0,0.0,1.0);
o.Alpha = 1.0;
o.Albedo = 0.0;
o.Emission = 0.0;
o.Gloss = 0.0;
o.Specular = 0.0;
o.Custom = 0.0;
//IN.meshUV.xy = tex1XY;
//IN.meshUV.zw = tex2XY;
// this is the diffuse UV passed into the vertex shader in register 0
//float4 Tex2D0=tex2D(_diffuse,(IN.uv_diffuse.xyxy).xy);
float4 Tex2D1=tex2D(_diffuse,(IN.uv_diffuse.xyxy).xy);
float4 Tex2D2=tex2D(_decal,(IN.meshUV.zwzw).xy);
float4 Add0=Tex2D1 + Tex2D2.aaaa;
float4 Multiply1=Add0 * Tex2D2;
//float4 Invert0= float4(1.0, 1.0, 1.0, 1.0) - Tex2D2.aaaa;
//float4 Multiply0=_numberC * Tex2D2.aaaa;
//float4 Add0=Multiply2 + Multiply0;
float4 Tex2DNormal0=float4(UnpackNormal( tex2D(_BumpMap,(IN.uv_BumpMap.xyxy).xy)).xyz, 1.0 );
float4 Multiply2=Tex2D1.aaaa * _SpecularColor;
o.Albedo = Multiply1;
o.Normal = Tex2DNormal0;
o.Specular = _Shininess.xxxx;
o.Gloss = Multiply2;
o.Alpha = Tex2D1.aaaa;
o.Normal = normalize(o.Normal);
float4 Fresnel0=(1.0 - dot( normalize( float4( IN.viewDir.x, IN.viewDir.y,IN.viewDir.z,1.0 ).xyz), normalize( Tex2DNormal0.xyz ) )).xxxx;
fixed3 worldN = WorldNormalVector(IN, o.Normal);
fixed3 worldR = normalize(WorldReflectionVector(IN, o.Normal));
float3 fProbeSpecCol = ShadeSH9(float4(worldR,1.0));
float fProbeSpecMask = pow(max(_ProbeSpecStr*(length(fProbeSpecCol)-_ProbeSpecSub-Fresnel0*2),0),_ProbeShininess+Fresnel0);
o.Emission = o.Albedo*ShadeSH9(float4(worldN,1.0)) + o.Gloss*fProbeSpecCol*fProbeSpecMask;
}
ENDCG
}
Fallback "Diffuse"
}
Comment