浏览代码

Added surface definition for FastBlinn

/main
Matt Dean 7 年前
当前提交
ef853b6a
共有 4 个文件被更改,包括 110 次插入39 次删除
  1. 41
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader
  2. 69
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc
  3. 33
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc
  4. 6
      MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardShader.shader

41
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipeline.shader


#pragma vertex LightweightVertex
#pragma fragment LightweightFragmentFastBlinn
void DefineSurface(LightweightVertexOutput i, inout SurfaceFastBlinn s)
{
// Albedo
float4 c = tex2D(_MainTex, i.uv01.xy);
s.Diffuse = LIGHTWEIGHT_GAMMA_TO_LINEAR(c.rgb) * _Color.rgb;
// Specular
#ifdef _SPECGLOSSMAP
half4 specularMap = tex2D(_SpecGlossMap, i.uv01.xy);
#if defined(UNITY_COLORSPACE_GAMMA) && defined(LIGHTWEIGHT_LINEAR)
s.Specular = LIGHTWEIGHT_GAMMA_TO_LINEAR(specularGloss.rgb);
#endif
#elif defined(_SPECGLOSSMAP_BASE_ALPHA)
s.Specular.rgb = LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_SpecGlossMap, i.uv01.xy).rgb) * _SpecColor.rgb;
s.Glossiness = s.Alpha;
#else
s.Specular = _SpecColor.rgb;
s.Glossiness = _SpecColor.a;
#endif
// Normal
#if _NORMALMAP
s.Normal = UnpackNormal(tex2D(_BumpMap, i.uv01.xy));
#endif
// Emission
s.Emission = CalculateEmission(i.uv01.xy);
// Alpha
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
s.Alpha = _Color.a;
#else
s.Alpha = c.a * _Color.a;
#endif
#ifdef _ALPHATEST_ON
clip(s.Alpha - _Cutoff);
#endif
}
ENDCG
}

69
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineCore.cginc


#endif
}
half3 MetallicSetup(float2 uv, Surface s, /*half3 albedo, half albedoAlpha, */out half3 specular, out half smoothness, out half oneMinusReflectivity)
half3 MetallicSetup(float2 uv, SurfacePBR s, /*half3 albedo, half albedoAlpha, */out half3 specular, out half smoothness, out half oneMinusReflectivity)
{
//half2 metallicGloss = MetallicSpecGloss(uv, albedoAlpha).ra;
//half metallic = metallicGloss.r;

return s.Albedo * oneMinusReflectivity;
}
half3 SpecularSetup(float2 uv, Surface s, /*half3 albedo, half albedoAlpha, */out half3 specular, out half smoothness, out half oneMinusReflectivity)
half3 SpecularSetup(float2 uv, SurfacePBR s, /*half3 albedo, half albedoAlpha, */out half3 specular, out half smoothness, out half oneMinusReflectivity)
{
half4 specGloss = float4(s.Specular, s.Smoothness);// MetallicSpecGloss(uv, albedoAlpha);

return o;
}
Surface InitializeSurface()
SurfacePBR InitializeSurfacePBR()
Surface s;
s.Albedo = float3(1, 1, 1);
SurfacePBR s;
s.Albedo = float3(0.5, 0.5, 0.5);
s.Specular = float3(0, 0, 0);
s.Metallic = 0;
s.Normal = float3(.5, .5, 1);

s.Alpha = 1;
return s;
}
}
SurfaceFastBlinn InitializeSurfaceFastBlinn()
{
SurfaceFastBlinn s;
s.Diffuse = float3(0.5, 0.5, 0.5);
s.Specular = float3(0, 0, 0);
s.Normal = float3(.5, .5, 1);
s.Emission = 0;
s.Glossiness = 0;
s.Alpha = 1;
return s;
}
void DefineSurface(LightweightVertexOutput i, inout Surface s);
void DefineSurface(LightweightVertexOutput i, inout SurfacePBR s);
void DefineSurface(LightweightVertexOutput i, inout SurfaceFastBlinn s);
Surface s = InitializeSurface();
SurfacePBR s = InitializeSurfacePBR();
DefineSurface(i, s);
float2 uv = i.uv01.xy;

