Hello!
I'm currently working on a shader intended to combine two effects, each accomplished through a distinct pass:
- **1st pass:** screen-space effect clipping pixels to form diagonal lines when the object is hidden by opaque elements (vertex and fragment shader).
- **2nd pass:** holographic emission with alpha blending and a scrolling texture used for emission (surface shader).
![alt text][1]
The shader is working fine in the editor. However, I'm **not getting the intended effect in the WebGL build** (see above image, in which I reproduced in the editor what I observe in the webgl build). **Each effect works fine on their own, but combining them in one shader breaks the hash effect.**
I guess I could assign two materials to the object with the two shaders, but I would rather not since I believe it could affect performance but most of all it keeps me from sharing values between the two effects such as the tint of the holographic effect.
----------
I tried :
- Reordering the two passes.
- Changing the quality and graphics settings (from best looking to worst looking).
- Various syntaxic tweaks that I can barely remember at this point, being quite new to shaders.
----------
Here's my code:
Shader "Custom/HoloObject" {
Properties{
_Color("Color", Color) = (1,1,1,1)
_HoloColor("Holo Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_Scanlines("Scanlines", 2D) = "black" {}
_ScanSpeed("Scan Speed", Range(0,1)) = 0.25
_LinesDensity("Lines Density", Range(0,30)) = 4
_RimPower("Rim Power", Range(0,8)) = 4
[MaterialToggle]
_Transparent("Transparent", float) = 1
[MaterialToggle]
_SeeThrough("See through", float) = 1
_SeeThroughPower ("See through power", Range(1,6)) = 3
[MaterialToggle]
_HoloActive("Holo Active", float) = 1
}
SubShader{
Tags{ "RenderType" = "Fade" "Queue" = "Transparent" "IgnoreProjector" = "True" }
// ------------- HASH EFFECT -------------
Pass
{
Name "Hash"
ZTest Greater
Lighting Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
struct v2f {
float2 uv : TEXCOORD0;
};
v2f vert(
float4 vertex : POSITION,
float2 uv : TEXCOORD0,
out float4 outpos : SV_POSITION
)
{
v2f o;
o.uv = uv;
outpos = UnityObjectToClipPos(vertex);
return o;
}
sampler2D _MainTex;
fixed4 _HoloColor;
float _SeeThrough;
float _SeeThroughPower;
fixed4 frag(v2f i, UNITY_VPOS_TYPE screenPos : VPOS) : SV_Target
{
fixed4 c;
UNITY_INITIALIZE_OUTPUT(fixed4, c);
if (_SeeThrough) {
screenPos.xy = floor(screenPos.xy) * 0.75;
float checker = -frac(screenPos.r + screenPos.g);
clip(checker);
c = _HoloColor;
c *= _SeeThroughPower;
return c;
}
else {
clip(-1.);
return c;
}
}
ENDCG
}
// ------------- HOLOGRAPHIC EFFECT -------------
LOD 200
ZTest Less
Cull Back
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard nodynlightmap nodirlightmap noshadow alpha:fade
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
struct Input {
float2 uv_MainTex;
float2 uv_Scanlines;
float3 worldPos;
float3 viewDir;
};
sampler2D _MainTex;
sampler2D _Scanlines;
half _Glossiness;
half _Metallic;
fixed4 _Color;
fixed4 _HoloColor;
float _ScanSpeed;
float _RimPower;
float _Transparent;
float _HoloActive;
float _LinesDensity;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
void surf(Input IN, inout SurfaceOutputStandard o) {
fixed4 c;
c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = (_Transparent ? c.a : 1);
if (_HoloActive) {
half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
o.Emission = tex2D(_Scanlines, (IN.worldPos - _Time.x * _ScanSpeed) * _LinesDensity).a * _HoloColor * _HoloColor.a * rim * _RimPower;
}
}
ENDCG
}
FallBack "Diffuse"
}
**Thank you very much for your help!**
[1]: /storage/temp/113805-shader-webgl-problem.png
↧