Skip to content

Commit 00e1644

Browse files
Added texture input to StencilWriter
1 parent 4e704d7 commit 00e1644

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

Assets/Shaders/StencilTarget.shader

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,42 +37,37 @@ Shader "Mabel/Stencils/Stencil Target"
3737
float4 vertex : POSITION;
3838
float2 uv : TEXCOORD0;
3939

40-
UNITY_VERTEX_INPUT_INSTANCE_ID // For instance ID support
40+
UNITY_VERTEX_INPUT_INSTANCE_ID
4141
};
4242

4343
struct v2f
4444
{
4545
float2 uv : TEXCOORD0;
4646
float4 vertex : SV_POSITION;
4747

48-
UNITY_VERTEX_OUTPUT_STEREO // For stereo rendering support
48+
UNITY_VERTEX_OUTPUT_STEREO
4949
};
5050

5151
sampler2D _MainTex;
5252
float4 _BaseColor;
5353

54-
// Vertex shader
5554
v2f vert(appdata v)
5655
{
5756
v2f o;
5857

59-
// Handle instancing
6058
UNITY_SETUP_INSTANCE_ID(v);
6159
UNITY_INITIALIZE_OUTPUT(v2f, o);
6260
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
6361

64-
// Apply the correct transformation for stereo rendering
6562
o.vertex = UnityObjectToClipPos(v.vertex);
6663

6764
o.uv = v.uv;
6865

6966
return o;
7067
}
7168

72-
// Fragment shader
7369
float4 frag(v2f i) : SV_Target
7470
{
75-
// Sample texture and apply color
7671
float4 texColor = tex2D(_MainTex, i.uv);
7772
return texColor * _BaseColor;
7873
}
@@ -82,4 +77,4 @@ Shader "Mabel/Stencils/Stencil Target"
8277
}
8378

8479
FallBack Off
85-
}
80+
}

Assets/Shaders/StencilWriter.shader

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ Shader "Mabel/Stencils/Stencil Writer"
33
Properties
44
{
55
_Color ("Color", Color) = (1,1,1,1)
6-
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
6+
_Background ("Texture", 2D) = "white" {}
7+
[PerRendererData] [HideInInspector] _MainTex ("Sprite Texture", 2D) = "white" {}
78
}
9+
810
SubShader
911
{
1012
Tags { "Queue"="Overlay" "RenderType"="Transparent" }
@@ -30,34 +32,33 @@ Shader "Mabel/Stencils/Stencil Writer"
3032

3133
sampler2D _MainTex;
3234
fixed4 _Color;
35+
sampler2D _Background;
3336
float4 _MainTex_ST;
3437

3538
struct appdata
3639
{
3740
float4 vertex : POSITION;
3841
float2 uv : TEXCOORD0;
3942

40-
UNITY_VERTEX_INPUT_INSTANCE_ID // Support for instancing
43+
UNITY_VERTEX_INPUT_INSTANCE_ID
4144
};
4245

4346
struct v2f
4447
{
4548
float2 uv : TEXCOORD0;
4649
float4 pos : SV_POSITION;
4750

48-
UNITY_VERTEX_OUTPUT_STEREO // Ensure stereo support
51+
UNITY_VERTEX_OUTPUT_STEREO
4952
};
5053

5154
v2f vert(appdata v)
5255
{
5356
v2f o;
5457

55-
// Setup instance data if required
5658
UNITY_SETUP_INSTANCE_ID(v);
5759
UNITY_INITIALIZE_OUTPUT(v2f, o);
5860
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
5961

60-
// Apply transformation for stereo rendering
6162
o.pos = UnityObjectToClipPos(v.vertex);
6263

6364
o.uv = TRANSFORM_TEX(v.uv, _MainTex);
@@ -67,7 +68,9 @@ Shader "Mabel/Stencils/Stencil Writer"
6768

6869
fixed4 frag(v2f i) : SV_Target
6970
{
70-
return tex2D(_MainTex, i.uv) * _Color;
71+
fixed4 bg = tex2D(_Background, i.uv);
72+
fixed4 background = bg * _Color;
73+
return tex2D(_MainTex, i.uv) * background;
7174
}
7275

7376
ENDHLSL

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v1.11.1
2+
## Changed Shaders
3+
### Stencil Writer
4+
* Added texture input
5+
16
# v1.11.0
27
## Added Shaders
38
### Stencil Writer

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.fragiledeviations.mabelsshaders",
3-
"version": "1.11.0",
3+
"version": "1.11.1",
44
"displayName": "Mabel's Shaders",
55
"description": "Various shaders for SLZ URP",
66
"unity": "2021.3",

0 commit comments

Comments
 (0)