half4 LightweightFragmentFastBlinn(LightweightVertexOutput i) : SV_Target
{
half4 diffuseAlpha = tex2D(_MainTex, i.uv01.xy);
half3 diffuse = LIGHTWEIGHT_GAMMA_TO_LINEAR(diffuseAlpha.rgb) * _Color.rgb;
half alpha = diffuseAlpha.a * _Color.a;
SurfaceFastBlinn s = InitializeSurfaceFastBlinn();
DefineSurface(i, s);
clip(alpha - _Cutoff);
clip(s.Alpha - _Cutoff);
half3 normalMap = UnpackNormal(tex2D(_BumpMap, i.uv01.xy));
CalculateNormal(normalMap, i, normal);
half4 specularGloss;
SpecularGloss(i.uv01.xy, alpha, specularGloss);
CalculateNormal(s.Normal, i, normal);
half3 viewDir = i.viewDir.xyz;
float3 worldPos = i.posWS.xyz;

half4 specularGloss = half4(s.Specular, s.Glossiness);
#ifndef _MULTIPLE_LIGHTS
LightInput lightInput;
INITIALIZE_MAIN_LIGHT(lightInput);

#endif
half3 color = LightingBlinnPhong(diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightInput.color;
half3 color = LightingBlinnPhong(s.Diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightInput.color;
half3 color = LightingLambert(diffuse, lightDirection, normal, lightAtten) * lightInput.color;
half3 color = LightingLambert(s.Diffuse, lightDirection, normal, lightAtten) * lightInput.color;
#endif
#else

#endif
#ifdef LIGHTWEIGHT_SPECULAR_HIGHLIGHTS
color += LightingBlinnPhong(diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightData.color;
color += LightingBlinnPhong(s.Diffuse, specularGloss, lightDirection, normal, viewDir, lightAtten) * lightData.color;
color += LightingLambert(diffuse, lightDirection, normal, lightAtten) * lightData.color;
color += LightingLambert(s.Diffuse, lightDirection, normal, lightAtten) * lightData.color;
#ifdef _EMISSION
color += LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, i.uv01.xy).rgb) * _EmissionColor;
#else
color += _EmissionColor;
#endif
color += CalculateEmissionFastBlinn(i.uv01.xy);
color += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) + i.fogCoord.yzw) * diffuse;
color += (DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.uv01.zw)) + i.fogCoord.yzw) * s.Diffuse;
color += i.fogCoord.yzw * diffuse;
color += i.fogCoord.yzw * s.Diffuse;
color += texCUBE(_Cube, reflectVec).rgb * specularGloss.rgb;
color += texCUBE(_Cube, reflectVec).rgb * s.Specular;
color += reflectionProbe.rgb * (reflectionProbe.a * unity_SpecCube0_HDR.x) * specularGloss.rgb;
color += reflectionProbe.rgb * (reflectionProbe.a * unity_SpecCube0_HDR.x) * s.Specular;
return OutputColor(color, alpha);
return OutputColor(color, s.Alpha);
};
#endif

33
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightPipelineInput.cginc


UNITY_VERTEX_OUTPUT_STEREO
};
//TODO - Shouldnt be here
struct Surface
struct SurfacePBR
{
float3 Albedo; // diffuse color
float3 Specular; // specular color

float Alpha; // alpha for transparencies
};
inline void CalculateNormal(float3 normalMap, LightweightVertexOutput i, out half3 normal)
struct SurfaceFastBlinn
{
float3 Diffuse; // diffuse color
float3 Specular; // specular color
float3 Normal; // tangent space normal, if written
half3 Emission;
half Glossiness; // 0=rough, 1=smooth
float Alpha; // alpha for transparencies
};
inline void CalculateNormal(half3 normalMap, LightweightVertexOutput i, out half3 normal)
#endif
}
inline half3 CalculateEmission(half2 uv)
{
#ifndef _EMISSION
return 0;
#else
return LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, uv).rgb) * _EmissionColor.rgb;
#endif
}
inline half3 CalculateEmissionFastBlinn(half2 uv)
{
#ifndef _EMISSION
return _EmissionColor.rgb;
#else
return LIGHTWEIGHT_GAMMA_TO_LINEAR(tex2D(_EmissionMap, uv).rgb) * _EmissionColor.rgb;
#endif
}

6
MaterialGraphProject/Assets/SRP/ScriptableRenderPipeline/LightweightPipeline/Shaders/LightweightStandardShader.shader


#pragma vertex LightweightVertex
#pragma fragment LightweightFragmentPBR
void DefineSurface(LightweightVertexOutput i, inout Surface s)
void DefineSurface(LightweightVertexOutput i, inout SurfacePBR s)
{
// Albedo
float4 c = tex2D(_MainTex, i.uv01.xy);

s.Occlusion = Occlusion(i.uv01.xy);
// Emission
#ifdef _EMISSION
s.Emission = Emission(i.uv01.xy);
#endif
s.Emission = CalculateEmission(i.uv01.xy);
// Alpha
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A

正在加载...
取消
保存