Shader model 3.0 needs completely self-written lighting / fog / ambient - calculations, when not using any fixed functions. Is there a basic SM3.0 shader that gets you kick-started??
Thats actually untrue
SM3 can use the SM2 calculations (ie all that are already present, used and required for per pixel lights and shadows, commonly visible through the PPL in the name. The available shaders on that end are part of the builtin shader resource download on the website)
Yes, but calculations like ambient and fog are often done fixed function and I can’t find the equivalents.
When I only use the following lighting calculations inside the pixel shader the fog isn’t taken into account and the material is darker as it should be.
half4 texcol = tex2D(_MainTex, i.uv) * _PPLAmbient * 2.0;
return DiffuseLight( i.lightDir, normal, texcol, LIGHT_ATTENUATION(i) );
That heavily depends on what we talk about.
For ambient you are wrong for example (PPLAmbient)
Thats because you use neither the fog data nor the any ambient calculation at all, not because these data are not there. Please check out the reference manual on all the built in shaders and naturally the builtin shader package on the website. They will definitely help you
Same goes for the shaderlab and cg documentations that come with Unity
Ok thanks, you’re of course right. I’ll take another look
This here is a sketch of the method I use for calculating exp2 fog in my SM 3.0 shaders. I hope it can get you kick started…
uniform float4 _FogColor;
uniform float _FogDensity;
float4 manualFogEXP2Fragment (v2f i) : COLOR {
half4 whateverColorCalculated = blahblah;
float whatEverDistanceFromView = someOtherBlahBlah;
float eFactor = 2.7183;
float fog = 1/(pow(eFactor,(pow(_FogDensity * whatEverDistanceFromView,2))));
half4 c = lerp(whateverColorCalculated, _FogColor,1-fog);
// Another method than lerp(): half4 c = (1-fog) * _FogColor + fog * whateverColorCalculated ;
return c;
}
Thanks, have already found the calculations.
half4 c = lerp(whateverColorCalculated, _FogColor, 1-fog);
can be changed to
half4 c = lerp(_FogColor, whateverColorCalculated,fog);
Saves the 1-fog calculation.