浏览代码

Refactored the common code to not depend on specific global variable names.

/tag-1.1.4-preview
Felipe Lira 7 年前
当前提交
1f60ea4c
共有 12 个文件被更改,包括 58 次插入64 次删除
  1. 28
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceCommon.hlsl
  2. 16
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfacePBR.hlsl
  3. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassDepthOnly.hlsl
  4. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl
  5. 13
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLitSimple.hlsl
  6. 2
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMeta.hlsl
  7. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassShadow.hlsl
  8. 31
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Particles.hlsl
  9. 6
      ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/ParticlesPBR.hlsl
  10. 8
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesSimpleLighting.shader
  11. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesUnlit.shader
  12. 4
      ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader

28
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfaceCommon.hlsl


///////////////////////////////////////////////////////////////////////////////
// Material Property Helpers //
///////////////////////////////////////////////////////////////////////////////
float2 TransformMainTextureCoord(float2 uv)
{
return TRANSFORM_TEX(uv, _MainTex);
}
half Alpha(half albedoAlpha)
half Alpha(half albedoAlpha, half4 color, half cutoff)
half alpha = albedoAlpha * _Color.a;
half alpha = albedoAlpha * color.a;
half alpha = _Color.a;
half alpha = color.a;
clip(alpha - _Cutoff);
clip(alpha - cutoff);
half4 MainTexture(float2 uv)
half4 SampleAlbedoAlpha(float2 uv, TEXTURE2D_ARGS(albedoAlphaMap, sampler_albedoAlphaMap))
return SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv);
return SAMPLE_TEXTURE2D(albedoAlphaMap, sampler_albedoAlphaMap, uv);
half3 Normal(float2 uv)
half3 SampleNormal(float2 uv, float scale, TEXTURE2D_ARGS(bumpMap, sampler_bumpMap))
half4 n = SAMPLE_TEXTURE2D(bumpMap, sampler_bumpMap, uv);
return UnpackNormal(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uv));
return UnpackNormal(n);
return UnpackNormalScale(SAMPLE_TEXTURE2D(_BumpMap, sampler_BumpMap, uv), _BumpScale);
return UnpackNormalScale(n, scale);
#endif
#else
return half3(0.0h, 0.0h, 1.0h);

half3 Emission(float2 uv)
half3 SampleEmission(float2 uv, half3 emissionColor, TEXTURE2D_ARGS(emissionMap, sampler_emissionMap))
return SAMPLE_TEXTURE2D(_EmissionMap, sampler_EmissionMap, uv).rgb * _EmissionColor.rgb;
return SAMPLE_TEXTURE2D(emissionMap, sampler_emissionMap, uv).rgb * emissionColor.rgb;
#endif
}

16
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/InputSurfacePBR.hlsl


#define SAMPLE_METALLICSPECULAR(uv) SAMPLE_TEXTURE2D(_MetallicGlossMap, sampler_MetallicGlossMap, uv)
#endif
half4 MetallicSpecGloss(float2 uv, half albedoAlpha)
half4 SampleMetallicSpecGloss(float2 uv, half albedoAlpha)
{
half4 specGloss;

return specGloss;
}
half Occlusion(float2 uv)
half SampleOcclusion(float2 uv)
{
#ifdef _OCCLUSIONMAP
#if (SHADER_TARGET < 30)

inline void InitializeStandardLitSurfaceData(float2 uv, out SurfaceData outSurfaceData)
{
half4 albedoAlpha = MainTexture(uv);
half4 albedoAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_PARAM(_MainTex, sampler_MainTex));
outSurfaceData.alpha = Alpha(albedoAlpha.a, _Color, _Cutoff);
half4 specGloss = MetallicSpecGloss(uv, albedoAlpha.a);
half4 specGloss = SampleMetallicSpecGloss(uv, albedoAlpha.a);
outSurfaceData.albedo = albedoAlpha.rgb * _Color.rgb;
#if _SPECULAR_SETUP

#endif
outSurfaceData.smoothness = specGloss.a;
outSurfaceData.normalTS = Normal(uv);
outSurfaceData.occlusion = Occlusion(uv);
outSurfaceData.emission = Emission(uv);
outSurfaceData.alpha = Alpha(albedoAlpha.a);
outSurfaceData.normalTS = SampleNormal(uv, _BumpScale, TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap));
outSurfaceData.occlusion = SampleOcclusion(uv);
outSurfaceData.emission = SampleEmission(uv, _EmissionColor, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap));
}
#endif // LIGHTWEIGHT_INPUT_SURFACE_PBR_INCLUDED

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassDepthOnly.hlsl


