Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5ed776a

Browse files
Create Standard Stipple Transparency.shader
1 parent 2d15f04 commit 5ed776a

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Standard shader with stipple transparency
2+
// by Alex Ocias - https://ocias.com
3+
// source: https://ocias.com/blog/unity-stipple-transparency-shader/
4+
// based on an article by Digital Rune: https://www.digitalrune.com/Blog/Post/1743/Screen-Door-Transparency
5+
6+
Shader "Ocias/Standard (Stipple Transparency)" {
7+
Properties {
8+
_Color ("Color", Color) = (1,1,1,1)
9+
_MainTex ("Albedo (RGB)", 2D) = "white" {}
10+
_Glossiness ("Smoothness", Range(0,1)) = 0.5
11+
_Metallic ("Metallic", Range(0,1)) = 0.0
12+
}
13+
SubShader {
14+
Tags { "RenderType"="Opaque" }
15+
LOD 100
16+
17+
CGPROGRAM
18+
// Physically based Standard lighting model, and enable shadows on all light types
19+
#pragma surface surf Standard fullforwardshadows
20+
21+
// Use shader model 3.0 target, to get nicer looking lighting
22+
#pragma target 3.0
23+
24+
sampler2D _MainTex;
25+
26+
struct Input {
27+
float2 uv_MainTex;
28+
float4 screenPos;
29+
};
30+
31+
half _Glossiness;
32+
half _Metallic;
33+
fixed4 _Color;
34+
35+
void surf (Input IN, inout SurfaceOutputStandard o) {
36+
// Albedo comes from a texture tinted by color
37+
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
38+
o.Albedo = c.rgb;
39+
// Metallic and smoothness come from slider variables
40+
o.Metallic = _Metallic;
41+
o.Smoothness = _Glossiness;
42+
43+
// Screen-door transparency: Discard pixel if below threshold.
44+
float4x4 thresholdMatrix =
45+
{ 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
46+
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
47+
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
48+
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
49+
};
50+
float4x4 _RowAccess = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
51+
float2 pos = IN.screenPos.xy / IN.screenPos.w;
52+
pos *= _ScreenParams.xy; // pixel position
53+
clip(c.a - thresholdMatrix[fmod(pos.x, 4)] * _RowAccess[fmod(pos.y, 4)]);
54+
}
55+
ENDCG
56+
}
57+
FallBack "Diffuse"
58+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /