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 klabauterklaus · Jul 27, 2011 at 07:56 PM · shaderrendervertexdeferreddisplacement

Vertex Displacement in Forward Rendering Shader

I'm trying to implement a gras rendering shader with moving blades in Unity 3. Everything works fine, except when i turn on shadows and deferred rendering. The shader must be forward rendering (it needs a custom lighting function).

The problem apparently is that it renders "invisible holes" in the form of the gras texture during deferred rendering, but it doesn't pick up the vertex displacement, so the result looks wrong (see picture below).

Here is the shader code:

Shader "Gras" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 } SubShader { Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} LOD 200 Cull Off CGPROGRAM #pragma surface surf SoftLight alphatest:_Cutoff vertex:vert exclude_path:prepass addshadow

half4 LightingSoftLight (SurfaceOutput s, half3 lightDir, half atten) { half NdotL = 0.35 abs(dot (s.Normal, lightDir)) + 0.35 lightDir.y; half4 c; c.rgb = s.Albedo _LightColor0.rgb (NdotL atten 2); c.a = s.Alpha; return c; }

sampler2D _MainTex; fixed4 _Color; uniform float _Wind; uniform float _WindStrength; uniform float _WindDX; uniform float _WindDY;

struct Input { float2 uv_MainTex; float4 color : COLOR; };

void vert (inout appdata_full v) { float ww = (0.25 - abs(sin(_Wind + v.texcoord1.y)) 0.25) _WindStrength v.texcoord1.x; v.vertex += float4(ww _WindDX, -ww 0.5, ww _WindDY, 0);
v.normal += float4(ww _WindDX, -ww 0.5, ww * _WindDY, 0);
}

void surf (Input IN, inout SurfaceOutput o) { fixed4 c = tex2D(_MainTex, IN.uv_MainTex) _Color; o.Albedo = c.rgb IN.color * 1.5; o.Alpha = c.a; } ENDCG }

Fallback "Transparent/Cutout/VertexLit" } alt text

Is there any way to make the deferred renderer pick up the vertex displacement or is this a bug?

Edit: Tried out some more and found out that the problem only arises when "Receive Shadows" is on - "Cast Shadows" makes no problems.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by cician · Feb 10, 2013 at 12:50 AM

It's the same in Unity 4.0. To reproduce:

  1. enable deferred rendering in player settings

  2. create a shader with vertex displacement and only forward lighting function, or add exclude_path:prepass

  3. apply the shader to a mesh with receive shadows enabled

Voilà.

alt text


forward_disp_bug.png (269.3 kB)
Comment
Add comment · Share
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
avatar image
0

Answer by Emptiness · May 01, 2013 at 10:17 AM

Hi!

Maybe this helps somebody.

Comment
Add comment · Share
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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Vertex Displacement Shader Problems 1 Answer

Unity shader vertex displace doesn't work 0 Answers

How do I alter vertex displacement based on UV coordinates? 0 Answers

Is it possible to get back data for a specific vertex from a shader ? 0 Answers

Vertex colour transparency and Beast lightmapping? 3 Answers


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