VertexOutput o = (VertexOutput)0;
UNITY_SETUP_INSTANCE_ID(v);
o.uv = TransformMainTextureCoord(v.texcoord);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.clipPos = TransformObjectToHClip(v.position.xyz);
return o;
}

Alpha(MainTexture(IN.uv).a);
Alpha(SampleAlbedoAlpha(IN.uv, TEXTURE2D_PARAM(_MainTex, sampler_MainTex)).a, _Color, _Cutoff);
return 0;
}
#endif

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLit.hlsl


UNITY_TRANSFER_INSTANCE_ID(v, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.uv = TransformMainTextureCoord(v.texcoord);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
float3 posWS = TransformObjectToWorld(v.vertex.xyz);
o.clipPos = TransformWorldToHClip(posWS);

13
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassLitSimple.hlsl


UNITY_TRANSFER_INSTANCE_ID(v, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.uv = TransformMainTextureCoord(v.texcoord);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.posWSShininess.xyz = TransformObjectToWorld(v.vertex.xyz);
o.posWSShininess.w = _Shininess * 128.0;

UNITY_SETUP_INSTANCE_ID(IN);
float2 uv = IN.uv;
half4 diffuseAlpha = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv);
half4 diffuseAlpha = SampleAlbedoAlpha(uv, TEXTURE2D_PARAM(_MainTex, sampler_MainTex));
half3 diffuse = diffuseAlpha.rgb * _Color.rgb;
half alpha = diffuseAlpha.a * _Color.a;

#endif
#ifdef _NORMALMAP
half3 normalTS = Normal(uv);
#else
half3 normalTS = half3(0, 0, 1);
#endif
half3 emission = Emission(uv);
half3 normalTS = SampleNormal(uv, 1.0, TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap));
half3 emission = SampleEmission(uv, _EmissionColor, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap));
half4 specularGloss = SpecularGloss(uv, diffuseAlpha.a);
half shininess = IN.posWSShininess.w;

2
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassMeta.hlsl


{
MetaVertexOuput o;
o.pos = MetaVertexPosition(v.vertex, v.uv1.xy, v.uv2.xy, unity_LightmapST);
o.uv = TransformMainTextureCoord(v.uv0);
o.uv = TRANSFORM_TEX(v.uv0, _MainTex);
return o;
}

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/LightweightPassShadow.hlsl


VertexOutput o;
UNITY_SETUP_INSTANCE_ID(v);
o.uv = TransformMainTextureCoord(v.texcoord);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.clipPos = GetShadowPositionHClip(v);
return o;
}

Alpha(MainTexture(IN.uv).a);
Alpha(SampleAlbedoAlpha(IN.uv, TEXTURE2D_PARAM(_MainTex, sampler_MainTex)).a, _Color, _Cutoff);
return 0;
}

31
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/Particles.hlsl


#include "Core.hlsl"
#include "CoreRP/ShaderLibrary/Color.hlsl"
#include "InputSurfaceCommon.hlsl"
CBUFFER_START(UnityPerMaterial)
float4 _SoftParticleFadeParams;

half4 _EmissionColor;
half4 _SpecColor;
#if defined (_COLORADDSUBDIFF_ON)
half4 _ColorAddSubDiff;

half _Shininess;
half _Metallic;
half _Glossiness;
half _BumpScale;
#include "InputSurfaceCommon.hlsl"
TEXTURE2D(_CameraDepthTexture);
SAMPLER(sampler_CameraDepthTexture);
TEXTURE2D(_CameraDepthTexture); SAMPLER(sampler_CameraDepthTexture);
TEXTURE2D(_SpecGlossMap); SAMPLER(sampler_SpecGlossMap);
#define SOFT_PARTICLE_NEAR_FADE _SoftParticleFadeParams.x
#define SOFT_PARTICLE_INV_FADE_DISTANCE _SoftParticleFadeParams.y

return color;
}
half3 NormalTS(VertexOutputLit IN)
half3 SampleNormalTS(VertexOutputLit IN, float scale, TEXTURE2D_ARGS(bumpMap, sampler_bumpMap))
half4 n = readTexture(TEXTURE2D_PARAM(bumpMap, sampler_bumpMap), IN);
return UnpackNormal(readTexture(TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap), IN));
return UnpackNormal(n);
return UnpackNormalScale(readTexture(TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap), IN), _BumpScale);
return UnpackNormalScale(n, scale);
#endif
#else
return half3(0.0h, 0.0h, 1.0h);

