Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NoureddineH · Mar 27, 2018 at 01:15 PM · shaderbuildwebglsurface shadervertex shader

Vertex-fragment shader pass not working in WebGL build.

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

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!


EDIT: Ok. It turns out that this shader works flawlessly on WebGL 1.0 but won't on WebGL 2.0. So at least there's a workaround, but I still don't understand why it works. I am however still interested in a way to make it work on WebGL 2.0.

shader-webgl-problem.png (374.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

133 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I unpack normal / tangent / uv information in the vertex function in a surface shader? 1 Answer

WebGL URP Lit shader project settings graphics 0 Answers

Distribute terrain in zones 3 Answers

How to get pure black shadow on gradient shader 0 Answers

Shadow artifacts on vertex animation shader 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges