Hi everybody,
I have started with shader programming. Currently I am trying to re-do existing Unity shaders but done in cg so i can compare the results.
At the moment I am trying to implement Unitys Lightmapped/Bumped Specular shader in cg and the result (much darker) just wont look like Unitys result.
I have tried many different combinations but it ll never look like Unitys result.
I have found the equation of lightmapping here:
http://forum.unity3d.com/viewtopic.php?t=33372&highlight=lightmap
What am I doing wrong?
Heres what I do:
Shader "Customized Shaders/Lightmapped Bumped Specular Alpha" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (0.5, 0.5, 0.5, 0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.078125
_MainTex ("Base (RGB) TransGloss (A)", 2D) = "white" {}
_BumpMap ("Bumpmap", 2D) = "bump" {}
_LightMap ("Lightmap (RGB)", 2D) = "lightmap" {LightmapMode}
}
Category {
AlphaToMask True
ColorMask RGB
Fog { Color [_AddFog] }
Blend AppSrcAdd AppDstAdd
// ------------------------------------------------------------------
// ARB fragment program
SubShader {
UsePass "Transparent/Cutout/Specular/BASE"
// Pixel lights
Pass {
Name "PPL"
Tags { "LightMode" = "Pixel" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_builtin
#pragma fragmentoption ARB_fog_exp2
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
#include "AutoLight.cginc"
struct appdata {
float4 vertex : POSITION;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
};
struct v2f {
V2F_POS_FOG;
LIGHTING_COORDS
float3 uvK; // xy = UV, z = specular K
float2 uv2;
float2 uv3;
float3 viewDirT;
float3 lightDirT;
};
uniform float4 _MainTex_ST, _BumpMap_ST, _LightMap_ST;
uniform float _Shininess;
v2f vert (appdata v)
{
v2f o;
PositionFog( v.vertex, o.pos, o.fog );
o.uvK.xy = TRANSFORM_TEX(v.texcoord,_MainTex);
o.uvK.z = _Shininess * 128;
o.uv2 = TRANSFORM_TEX(v.texcoord,_BumpMap);
o.uv3 = TRANSFORM_TEX(v.texcoord1,_LightMap);
TANGENT_SPACE_ROTATION;
o.lightDirT = mul( rotation, ObjSpaceLightDir( v.vertex ) );
o.viewDirT = mul( rotation, ObjSpaceViewDir( v.vertex ) );
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
uniform sampler2D _BumpMap;
uniform sampler2D _MainTex;
uniform sampler2D _LightMap;
uniform float4 _Color;
float4 frag (v2f i) : COLOR
{
float4 lightcol = tex2D( _LightMap, i.uv3 );
float4 texcol = tex2D( _MainTex, i.uvK.xy );
texcol = texcol*lightcol + (texcol*_PPLAmbient*2*_Color);
// get normal from the normal map
float3 normal = tex2D(_BumpMap, i.uv2).xyz * 2 - 1;
half4 c = SpecularLight( i.lightDirT, i.viewDirT, normal, texcol, i.uvK.z, LIGHT_ATTENUATION(i) );
return c;
}
ENDCG
}
}
}
FallBack "Transparent/Cutout/VertexLit", 1
}
Any help is much appreciated!
Thanks