I saw this thread. It didn't help me any bit. Thanks anyway 😉
SoulGame đã viếtWow, that's pretty much exactly the question I came to ask. I'm trying to merge Spine/Skeleton with DefaultColorFlash, but it's quite a mess. I can't get rid of all errors. (Although I'm not sure why I'm trying to do that since I have no idea what Spine/Skeleton is meant for, I'm just reluctant to remove it since it's probably needed by spine-runtime somehow)Anyway, if you could share your progress with the merging it would be nice, you might be John Snow, but I'm Hodor here.
Yeah sure. It's enough that one persons throws away a little life time 😃
But be prepared, as I mentioned in my edit, I took the generated code. The lighting-shader code is pretty messed up now (but at the moment I don't really care too much about a 'clean shader code')
To clear things up at least a little here. Every adjustment I took is marked with the comment "//color shader"
You will find those at line: 102, 124, 150, 160
Shader "YourProjectHere/YourFavouriteShaderName"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_FlashColor ("Flash Color", Color) = (1,1,1,1)
_FlashAmount ("Flash Amount",Range(0.0,1.0)) = 0.0
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
_Cutoff ("Shadow alpha cutoff", Range(0,1)) = 0.1
}
// 2 texture stage GPUs
SubShader {
LOD 100
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Cull Off
ZWrite Off
Blend One OneMinusSrcAlpha
Pass {
Tags { "LIGHTMODE"="Vertex" "QUEUE"="Transparent" "IGNOREPROJECTOR"="true" "RenderType"="Transparent" }
ZWrite Off
Cull Off
Blend One OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityShaderVariables.cginc"
#pragma multi_compile_fog
#include "UnityCG.cginc"
#define USING_FOG (defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2))
// ES2.0/WebGL/3DS can not do loops with non-constant-expression iteration counts :(
#if defined(SHADER_API_GLES)
#define LIGHT_LOOP_LIMIT 8
#elif defined(SHADER_API_N3DS)
#define LIGHT_LOOP_LIMIT 4
#else
#define LIGHT_LOOP_LIMIT unity_VertexLightParams.x
#endif
#define ENABLE_SPECULAR (!defined(SHADER_API_N3DS))
// Compile specialized variants for when positional (point/spot) and spot lights are present
#pragma multi_compile __ POINT SPOT
// Compute illumination from one light, given attenuation
half3 computeLighting (int idx, half3 dirToLight, half3 eyeNormal, half3 viewDir, half4 diffuseColor, half shininess, half atten, inout half3 specColor) {
half NdotL = max(dot(eyeNormal, dirToLight), 0.0);
// diffuse
half3 color = NdotL * diffuseColor.rgb * unity_LightColor[idx].rgb;
return color * atten;
}
// Compute attenuation & illumination from one light
half3 computeOneLight(int idx, float3 eyePosition, half3 eyeNormal, half3 viewDir, half4 diffuseColor, half shininess, inout half3 specColor) {
float3 dirToLight = unity_LightPosition[idx].xyz;
half att = 1.0;
#if defined(POINT) || defined(SPOT)
dirToLight -= eyePosition * unity_LightPosition[idx].w;
// distance attenuation
float distSqr = dot(dirToLight, dirToLight);
att /= (1.0 + unity_LightAtten[idx].z * distSqr);
if (unity_LightPosition[idx].w != 0 && distSqr > unity_LightAtten[idx].w) att = 0.0; // set to 0 if outside of range
dirToLight *= rsqrt(distSqr);
#if defined(SPOT)
// spot angle attenuation
half rho = max(dot(dirToLight, unity_SpotDirection[idx].xyz), 0.0);
half spotAtt = (rho - unity_LightAtten[idx].x) * unity_LightAtten[idx].y;
att *= saturate(spotAtt);
#endif
#endif
att *= 0.5; // passed in light colors are 2x brighter than what used to be in FFP
return min (computeLighting (idx, dirToLight, eyeNormal, viewDir, diffuseColor, shininess, att, specColor), 1.0);
}
// uniforms
int4 unity_VertexLightParams; // x: light count, y: zero, z: one (y/z needed by d3d9 vs loop instruction)
float4 _MainTex_ST;
// vertex shader input data
struct appdata {
float3 pos : POSITION;
float3 normal : NORMAL;
half4 color : COLOR;
float3 uv0 : TEXCOORD0;
};
// vertex-to-fragment interpolators
struct v2f {
fixed4 color : COLOR0;
float2 uv0 : TEXCOORD0;
#if USING_FOG
fixed fog : TEXCOORD1;
#endif
float4 pos : SV_POSITION;
};
// color shader
fixed4 _Color;
fixed4 _FlashColor;
float _FlashAmount;
// vertex shader
v2f vert (appdata IN) {
v2f o;
half4 color = IN.color;
float3 eyePos = mul (UNITY_MATRIX_MV, float4(IN.pos,1)).xyz;
half3 eyeNormal = normalize (mul ((float3x3)UNITY_MATRIX_IT_MV, IN.normal).xyz);
half3 viewDir = 0.0;
// lighting
half3 lcolor = half4(0,0,0,1).rgb + color.rgb * glstate_lightmodel_ambient.rgb;
half3 specColor = 0.0;
half shininess = 0 * 128.0;
for (int il = 0; il < LIGHT_LOOP_LIMIT; ++il) {
lcolor += computeOneLight(il, eyePos, eyeNormal, viewDir, color, shininess, specColor);
}
color.rgb = lcolor.rgb;
color.a = color.a;
// color shader
o.color = IN.color * _Color * saturate(color);
// compute texture coordinates
o.uv0 = IN.uv0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
// fog
#if USING_FOG
float fogCoord = length(eyePos.xyz); // radial fog distance
UNITY_CALC_FOG_FACTOR(fogCoord);
o.fog = saturate(unityFogFactor);
#endif
// transform position
o.pos = mul(UNITY_MATRIX_MVP, float4(IN.pos,1));
return o;
}
// textures
sampler2D _MainTex;
// fragment shader
fixed4 frag (v2f IN) : SV_Target {
fixed4 col;
fixed4 tex, tmp0, tmp1, tmp2;
// SetTexture #0
tex = tex2D (_MainTex, IN.uv0.xy);
// color shader
col.rgb = tex * IN.color;
// color shader
col *= 1.8;
col.a = tex.a * IN.color.a;
// fog
#if USING_FOG
col.rgb = lerp (unity_FogColor.rgb, col.rgb, IN.fog);
#endif
// color shader
col.rgb *= lerp(col.rgb, _FlashColor.rgb, _FlashAmount);
col.rgb *= col.a
return col;
}
// texenvs
//! TexEnv0: 02010103 01050107 [_MainTex]
ENDCG
}
Pass
{
Name "Caster"
Tags { "LightMode"="ShadowCaster" }
Offset 1, 1
Fog { Mode Off }
ZWrite On
ZTest LEqual
Cull Off
Lighting Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#pragma fragmentoption ARB_precision_hint_fastest
#include "UnityCG.cginc"
struct v2f {
V2F_SHADOW_CASTER;
float2 uv : TEXCOORD1;
};
uniform float4 _MainTex_ST;
v2f vert (appdata_base v) {
v2f o;
TRANSFER_SHADOW_CASTER(o)
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
uniform sampler2D _MainTex;
uniform fixed _Cutoff;
float4 frag (v2f i) : COLOR {
fixed4 texcol = tex2D(_MainTex, i.uv);
clip(texcol.a - _Cutoff);
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
}
// 1 texture stage GPUs
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
LOD 100
Cull Off
ZWrite Off
Blend One OneMinusSrcAlpha
Pass {
Tags { "LightMode"="Vertex" }
ColorMaterial AmbientAndDiffuse
Lighting On
SetTexture [_MainTex] {
Combine texture * primary DOUBLE, texture * primary
}
}
}
}
You should be able to copy-paste the whole thing. (and adjust the name). I hope I can save you some headaches. Hodor.
Edit: I just realized, that you asked for the 'normal' Skeleton shader. I could replace it with the DefaultColorShader. That doesn't work for you?