half3 Emission(VertexOutputLit IN)
half3 SampleEmission(VertexOutputLit IN, half3 emissionColor, TEXTURE2D_ARGS(emissionMap, sampler_emissionMap))
return readTexture(TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap), IN).rgb * _EmissionColor.rgb;
return readTexture(TEXTURE2D_PARAM(emissionMap, sampler_emissionMap), IN).rgb * emissionColor.rgb;
half4 Albedo(VertexOutputLit IN)
half4 SampleAlbedo(VertexOutputLit IN, TEXTURE2D_ARGS(albedoMap, sampler_albedoMap))
half4 albedo = readTexture(TEXTURE2D_PARAM(_MainTex, sampler_MainTex), IN) * IN.color;
half4 albedo = readTexture(TEXTURE2D_PARAM(albedoMap, sampler_albedoMap), IN) * IN.color;
// No distortion Support
fragColorMode(IN);

return albedo;
}
half4 SpecularGloss(VertexOutputLit IN, half alpha)
half4 SampleSpecularGloss(VertexOutputLit IN, half alpha, half4 specColor, TEXTURE2D_ARGS(specGlossMap, sampler_specGlossMap))
specularGloss = readTexture(TEXTURE2D_PARAM(_SpecGlossMap, sampler_SpecGlossMap), IN);
specularGloss = readTexture(TEXTURE2D_PARAM(specGlossMap, sampler_specGlossMap), IN);
specularGloss = _SpecColor;
specularGloss = specColor;
#endif
#ifdef _GLOSSINESS_FROM_BASE_ALPHA

6
ScriptableRenderPipeline/LightweightPipeline/LWRP/ShaderLibrary/ParticlesPBR.hlsl


void InitializeSurfaceData(VertexOutputLit IN, out SurfaceData surfaceData)
{
half4 albedo = Albedo(IN);
half4 albedo = SampleAlbedo(IN, TEXTURE2D_PARAM(_MainTex, sampler_MainTex));
#if defined(_METALLICGLOSSMAP)
half2 metallicGloss = readTexture(TEXTURE2D_PARAM(_MetallicGlossMap, sampler_MetallicGlossMap), IN).ra * half2(1.0, _Glossiness);

half3 normalTS = NormalTS(IN);
half3 emission = Emission(IN);
half3 normalTS = SampleNormalTS(IN, _BumpScale, TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap));
half3 emission = SampleEmission(IN, _EmissionColor, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap));
surfaceData.albedo = albedo.rgb;
surfaceData.specular = half3(0.0h, 0.0h, 0.0h);

8
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesSimpleLighting.shader


half4 ParticlesLitFragment(VertexOutputLit IN) : SV_Target
{
half4 albedo = Albedo(IN);
half4 albedo = SampleAlbedo(IN, TEXTURE2D_PARAM(_MainTex, sampler_MainTex));
half3 normalTS = NormalTS(IN);
half3 emission = Emission(IN);
half4 specularGloss = SpecularGloss(IN, albedo.a);
half3 normalTS = SampleNormalTS(IN, 1.0, TEXTURE2D_PARAM(_BumpMap, sampler_BumpMap));
half3 emission = SampleEmission(IN, _EmissionColor, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap));
half4 specularGloss = SampleSpecularGloss(IN, albedo.a, _SpecColor, TEXTURE2D_PARAM(_SpecGlossMap, sampler_SpecGlossMap));
half shininess = IN.viewDirShininess.w;
InputData inputData;

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardParticlesUnlit.shader


half4 fragParticleUnlit(VertexOutputLit IN) : SV_Target
{
half4 albedo = Albedo(IN);
half4 albedo = SampleAlbedo(IN, TEXTURE2D_PARAM(_MainTex, sampler_MainTex));
half3 emission = Emission(IN);
half3 emission = SampleEmission(IN, _EmissionColor, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap));
half3 diffuse = AlphaModulate(albedo.rgb, alpha);
half3 result = diffuse + emission;

4
ScriptableRenderPipeline/LightweightPipeline/LWRP/Shaders/LightweightStandardSimpleLighting.shader


{
float2 uv = i.uv;
MetaInput o;
o.Albedo = _Color.rgb * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv).rgb;
o.Albedo = _Color.rgb * SampleAlbedoAlpha(uv, TEXTURE2D_PARAM(_MainTex, sampler_MainTex)).rgb;
o.Emission = Emission(uv);
o.Emission = SampleEmission(uv, _EmissionColor, TEXTURE2D_PARAM(_EmissionMap, sampler_EmissionMap));
return MetaFragment(o);
}

正在加载...
取消
保存