Shader não funciona no Unity URP
Página 1 de 1
Shader não funciona no Unity URP
Eu estou produzindo um jogo com a temática de MMD ou TDA para simplificar.
E estou usando um pacote chamado MMD4Mecanim para isso.
So que o unity URP é muito melhor para fazer coisas relacionadas a clima e ambientação do que o unity base.
O problema é que os Shader do pacote estão ficando rosas no URP.
Então se alguém souber como arrumar ou onde eu posso conseguir ajuda com isso seria de grande ajuda.
Vou deixar aqui embaixo os códigos do Shader e o link para o pacote caso queira ver com mais exatidão.
Link do pacote: https://stereoarts.jp/
Códigos dos Importadores de inclusão do Shader:
E estou usando um pacote chamado MMD4Mecanim para isso.
So que o unity URP é muito melhor para fazer coisas relacionadas a clima e ambientação do que o unity base.
O problema é que os Shader do pacote estão ficando rosas no URP.
Então se alguém souber como arrumar ou onde eu posso conseguir ajuda com isso seria de grande ajuda.
Vou deixar aqui embaixo os códigos do Shader e o link para o pacote caso queira ver com mais exatidão.
Link do pacote: https://stereoarts.jp/
Códigos dos Importadores de inclusão do Shader:
- Código:
// Not for redistribution without the author's express written permission
#include "HLSLSupport.cginc"
#include "UnityShaderVariables.cginc"
#define UNITY_PASS_SHADOWCOLLECTOR
#define SHADOW_COLLECTOR_PASS
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "MMD4Mecanim-MMDLit-Lighting.cginc"
#include "MMD4Mecanim-MMDLit-Surface-Lighting.cginc"
#define INTERNAL_DATA
#define WorldReflectionVector(data,normal) data.worldRefl
#define WorldNormalVector(data,normal) normal
//half4 _Color;
//sampler2D _MainTex;
struct v2f_surf {
V2F_SHADOW_COLLECTOR;
float2 pack0 : TEXCOORD5;
};
v2f_surf vert_surf (appdata_full v) {
v2f_surf o;
o.pack0.xy = v.texcoord;
TRANSFER_SHADOW_COLLECTOR(o)
return o;
}
fixed4 frag_surf (v2f_surf IN) : MMDLIT_SV_TARGET{
half4 albedo = (half4)tex2D(_MainTex, IN.pack0.xy);
albedo.a *= _Color.a; // for Transparency
MMDLIT_CLIP(albedo.a)
SHADOW_COLLECTOR_FRAGMENT(IN)
}
fixed4 frag_fast (v2f_surf IN) : MMDLIT_SV_TARGET{
MMDLIT_CLIP_FAST(1.0)
SHADOW_COLLECTOR_FRAGMENT(IN)
}
#ifdef TESSELLATION_ON
#ifdef UNITY_CAN_COMPILE_TESSELLATION
// tessellation domain shader
[UNITY_domain("tri")]
v2f_surf ds_surf(UnityTessellationFactors tessFactors, const OutputPatch<InternalTessInterp_appdata_full, 3> vi, float3 bary : SV_DomainLocation)
{
appdata_full v = _ds_appdata_full(tessFactors, vi, bary);
v2f_surf o = vert_surf(v);
return o;
}
#endif // UNITY_CAN_COMPILE_TESSELLATION
#endif // TESSELLATION_ON
- Código:
// Not for redistribution without the author's express written permission
#include "HLSLSupport.cginc"
#include "UnityShaderVariables.cginc"
#ifndef UNITY_PASS_FORWARDADD
#define UNITY_PASS_FORWARDADD
#endif
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "MMD4Mecanim-MMDLit-AutoLight.cginc"
#define INTERNAL_DATA
#define WorldReflectionVector(data,normal) data.worldRefl
#define WorldNormalVector(data,normal) normal
#include "MMD4Mecanim-MMDLit-Lighting.cginc"
#include "MMD4Mecanim-MMDLit-Surface-Lighting.cginc"
#include "MMD4Mecanim-MMDLit-Compatible.cginc"
struct v2f_surf
{
float4 pos : SV_POSITION;
float4 pack0 : TEXCOORD0;
half3 normal : TEXCOORD1;
half4 lightDir : TEXCOORD2;
half4 viewDir : TEXCOORD3;
LIGHTING_COORDS(4,5)
};
float4 _MainTex_ST;
v2f_surf vert_surf(appdata_full v)
{
v2f_surf o;
o.pos = _UnityObjectToClipPos(v.vertex);
o.pack0.xy = v.texcoord.xy;
o.normal = mul((float3x3)_UNITY_OBJECT_TO_WORLD, SCALED_NORMAL);
o.lightDir.xyz = WorldSpaceLightDir(v.vertex);
o.viewDir.xyz = WorldSpaceViewDir(v.vertex);
half NdotL = dot(o.normal, (half3)o.lightDir);
half toonRefl = MMDLit_GetToolRefl(NdotL);
o.pack0.z = toonRefl;
o.pack0.w = MMDLit_GetForwardAddStr(toonRefl);
o.lightDir.w = 0.0;
o.viewDir.w = MMDLit_GetToonShadow(toonRefl);
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
inline half3 frag_core(in v2f_surf IN, half4 albedo)
{
half atten = LIGHT_ATTENUATION(IN); // SHADOW_ATTENUATION() might be 1.0 (Can use LIGHT_ATTENUATION() only.)
#ifndef USING_DIRECTIONAL_LIGHT
half3 lightDir = normalize((half3)IN.lightDir);
#else
half3 lightDir = (half3)IN.lightDir;
#endif
half toonRefl = (half)IN.pack0.z;
half forwardAddStr = (half)IN.pack0.w;
half toonShadow = IN.viewDir.w;
half NdotL = IN.lightDir.w;
half3 c = MMDLit_Lighting_Add(
(half3)albedo,
NdotL,
toonRefl,
toonShadow,
IN.normal,
(half3)lightDir,
normalize((half3)IN.viewDir),
atten);
c *= forwardAddStr;
return c;
}
fixed4 frag_surf(v2f_surf IN) : MMDLIT_SV_TARGET
{
half4 albedo = MMDLit_GetAlbedo(IN.pack0.xy);
albedo.a *= _Color.a; // for Transparency
MMDLIT_CLIP(albedo.a)
half3 c = frag_core(IN, albedo);
c = min(c, 1.0);
c *= albedo.a;
return fixed4(c, 0.0);
}
fixed4 frag_fast(v2f_surf IN) : MMDLIT_SV_TARGET
{
half4 albedo = MMDLit_GetAlbedo(IN.pack0.xy);
MMDLIT_CLIP_FAST(albedo.a)
half3 c = frag_core(IN, albedo);
return fixed4(c, 0.0);
}
#ifdef TESSELLATION_ON
#ifdef UNITY_CAN_COMPILE_TESSELLATION
// tessellation domain shader
[UNITY_domain("tri")]
v2f_surf ds_surf(UnityTessellationFactors tessFactors, const OutputPatch<InternalTessInterp_appdata_full, 3> vi, float3 bary : SV_DomainLocation)
{
appdata_full v = _ds_appdata_full(tessFactors, vi, bary);
v2f_surf o = vert_surf(v);
return o;
}
#endif // UNITY_CAN_COMPILE_TESSELLATION
#endif // TESSELLATION_ON
- Código:
// Not for redistribution without the author's express written permission
// UNITY_SHADER_NO_UPGRADE
#include "AutoLight.cginc"
// ------------------------------
// Light helpers (5.0+ version)
// ------------------------------
#if UNITY_VERSION >= 540
#define _UNITY_WORLD_TO_LIGHT unity_WorldToLight
#else
#define _UNITY_WORLD_TO_LIGHT _LightMatrix0
#endif
#if UNITY_VERSION >= 500
#undef UNITY_LIGHT_ATTENUATION
#ifdef POINT
#define UNITY_LIGHT_ATTENUATION(destName, input, worldPos) \
unityShadowCoord3 lightCoord = mul(_UNITY_WORLD_TO_LIGHT, unityShadowCoord4(worldPos, 1)).xyz; \
fixed destName = (tex2D(_LightTexture0, dot(lightCoord, lightCoord).rr).UNITY_ATTEN_CHANNEL);
#endif
#ifdef SPOT
#define UNITY_LIGHT_ATTENUATION(destName, input, worldPos) \
unityShadowCoord4 lightCoord = mul(_UNITY_WORLD_TO_LIGHT, unityShadowCoord4(worldPos, 1)); \
fixed destName = (lightCoord.z > 0) * UnitySpotCookie(lightCoord) * UnitySpotAttenuate(lightCoord.xyz);
#endif
#ifdef DIRECTIONAL
#define UNITY_LIGHT_ATTENUATION(destName, input, worldPos) fixed destName = 1.0;
#endif
#ifdef POINT_COOKIE
#define UNITY_LIGHT_ATTENUATION(destName, input, worldPos) \
unityShadowCoord3 lightCoord = mul(_UNITY_WORLD_TO_LIGHT, unityShadowCoord4(worldPos, 1)).xyz; \
fixed destName = tex2D(_LightTextureB0, dot(lightCoord, lightCoord).rr).UNITY_ATTEN_CHANNEL * texCUBE(_LightTexture0, lightCoord).w;
#endif
#ifdef DIRECTIONAL_COOKIE
#define UNITY_LIGHT_ATTENUATION(destName, input, worldPos) \
unityShadowCoord2 lightCoord = mul(_UNITY_WORLD_TO_LIGHT, unityShadowCoord4(worldPos, 1)).xy; \
fixed destName = tex2D(_LightTexture0, lightCoord).w;
#endif
#endif // UNITY_VERSION >= 500
// -----------------------------
// Light helpers (4.x version)
// -----------------------------
#undef LIGHT_ATTENUATION
#ifdef POINT
#define LIGHT_ATTENUATION(a) (tex2D(_LightTexture0, dot(a._LightCoord,a._LightCoord).rr).UNITY_ATTEN_CHANNEL)
#endif
#ifdef SPOT
#define LIGHT_ATTENUATION(a) ( (a._LightCoord.z > 0) * UnitySpotCookie(a._LightCoord) * UnitySpotAttenuate(a._LightCoord.xyz) )
#endif
#ifdef DIRECTIONAL
#define LIGHT_ATTENUATION(a) 1.0
#endif
#ifdef POINT_COOKIE
#define LIGHT_ATTENUATION(a) (tex2D(_LightTextureB0, dot(a._LightCoord,a._LightCoord).rr).UNITY_ATTEN_CHANNEL * texCUBE(_LightTexture0, a._LightCoord).w)
#endif
#ifdef DIRECTIONAL_COOKIE
#define LIGHT_ATTENUATION(a) (tex2D(_LightTexture0, a._LightCoord).w)
#endif
// -----------------------------
// Salvage some macros (2018.1 or later)
// -----------------------------
#if UNITY_VERSION >= 201801
#if !defined(UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS)
#undef DECLARE_LIGHT_COORDS
#undef COMPUTE_LIGHT_COORDS
#ifdef POINT
# define DECLARE_LIGHT_COORDS(idx) unityShadowCoord3 _LightCoord : TEXCOORD##idx;
# define COMPUTE_LIGHT_COORDS(a) a._LightCoord = mul(unity_WorldToLight, mul(unity_ObjectToWorld, v.vertex)).xyz;
#endif
#ifdef SPOT
# define DECLARE_LIGHT_COORDS(idx) unityShadowCoord4 _LightCoord : TEXCOORD##idx;
# define COMPUTE_LIGHT_COORDS(a) a._LightCoord = mul(unity_WorldToLight, mul(unity_ObjectToWorld, v.vertex));
#endif
#ifdef DIRECTIONAL
#define DECLARE_LIGHT_COORDS(idx)
#define COMPUTE_LIGHT_COORDS(a)
#endif
#ifdef POINT_COOKIE
# define DECLARE_LIGHT_COORDS(idx) unityShadowCoord3 _LightCoord : TEXCOORD##idx;
# define COMPUTE_LIGHT_COORDS(a) a._LightCoord = mul(unity_WorldToLight, mul(unity_ObjectToWorld, v.vertex)).xyz;
#endif
#ifdef DIRECTIONAL_COOKIE
# define DECLARE_LIGHT_COORDS(idx) unityShadowCoord2 _LightCoord : TEXCOORD##idx;
# define COMPUTE_LIGHT_COORDS(a) a._LightCoord = mul(unity_WorldToLight, mul(unity_ObjectToWorld, v.vertex)).xy;
#endif
#endif //!defined(UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS)
#endif // UNITY_VERSION >= 201801
- Código:
// Not for redistribution without the author's express written permission
#include "HLSLSupport.cginc"
#include "UnityShaderVariables.cginc"
#ifndef UNITY_PASS_SHADOWCASTER
#define UNITY_PASS_SHADOWCASTER
#endif
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "MMD4Mecanim-MMDLit-Lighting.cginc"
#include "MMD4Mecanim-MMDLit-Surface-Lighting.cginc"
#define INTERNAL_DATA
#define WorldReflectionVector(data,normal) data.worldRefl
#define WorldNormalVector(data,normal) normal
struct v2f_surf {
V2F_SHADOW_CASTER;
float2 pack0 : TEXCOORD1;
};
v2f_surf vert_surf (appdata_full v) {
v2f_surf o;
o.pack0.xy = v.texcoord;
TRANSFER_SHADOW_CASTER(o)
return o;
}
fixed4 frag_surf (v2f_surf IN) : MMDLIT_SV_TARGET{
half4 albedo = (half4)tex2D(_MainTex, IN.pack0.xy);
albedo.a *= _Color.a; // for Transparency
MMDLIT_CLIP(albedo.a)
SHADOW_CASTER_FRAGMENT(IN)
}
fixed4 frag_fast (v2f_surf IN) : MMDLIT_SV_TARGET{
MMDLIT_CLIP_FAST(1.0)
SHADOW_CASTER_FRAGMENT(IN)
}
#ifdef TESSELLATION_ON
#ifdef UNITY_CAN_COMPILE_TESSELLATION
// tessellation domain shader
[UNITY_domain("tri")]
v2f_surf ds_surf(UnityTessellationFactors tessFactors, const OutputPatch<InternalTessInterp_appdata_full, 3> vi, float3 bary : SV_DomainLocation)
{
appdata_full v = _ds_appdata_full(tessFactors, vi, bary);
v2f_surf o = vert_surf(v);
return o;
}
#endif // UNITY_CAN_COMPILE_TESSELLATION
#endif // TESSELLATION_ON
- Código:
// Not for redistribution without the author's express written permission
#include "HLSLSupport.cginc"
#include "UnityShaderVariables.cginc"
#ifndef UNITY_PASS_FORWARDADD
#define UNITY_PASS_FORWARDADD
#endif
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "MMD4Mecanim-MMDLit-AutoLight.cginc"
#define INTERNAL_DATA
#define WorldReflectionVector(data,normal) data.worldRefl
#define WorldNormalVector(data,normal) normal
#include "MMD4Mecanim-MMDLit-Lighting.cginc"
#include "MMD4Mecanim-MMDLit-SurfaceEdge-Lighting.cginc"
struct v2f_surf {
float4 pos : SV_POSITION;
LIGHTING_COORDS(0,1)
};
v2f_surf vert_surf (appdata_full v)
{
v2f_surf o;
float3 worldN = mul((float3x3)_UNITY_OBJECT_TO_WORLD, SCALED_NORMAL);
v.vertex = MMDLit_GetEdgeVertex(v.vertex, v.normal);
o.pos = MMDLit_TransformEdgeVertex(v.vertex);
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
fixed4 frag_surf (v2f_surf IN) : MMDLIT_SV_TARGET
{
half alpha;
half3 albedo = MMDLit_GetAlbedo(alpha);
MMDLIT_CLIP(alpha)
half3 c = MMDLit_Lighting(albedo, LIGHT_ATTENUATION(IN), half3(0.0, 0.0, 0.0));
c = min(c, 1.0);
c *= alpha;
return fixed4(c, 0.0);
}
#ifdef TESSELLATION_ON
#ifdef UNITY_CAN_COMPILE_TESSELLATION
// tessellation domain shader
[UNITY_domain("tri")]
v2f_surf ds_surf(UnityTessellationFactors tessFactors, const OutputPatch<InternalTessInterp_appdata_full, 3> vi, float3 bary : SV_DomainLocation)
{
appdata_full v = _ds_appdata_full(tessFactors, vi, bary);
v2f_surf o = vert_surf(v);
return o;
}
#endif // UNITY_CAN_COMPILE_TESSELLATION
#endif // TESSELLATION_ON
- Código:
// Not for redistribution without the author's express written permission
#include "HLSLSupport.cginc"
#include "UnityShaderVariables.cginc"
#ifndef UNITY_PASS_FORWARDBASE
#define UNITY_PASS_FORWARDBASE
#endif
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "MMD4Mecanim-MMDLit-Lighting.cginc"
#include "MMD4Mecanim-MMDLit-NEXTEdge-Lighting.cginc"
struct v2f_surf {
float4 pos : SV_POSITION;
half3 viewDir : TEXCOORD1;
half3 normal : TEXCOORD2;
};
v2f_surf vert_surf (appdata_full v)
{
v2f_surf o;
v.vertex = MMDLit_GetEdgeVertex(v.vertex, v.normal);
o.pos = MMDLit_TransformEdgeVertex(v.vertex);
o.normal = mul((float3x3)_UNITY_OBJECT_TO_WORLD, SCALED_NORMAL);
o.viewDir = (half3)WorldSpaceViewDir(v.vertex);
return o;
}
half4 frag_surf (v2f_surf IN) : MMDLIT_SV_TARGET
{
half4 c = _EdgeColor;
half3 viewDir = normalize(IN.viewDir);
half r = saturate(dot(-viewDir, IN.normal));
c.a *= r * ALPHA_SCALE;
return c;
}
- Código:
// Not for redistribution without the author's express written permission
#include "HLSLSupport.cginc"
#include "UnityShaderVariables.cginc"
#ifndef UNITY_PASS_FORWARDBASE
#define UNITY_PASS_FORWARDBASE
#endif
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "MMD4Mecanim-MMDLit-AutoLight.cginc"
#define INTERNAL_DATA
#define WorldReflectionVector(data,normal) data.worldRefl
#define WorldNormalVector(data,normal) normal
#include "MMD4Mecanim-MMDLit-Lighting.cginc"
#include "MMD4Mecanim-MMDLit-SurfaceEdge-Lighting.cginc"
struct v2f_surf {
float4 pos : SV_POSITION;
LIGHTING_COORDS(0,1)
half3 vlight : TEXCOORD2;
};
v2f_surf vert_surf (appdata_full v)
{
v2f_surf o;
v.vertex = MMDLit_GetEdgeVertex(v.vertex, v.normal);
o.pos = MMDLit_TransformEdgeVertex(v.vertex);
float3 worldN = mul((float3x3)_UNITY_OBJECT_TO_WORLD, SCALED_NORMAL);
o.vlight = ShadeSH9(float4(worldN, 1.0));
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
fixed4 frag_surf (v2f_surf IN) : MMDLIT_SV_TARGET
{
half alpha;
half3 albedo = MMDLit_GetAlbedo(alpha);
MMDLIT_CLIP(alpha)
half atten = LIGHT_ATTENUATION(IN);
half3 c;
c = MMDLit_Lighting(albedo, atten, IN.vlight);
return fixed4(c, alpha);
}
#ifdef TESSELLATION_ON
#ifdef UNITY_CAN_COMPILE_TESSELLATION
// tessellation domain shader
[UNITY_domain("tri")]
v2f_surf ds_surf(UnityTessellationFactors tessFactors, const OutputPatch<InternalTessInterp_appdata_full, 3> vi, float3 bary : SV_DomainLocation)
{
appdata_full v = _ds_appdata_full(tessFactors, vi, bary);
v2f_surf o = vert_surf(v);
return o;
}
#endif // UNITY_CAN_COMPILE_TESSELLATION
#endif // TESSELLATION_ON
- Código:
// Not for redistribution without the author's express written permission
#include "HLSLSupport.cginc"
#include "UnityShaderVariables.cginc"
#ifndef UNITY_PASS_FORWARDBASE
#define UNITY_PASS_FORWARDBASE
#endif
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "MMD4Mecanim-MMDLit-AutoLight.cginc"
#define INTERNAL_DATA
#define WorldReflectionVector(data,normal) data.worldRefl
#define WorldNormalVector(data,normal) normal
#include "MMD4Mecanim-MMDLit-Lighting.cginc"
#include "MMD4Mecanim-MMDLit-Surface-Lighting.cginc"
#include "MMD4Mecanim-MMDLit-Compatible.cginc"
#ifdef TESSELLATION_ON
#include "Tessellation.cginc"
#endif
struct v2f_surf {
float4 pos : SV_POSITION;
float2 pack0 : TEXCOORD0;
half3 normal : TEXCOORD1;
half3 vlight : TEXCOORD2;
half3 viewDir : TEXCOORD3;
LIGHTING_COORDS(4,5)
half3 mmd_globalAmbient : TEXCOORD6;
#ifdef SPHEREMAP_ON
half3 mmd_uvwSphere : TEXCOORD7;
#endif
};
float4 _MainTex_ST;
v2f_surf vert_surf(appdata_full v)
{
v2f_surf o;
o.pos = _UnityObjectToClipPos(v.vertex);
o.pack0.xy = v.texcoord.xy;
float3 worldN = mul((float3x3)_UNITY_OBJECT_TO_WORLD, SCALED_NORMAL);
o.normal = worldN;
#ifdef SPHEREMAP_ON
float4x4 matMV = MMDLit_GetMatrixMV();
half3 norm = normalize(mul((float3x3)matMV, v.normal));
half3 eye = normalize(mul(matMV, v.vertex).xyz);
o.mmd_uvwSphere = reflect(eye, norm);
#endif
o.viewDir = (half3)WorldSpaceViewDir(v.vertex);
o.vlight = ShadeSH9(float4(worldN, 1.0));
o.mmd_globalAmbient = o.vlight;
#ifdef VERTEXLIGHT_ON
float3 worldPos = mul(_UNITY_OBJECT_TO_WORLD, v.vertex).xyz;
o.vlight += Shade4PointLights(
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
unity_4LightAtten0, worldPos, worldN );
#endif // VERTEXLIGHT_ON
// Feedback Ambient.
o.vlight *= MMDLit_GetAmbientRate();
TRANSFER_VERTEX_TO_FRAGMENT(o);
return o;
}
inline half4 frag_core(in v2f_surf IN, half4 albedo)
{
half atten = LIGHT_ATTENUATION(IN);
half shadowAtten = SHADOW_ATTENUATION(IN);
half3 c;
half3 baseC;
half NdotL = dot(IN.normal, _WorldSpaceLightPos0.xyz);
c = MMDLit_Lighting(
(half3)albedo,
#ifdef SPHEREMAP_ON
IN.mmd_uvwSphere,
#else
half3( 0.0, 0.0, 0.0 ),
#endif
NdotL,
IN.normal,
_WorldSpaceLightPos0.xyz,
normalize(IN.viewDir),
atten,
shadowAtten,
baseC,
IN.mmd_globalAmbient);
c += baseC * IN.vlight;
return half4(c, albedo.a);
}
// for Transparency
half4 frag_surf(v2f_surf IN) : MMDLIT_SV_TARGET
{
half4 albedo = MMDLit_GetAlbedo(IN.pack0.xy);
albedo.a *= _Color.a; // for Transparency
MMDLIT_CLIP(albedo.a)
return frag_core(IN, albedo);
}
// for Opaque
half4 frag_fast(v2f_surf IN) : MMDLIT_SV_TARGET
{
half4 albedo = MMDLit_GetAlbedo(IN.pack0.xy);
MMDLIT_CLIP_FAST(albedo.a)
return frag_core(IN, albedo);
}
#ifdef TESSELLATION_ON
#ifdef UNITY_CAN_COMPILE_TESSELLATION
// tessellation domain shader
[UNITY_domain("tri")]
v2f_surf ds_surf(UnityTessellationFactors tessFactors, const OutputPatch<InternalTessInterp_appdata_full, 3> vi, float3 bary : SV_DomainLocation)
{
appdata_full v = _ds_appdata_full(tessFactors, vi, bary);
v2f_surf o = vert_surf(v);
return o;
}
#endif // UNITY_CAN_COMPILE_TESSELLATION
#endif // TESSELLATION_ON
- Código:
// Not for redistribution without the author's express written permission
// UNITY_SHADER_NO_UPGRADE
#ifndef MMDLIT_SURFACE_TESSELLATION_INCLUDED
#define MMDLIT_SURFACE_TESSELLATION_INCLUDED
#ifdef TESSELLATION_ON
#include "HLSLSupport.cginc" // UNITY_CAN_COMPILE_TESSELLATION
#include "Lighting.cginc" // UnityTessellationFactors
#include "Tessellation.cginc"
#ifdef UNITY_CAN_COMPILE_TESSELLATION
float _TessPhongStrength;
float _TessEdgeLength;
float _TessExtrusionAmount;
#if UNITY_VERSION >= 500
struct InternalTessInterp_appdata_full
{
float4 vertex : INTERNALTESSPOS;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
float4 texcoord2 : TEXCOORD2;
float4 texcoord3 : TEXCOORD3;
#if defined(SHADER_API_XBOX360)
half4 texcoord4 : TEXCOORD4;
half4 texcoord5 : TEXCOORD5;
#endif // defined(SHADER_API_XBOX360)
fixed4 color : COLOR;
// UNITY_INSTANCE_ID
};
#else // UNITY_VERSION >= 500
struct InternalTessInterp_appdata_full
{
float4 vertex : INTERNALTESSPOS;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
fixed4 color : COLOR;
#if defined(SHADER_API_XBOX360)
half4 texcoord2 : TEXCOORD2;
half4 texcoord3 : TEXCOORD3;
half4 texcoord4 : TEXCOORD4;
half4 texcoord5 : TEXCOORD5;
#endif // defined(SHADER_API_XBOX360)
};
#endif // UNITY_VERSION >= 500
InternalTessInterp_appdata_full tess_appdata_full(appdata_full v)
{
InternalTessInterp_appdata_full o;
o.vertex = v.vertex;
o.tangent = v.tangent;
o.normal = v.normal;
o.texcoord = v.texcoord;
o.texcoord1 = v.texcoord1;
o.color = v.color;
#if UNITY_VERSION >= 500
o.texcoord2 = v.texcoord2;
o.texcoord3 = v.texcoord3;
#if defined(SHADER_API_XBOX360)
o.texcoord4 = v.texcoord4;
o.texcoord5 = v.texcoord5;
#endif // defined(SHADER_API_XBOX360)
#else // UNITY_VERSION >= 500
#if defined(SHADER_API_XBOX360)
o.texcoord2 = v.texcoord2;
o.texcoord3 = v.texcoord3;
o.texcoord4 = v.texcoord4;
o.texcoord5 = v.texcoord5;
#endif // defined(SHADER_API_XBOX360)
#endif // UNITY_VERSION >= 500
return o;
}
// tessellation hull constant shader
UnityTessellationFactors hsconst_appdata_full(InputPatch<InternalTessInterp_appdata_full, 3> v)
{
float4 tf = UnityEdgeLengthBasedTess(v[0].vertex, v[1].vertex, v[2].vertex, _TessEdgeLength);
UnityTessellationFactors o;
o.edge[0] = tf.x;
o.edge[1] = tf.y;
o.edge[2] = tf.z;
o.inside = tf.w;
return o;
}
// tessellation hull shader
[UNITY_domain("tri")]
[UNITY_partitioning("fractional_odd")]
[UNITY_outputtopology("triangle_cw")]
[UNITY_patchconstantfunc("hsconst_appdata_full")]
[UNITY_outputcontrolpoints(3)]
InternalTessInterp_appdata_full hs_appdata_full(InputPatch<InternalTessInterp_appdata_full, 3> v, uint id : SV_OutputControlPointID)
{
return v[id];
}
inline appdata_full _ds_appdata_full(UnityTessellationFactors tessFactors, const OutputPatch<InternalTessInterp_appdata_full, 3> vi, float3 bary : SV_DomainLocation)
{
appdata_full v;
v.vertex = vi[0].vertex*bary.x + vi[1].vertex*bary.y + vi[2].vertex*bary.z;
float3 pp[3];
for (int i = 0; i < 3; ++i)
pp[i] = v.vertex.xyz - vi[i].normal * (dot(v.vertex.xyz, vi[i].normal) - dot(vi[i].vertex.xyz, vi[i].normal));
v.vertex.xyz = _TessPhongStrength * (pp[0] * bary.x + pp[1] * bary.y + pp[2] * bary.z) + (1.0f - _TessPhongStrength) * v.vertex.xyz;
v.tangent = vi[0].tangent*bary.x + vi[1].tangent*bary.y + vi[2].tangent*bary.z;
v.normal = vi[0].normal*bary.x + vi[1].normal*bary.y + vi[2].normal*bary.z;
v.vertex.xyz += v.normal.xyz * _TessExtrusionAmount;
v.texcoord = vi[0].texcoord*bary.x + vi[1].texcoord*bary.y + vi[2].texcoord*bary.z;
v.texcoord1 = vi[0].texcoord1*bary.x + vi[1].texcoord1*bary.y + vi[2].texcoord1*bary.z;
v.color = vi[0].color*bary.x + vi[1].color*bary.y + vi[2].color*bary.z;
#if UNITY_VERSION >= 500
v.texcoord2 = vi[0].texcoord2*bary.x + vi[1].texcoord2*bary.y + vi[2].texcoord2*bary.z;
v.texcoord3 = vi[0].texcoord3*bary.x + vi[1].texcoord3*bary.y + vi[2].texcoord3*bary.z;
#if defined(SHADER_API_XBOX360)
v.texcoord4 = vi[0].texcoord4*bary.x + vi[1].texcoord4*bary.y + vi[2].texcoord4*bary.z;
v.texcoord5 = vi[0].texcoord5*bary.x + vi[1].texcoord5*bary.y + vi[2].texcoord5*bary.z;
#endif // defined(SHADER_API_XBOX360)
#else // UNITY_VERSION >= 500
#if defined(SHADER_API_XBOX360)
v.texcoord2 = vi[0].texcoord2*bary.x + vi[1].texcoord2*bary.y + vi[2].texcoord2*bary.z;
v.texcoord3 = vi[0].texcoord3*bary.x + vi[1].texcoord3*bary.y + vi[2].texcoord3*bary.z;
v.texcoord4 = vi[0].texcoord4*bary.x + vi[1].texcoord4*bary.y + vi[2].texcoord4*bary.z;
v.texcoord5 = vi[0].texcoord5*bary.x + vi[1].texcoord5*bary.y + vi[2].texcoord5*bary.z;
#endif // defined(SHADER_API_XBOX360)
#endif // UNITY_VERSION >= 500
return v;
}
#endif // UNITY_CAN_COMPILE_TESSELLATION
#endif // TESSELLATION_ON
#endif // MMDLIT_SURFACE_TESSELLATION_INCLUDED
- Código:
// UNITY_SHADER_NO_UPGRADE
#ifndef MMD4MECANIM_MMDLIT_COMPATIBLE_INCLUDED
#define MMD4MECANIM_MMDLIT_COMPATIBLE_INCLUDED
#if UNITY_VERSION >= 540
#define _UNITY_OBJECT_TO_WORLD unity_ObjectToWorld
#else
#define _UNITY_OBJECT_TO_WORLD _Object2World
#endif
#if UNITY_VERSION >= 560
#define _UNITY_SHADOW_ATTENUATION UNITY_SHADOW_ATTENUATION
#else
#define _UNITY_SHADOW_ATTENUATION(a, worldPos) SHADOW_ATTENUATION(a)
#endif
#if UNITY_VERSION >= 550
#define _UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_VERTEX_INPUT_INSTANCE_ID
#else
#define _UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_INSTANCE_ID
#endif
#if UNITY_VERSION >= 540
#define _UnityObjectToClipPos(V_) UnityObjectToClipPos(V_)
#define _UnityObjectToViewPos(V_) UnityObjectToViewPos(V_)
#else
#define _UnityObjectToClipPos(V_) mul(UNITY_MATRIX_MVP, V_)
#define _UnityObjectToViewPos(V_) mul(UNITY_MATRIX_MV, float4((float3)V_, 1.0)).xyz
#endif
#if UNITY_VERSION >= 540
#ifdef UNITY_USE_PREMULTIPLIED_MATRICES
inline float4x4 MMDLit_GetMatrixMV() { return UNITY_MATRIX_MV; }
#else
inline float4x4 MMDLit_GetMatrixMV() { return mul(UNITY_MATRIX_V, _UNITY_OBJECT_TO_WORLD); }
#endif
#else
inline float4x4 MMDLit_GetMatrixMV() { return UNITY_MATRIX_MV; }
#endif
#endif
- Código:
// Not for redistribution without the author's express written permission
#ifndef MMDLIT_SURFACEEDGE_LIGHTING_INCLUDED
#define MMDLIT_SURFACEEDGE_LIGHTING_INCLUDED
#include "MMD4Mecanim-MMDLit-Surface-Tessellation.cginc"
#include "MMD4Mecanim-MMDLit-Compatible.cginc"
half _AmbientToDiffuse;
half4 _EdgeColor;
float _EdgeSize;
#define MMDLIT_GLOBALLIGHTING (0.6)
#define MMDLIT_EDGE_ZOFST (0.00001)
inline float MMDLit_GetEdgeSize()
{
return _EdgeSize;
}
inline float4 MMDLit_GetEdgeVertex(float4 vertex, float3 normal)
{
#if 1
float edge_size = MMDLit_GetEdgeSize();
#else
// Adjust edge_size by distance & fovY
float4 world_pos = mul(MMDLit_GetMatrixMV(), vertex);
float r_proj_y = UNITY_MATRIX_P[1][1];
float edge_size = abs(MMDLit_GetEdgeSize() / r_proj_y * world_pos.z) * 2.0;
#endif
return vertex + float4(normal.xyz * edge_size, 0.0);
}
inline float4 MMDLit_TransformEdgeVertex(float4 vertex)
{
#if 0
vertex = _UnityObjectToClipPos(vertex);
vertex.z += MMDLIT_EDGE_ZOFST * vertex.w;
return vertex;
#else
return _UnityObjectToClipPos(vertex);
#endif
}
inline half3 MMDLit_GetAlbedo(out half alpha)
{
alpha = _EdgeColor.a;
return (half3)_EdgeColor;
}
inline half3 MMDLit_Lighting(half3 albedo, half atten, half3 globalAmbient)
{
half3 color = (half3)_LightColor0 * MMDLIT_ATTEN(atten);
color *= MMDLIT_GLOBALLIGHTING;
#ifdef AMB2DIFF_ON
color *= saturate(globalAmbient * _AmbientToDiffuse); // Feedback ambient for Unity5.
#endif
#ifdef UNITY_PASS_FORWARDADD
// No Ambient.
#else
color += globalAmbient;
#endif
color *= albedo;
return color;
}
#endif // MMDLIT_SURFACEEDGE_LIGHTING_INCLUDED
- Código:
#include "MMD4Mecanim-MMDLit-Compatible.cginc"
// Not for redistribution without the author's express written permission
half4 _EdgeColor;
float _EdgeSize;
//float _EdgeZOffset;
inline float MMDLit_GetEdgeSize()
{
return _EdgeSize * EDGE_SCALE;
}
inline float4 MMDLit_GetEdgeVertex(float4 vertex, float3 normal)
{
#if 0
float edge_size = MMDLit_GetEdgeSize();
#else
// Adjust edge_size by distance & fovY
float r_proj_y = UNITY_MATRIX_P[1][1];
float edge_size = abs(MMDLit_GetEdgeSize() / r_proj_y);
#endif
return vertex + float4(normal.xyz * edge_size, 0.0);
}
inline float4 MMDLit_TransformEdgeVertex(float4 vertex)
{
#if 1
return _UnityObjectToClipPos(vertex);
#else
vertex = _UnityObjectToClipPos(vertex);
vertex.z += _EdgeZOffset * vertex.w;
return vertex;
#endif
}
- Código:
// Not for redistribution without the author's express written permission
// UNITY_SHADER_NO_UPGRADE
#ifndef MMDLIT_LIGHTING_INCLUDED
#define MMDLIT_LIGHTING_INCLUDED
#include "MMD4Mecanim-MMDLit-Compatible.cginc"
#if UNITY_VERSION >= 500
#define MMDLIT_ATTEN(ATTEN_) (ATTEN_)
#define MMDLIT_SV_TARGET SV_Target
#else
#define MMDLIT_ATTEN(ATTEN_) (ATTEN_ * 2)
#define MMDLIT_SV_TARGET COLOR
#endif
#if defined(SPHEREMAP_MUL) || defined(SPHEREMAP_ADD)
#define SPHEREMAP_ON
#endif
// UnityCG.cginc
inline half3 MMDLit_DecodeLightmap(half4 color)
{
#if (defined(SHADER_API_GLES) || defined(SHADER_API_GLES3)) && defined(SHADER_API_MOBILE)
return (2.0 * (half3)color);
#else
// potentially faster to do the scalar multiplication
// in parenthesis for scalar GPUs
return (8.0 * color.a) * (half3)color;
#endif
}
// Lighting.cginc
inline half3 MMDLit_DirLightmapDiffuse(in half3x3 dirBasis, half4 color, half4 scale, half3 normal, bool surfFuncWritesNormal, out half3 scalePerBasisVector)
{
half3 lm = MMDLit_DecodeLightmap(color);
// will be compiled out (and so will the texture sample providing the value)
// if it's not used in the lighting function, like in LightingLambert
scalePerBasisVector = MMDLit_DecodeLightmap(scale);
// will be compiled out when surface function does not write into o.Normal
if (surfFuncWritesNormal)
{
half3 normalInRnmBasis = saturate(mul(dirBasis, normal));
lm *= dot (normalInRnmBasis, scalePerBasisVector);
}
return lm;
}
// UnityCG.cginc
inline half MMDLit_Luminance( half3 c )
{
return dot( c, half3(0.22, 0.707, 0.071) );
}
inline half MMDLit_SpecularRefl( half3 normal, half3 lightDir, half3 viewDir, half s )
{
//return saturate(pow(saturate(dot(normal, normalize(lightDir + viewDir))), s));
return pow(saturate(dot(normal, normalize(lightDir + viewDir))), s); // Optimized.
// (Memo: pow(x,0) as Depends on the particular graphics processor 0 or NaN)
}
// Platform limitation. (Must be unsupported without permission.)
#if defined(SHADER_API_PSSL) || defined(SHADER_API_XBOXONE) || defined(SHADER_API_XBOX360) || defined(SHADER_API_PSP2) || defined(SHADER_API_WIIU)
#define _SHADER_API_CONSOLE
#endif
#ifdef _SHADER_API_CONSOLE
#define MMDLIT_CLIP(A_) clip((A_) - (1.0 / 255.0));
#define MMDLIT_CLIP_FAST(A_)
#else
half ___Eliminate; // Please observe terms of use. (Don't modify this code)
#define MMDLIT_CLIP(A_) clip((A_) * ___Eliminate - (1.0 / 255.0));
#define MMDLIT_CLIP_FAST(A_) MMDLIT_CLIP((A_))
#endif
#endif
- Código:
// Not for redistribution without the author's express written permission
#ifndef MMDLIT_SURFACE_LIGHTING_INCLUDED
#define MMDLIT_SURFACE_LIGHTING_INCLUDED
//#include "MMD4Mecanim-MMDLit-Lighting.cginc"
#include "MMD4Mecanim-MMDLit-Surface-Tessellation.cginc"
#ifndef MMD4MECANIM_STANDARD
half4 _Color;
#endif
half4 _Specular;
half4 _Ambient;
half _Shininess;
half _ShadowLum;
half _AmbientToDiffuse;
#ifndef MMD4MECANIM_STANDARD
sampler2D _MainTex;
#endif
sampler2D _ToonTex;
half _AddLightToonCen;
half _AddLightToonMin;
half4 _ToonTone;
half4 _Emissive;
samplerCUBE _SphereCube;
#define MMDLIT_GLOBALLIGHTING half3(0.6, 0.6, 0.6)
#define MMDLIT_CENTERAMBIENT half3(0.5, 0.5, 0.5)
#define MMDLIT_CENTERAMBIENT_INV half3(1.0 / 0.5, 1.0 / 0.5, 1.0 / 0.5)
#define MMDLIT_DIFFUSECLIPPING half3(0.5, 0.5, 0.5)
// Ambient Feedback Rate from Unity.
inline half3 MMDLit_GetTempAmbientL()
{
return max(MMDLIT_CENTERAMBIENT - (half3)_Ambient, half3(0,0,0)) * MMDLIT_CENTERAMBIENT_INV;
}
inline half3 MMDLit_GetAmbientRate()
{
return half3(1.0, 1.0, 1.0) - MMDLit_GetTempAmbientL();
}
inline half3 MMDLit_GetTempAmbient( half3 globalAmbient )
{
return globalAmbient * MMDLit_GetAmbientRate();
}
inline half3 MMDLit_GetTempDiffuse( half3 globalAmbient )
{
half3 tempColor = min((half3)_Ambient + (half3)_Color * MMDLIT_GLOBALLIGHTING, half3(1,1,1));
tempColor = max(tempColor - MMDLit_GetTempAmbient(globalAmbient), half3(0,0,0));
#ifdef AMB2DIFF_ON // Passed in Forward Add
tempColor *= min(globalAmbient * _AmbientToDiffuse, half3(1,1,1)); // Feedback ambient for Unity5.
#endif
return tempColor;
}
inline half3 MMDLit_GetTempDiffuse_NoAmbient()
{
half3 tempColor = saturate((half3)_Ambient + (half3)_Color * MMDLIT_GLOBALLIGHTING - MMDLIT_DIFFUSECLIPPING);
return tempColor;
}
inline void MMDLit_GetBaseColor(
half3 albedo,
half3 tempDiffuse,
half3 uvw_Sphere,
out half3 baseC,
out half3 baseD)
{
#ifdef SPHEREMAP_MUL
half3 sph = (half3)texCUBE(_SphereCube, uvw_Sphere);
baseC = albedo * sph;
baseD = baseC * tempDiffuse; // for Diffuse only.
#elif SPHEREMAP_ADD
half3 sph = (half3)texCUBE(_SphereCube, uvw_Sphere);
baseC = albedo + sph;
baseD = albedo * tempDiffuse + sph; // for Diffuse only.
#else
baseC = albedo;
baseD = albedo * tempDiffuse;
#endif
}
inline half4 MMDLit_GetAlbedo(float2 uv_MainTex)
{
return (half4)tex2D(_MainTex, uv_MainTex);
}
inline half MMDLit_GetToolRefl(half NdotL)
{
return NdotL * _ToonTone.y + _ToonTone.z; // Necesally saturate.
}
inline half MMDLit_GetShadowAttenToToon(half shadowAtten)
{
return ((shadowAtten - 0.5) * _ToonTone.x) + _ToonTone.z; // Necesally saturate.
}
inline half MMDLit_GetToonShadow(half toonRefl)
{
half toonShadow = toonRefl * 2.0;
return (half)saturate(toonShadow * toonShadow - 1.0);
}
inline half MMDLit_GetForwardAddStr(half toonRefl)
{
half toonShadow = (toonRefl - _AddLightToonCen) * 2.0;
return (half)clamp(toonShadow * toonShadow - 1.0, _AddLightToonMin, 1.0);
}
// for ForwardBase
inline half3 MMDLit_GetRamp(half NdotL, half shadowAtten)
{
half refl = saturate(min(MMDLit_GetToolRefl(NdotL), MMDLit_GetShadowAttenToToon(shadowAtten)));
half toonRefl = refl;
#ifdef SELFSHADOW_ON
refl = 0;
#endif
half3 ramp = (half3)tex2D(_ToonTex, half2(refl, refl));
#ifdef SELFSHADOW_ON
half toonShadow = MMDLit_GetToonShadow(toonRefl);
ramp = lerp(ramp, half3(1.0, 1.0, 1.0), toonShadow);
#endif
ramp = saturate(1.0 - (1.0 - ramp) * _ShadowLum);
return ramp;
}
// for ForwardAdd
inline half3 MMDLit_GetRamp_Add(half toonRefl, half toonShadow)
{
half refl = saturate(toonRefl);
#ifdef SELFSHADOW_ON
refl = 0;
#endif
half3 ramp = (half3)tex2D(_ToonTex, half2(refl, refl));
#ifdef SELFSHADOW_ON
half3 rampSS = (1.0 - toonShadow) * ramp + toonShadow;
ramp = rampSS;
#endif
ramp = saturate(1.0 - (1.0 - ramp) * _ShadowLum);
return ramp;
}
// for FORWARD_BASE
inline half3 MMDLit_Lighting(
half3 albedo,
half3 uvw_Sphere,
half NdotL,
half3 normal,
half3 lightDir,
half3 viewDir,
half atten,
half shadowAtten,
out half3 baseC,
half3 globalAmbient)
{
half3 ramp = MMDLit_GetRamp(NdotL, shadowAtten);
half3 lightColor = (half3)_LightColor0 * MMDLIT_ATTEN(atten);
half3 baseD;
MMDLit_GetBaseColor(albedo, MMDLit_GetTempDiffuse(globalAmbient), uvw_Sphere, baseC, baseD);
half3 c = baseD * lightColor * ramp;
#ifdef SPECULAR_ON
half refl = MMDLit_SpecularRefl(normal, lightDir, viewDir, _Shininess);
c += (half3)_Specular * lightColor * refl;
#endif
#ifdef EMISSIVE_ON
// AutoLuminous
c += baseC * (half3)_Emissive;
#endif
return c;
}
// for FORWARD_ADD
inline half3 MMDLit_Lighting_Add(
half3 albedo,
half NdotL,
half toonRefl,
half toonShadow,
half3 normal,
half3 lightDir,
half3 viewDir,
half atten)
{
half3 ramp = MMDLit_GetRamp_Add(toonRefl, toonShadow);
half3 lightColor = (half3)_LightColor0 * MMDLIT_ATTEN(atten);
half3 baseC;
half3 baseD;
MMDLit_GetBaseColor(albedo, MMDLit_GetTempDiffuse_NoAmbient(), half3(0.0, 0.0, 0.0), baseC, baseD);
half3 c = baseD * lightColor * ramp;
#ifdef SPECULAR_ON
half refl = MMDLit_SpecularRefl(normal, lightDir, viewDir, _Shininess);
c += (half3)_Specular * lightColor * refl;
#endif
return c;
}
inline half MMDLit_MulAtten(half atten, half shadowAtten)
{
return atten * shadowAtten;
}
#endif // MMDLIT_SURFACE_LIGHTING_INCLUDED
Tópicos semelhantes
» [DUVIDA] UNITY COM SHADER HORRIVEL!!!!
» Como fazer um shader OutLine no Unity URP(PBR Graph) ?
» Tem Como Fazer um Shader com o Shader Graph que Deixa a Escala Infinita?
» Shader
» Problema com o Shader (Shader Bloqueado)
» Como fazer um shader OutLine no Unity URP(PBR Graph) ?
» Tem Como Fazer um Shader com o Shader Graph que Deixa a Escala Infinita?
» Shader
» Problema com o Shader (Shader Bloqueado)
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos