Harald Oh you did, you never mentioned that above.
I meant it with this line,
sindex I've noticed something, this happens with the code I posted and your solution.
I am sorry for not being clear enough.
This is where I've defined the keyword
Properties {
[NoScaleOffset] _MainTex("Main Texture", 2D) = "black" {}
[HideInInspector] _StencilRef("Stencil Reference", Float) = 1.0
[Enum(UnityEngine.Rendering.CompareFunction)] _StencilComp("Stencil Comparison", Float) = 8 // Set to Always as default
[MaterialToggle(WORLDSPACE_OUTLINE_WIDTH)] _UseWorldSpaceOutline("Use World Space Outline", Float) = 1
// Outline properties are drawn via custom editor.
[HideInInspector] _OutlineWidth("Outline Width", Range(0,16)) = 3.0
[HideInInspector] _OutlineColor("Outline Color", Color) = (1,1,0,1)
[HideInInspector] _OutlineReferenceTexWidth("Reference Texture Width", Int) = 1024
[HideInInspector] _ThresholdEnd("Outline Threshold", Range(0,1)) = 0.25
[HideInInspector] _OutlineSmoothness("Outline Smoothness", Range(0,1)) = 1.0
[HideInInspector][MaterialToggle(_USE8NEIGHBOURHOOD_ON)] _Use8Neighbourhood("Sample 8 Neighbours", Float) = 1
[HideInInspector] _OutlineOpaqueAlpha("Opaque Alpha", Range(0,1)) = 1.0
[HideInInspector] _OutlineMipLevel("Outline Mip Level", Range(0,3)) = 0
}
SubShader {
// Universal Pipeline tag is required. If Universal render pipeline is not set in the graphics settings
// this Subshader will fail.
Tags { "RenderPipeline" = "UniversalPipeline" "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
LOD 100
Cull Off
ZWrite Off
Blend One OneMinusSrcAlpha
Stencil {
Ref[_StencilRef]
Comp[_StencilComp]
Pass Keep
}
Pass {
Name "Outline"
HLSLPROGRAM
// Required to compile gles 2.0 with standard srp library
#pragma prefer_hlslcc gles
#pragma exclude_renderers d3d11_9x
//--------------------------------------
// GPU Instancing
#pragma multi_compile_instancing
#pragma vertex vertOutline
#pragma fragment fragOutline
#pragma shader_feature _ _USE8NEIGHBOURHOOD_ON
#pragma shader_feature _ WORLDSPACE_OUTLINE_WIDTH_ON
#define USE_URP
#define fixed4 half4
#define fixed3 half3
#define fixed half
#define NO_CUTOFF_PARAM
#include "Packages/com.esotericsoftware.spine.urp-shaders/Shaders/Include/Spine-Input-Outline-URP.hlsl"
#include "Spine-Custom-URP-Outline-Pass.hlsl"
ENDHLSL
}
and how I am using it
float4 computeOutlinePixel(sampler2D mainTexture, float2 mainTextureTexelSize,
float2 uv, float vertexColorAlpha,
float OutlineWidth, float OutlineReferenceTexWidth, float OutlineMipLevel,
float OutlineSmoothness, float ThresholdEnd, float OutlineOpaqueAlpha, float4 OutlineColor) {
float4 texColor = fixed4(0, 0, 0, 0);
#if WORLDSPACE_OUTLINE_WIDTH_ON
float outlineWidthCompensated = OutlineWidth / (OutlineReferenceTexWidth * mainTextureTexelSize.x);
float xOffset = mainTextureTexelSize.x * outlineWidthCompensated;
float yOffset = mainTextureTexelSize.y * outlineWidthCompensated;
float xOffsetDiagonal = mainTextureTexelSize.x * outlineWidthCompensated * 0.7;
float yOffsetDiagonal = mainTextureTexelSize.y * outlineWidthCompensated * 0.7;
#else
float2 ddxUV = ddx(uv);
float2 ddyUV = ddy(uv);
float2 ddu = float2(ddxUV.x, ddyUV.x);
float2 ddv = float2(ddxUV.y, ddyUV.y);
float xOffset = length(ddu) * OutlineWidth * mainTextureTexelSize.x * OutlineReferenceTexWidth;
float yOffset = length(ddv) * OutlineWidth * mainTextureTexelSize.x * OutlineReferenceTexWidth;
float xOffsetDiagonal = xOffset * 0.7;
float yOffsetDiagonal = yOffset * 0.7;
#endif
float pixelCenter = tex2D(mainTexture, uv).a;
float4 uvCenterWithLod = float4(uv, 0, OutlineMipLevel);
float pixelTop = tex2Dlod(mainTexture, uvCenterWithLod + float4(0, yOffset, 0, 0)).a;
float pixelBottom = tex2Dlod(mainTexture, uvCenterWithLod + float4(0, -yOffset, 0, 0)).a;
float pixelLeft = tex2Dlod(mainTexture, uvCenterWithLod + float4(-xOffset, 0, 0, 0)).a;
float pixelRight = tex2Dlod(mainTexture, uvCenterWithLod + float4(xOffset, 0, 0, 0)).a;
#if _USE8NEIGHBOURHOOD_ON
float numSamples = 8;
float pixelTopLeft = tex2Dlod(mainTexture, uvCenterWithLod + float4(-xOffsetDiagonal, yOffsetDiagonal, 0, 0)).a;
float pixelTopRight = tex2Dlod(mainTexture, uvCenterWithLod + float4(xOffsetDiagonal, yOffsetDiagonal, 0, 0)).a;
float pixelBottomLeft = tex2Dlod(mainTexture, uvCenterWithLod + float4(-xOffsetDiagonal, -yOffsetDiagonal, 0, 0)).a;
float pixelBottomRight = tex2Dlod(mainTexture, uvCenterWithLod + float4(xOffsetDiagonal, -yOffsetDiagonal, 0, 0)).a;
float average = (pixelTop + pixelBottom + pixelLeft + pixelRight +
pixelTopLeft + pixelTopRight + pixelBottomLeft + pixelBottomRight)
* vertexColorAlpha / numSamples;
#else // 4 neighbourhood
float numSamples = 4;
float average = (pixelTop + pixelBottom + pixelLeft + pixelRight) * vertexColorAlpha / numSamples;
#endif
float thresholdStart = ThresholdEnd * (1.0 - OutlineSmoothness);
float outlineAlpha = saturate(saturate((average - thresholdStart) / (ThresholdEnd - thresholdStart)) - pixelCenter);
outlineAlpha = pixelCenter > OutlineOpaqueAlpha ? 0 : outlineAlpha;
return lerp(texColor, OutlineColor, outlineAlpha);
}
Harald Also please note that in this forum you can use triple-backticks ``` before and after a code-block for multi-line code.
Ty for letting me know this