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 Jason_Knapp · Sep 22, 2016 at 07:03 PM · shadersdeferred rendering

Surface shader custom lighting model in deferred lighting

I have a custom lighting model that is working as expected in forward rendering. Following the documentation at https://docs.unity3d.com/Manual/SL-SurfaceShaderLighting.html I attempted to support deferred by adding a (...)_PrePass function. It did not appear to be working, so I scaled back to a basic example.

I am sure that I the project/camera is set to deferred because e.g. the frame debugger shows other objects using the standard shader drawing as you would expect in the RenderDeferred.x steps.

For example, following http://kylehalladay.com/blog/tutorial/2014/04/05/Writing-Shaders-For-Deferred-Lighting-Unity.html . That shader does not work either - it does not render anything.

Has anything changed in how this works? Here is the body of the example shader:

 Shader "Custom/DeferredDiffuse"
 {
     Properties
     {
         _MainTex("Base (RGB)", 2D) = "white" {}
     }
         SubShader
     {
         Tags{ "RenderType" = "Opaque" }
         LOD 200
 
         CGPROGRAM
 #pragma surface surf MyDiffuse
 
         sampler2D _MainTex;
 
     struct Input {
         float2 uv_MainTex;
     };
 
     void surf(Input IN, inout SurfaceOutput o) {
         half4 c = tex2D(_MainTex, IN.uv_MainTex);
         o.Albedo = c.rgb;
         o.Alpha = c.a;
     }
 
     float4 LightingMyDiffuse_PrePass(SurfaceOutput i, float4 light)
     {
         return float4(i.Albedo * light.rgb, 1.0);
     }
     ENDCG
     }
 }
Comment
Add comment · Show 3
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 Namey5 · Sep 22, 2016 at 10:07 PM 0
Share

Are you using Deferred or Pre Pass (Legacy Deferred)? Because these definitions would be for the latter. The shader should still be compatible in all 3 rendering paths.

avatar image Jason_Knapp Namey5 · Sep 23, 2016 at 12:34 PM 0
Share

@Namey5 Thanks for the comment. I was using deferred, when I switch to legacy deferred the object draws as expected.

avatar image Namey5 Jason_Knapp · Sep 24, 2016 at 09:05 AM 0
Share

Yeah, technically speaking the only shader compatible with full Deferred shading is the Standard shader. If you want to utilize elements of the G-Buffer but still use custom shaders, pre-pass (Deferred lighting) is the way to go.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Modify Gbuffer Layout / Add RenderTarget 2 Answers

Particle shaders not visible when using multiple cameras 0 Answers

Deferred Light Rendering: Prevent additional lighting passes on pixels in overlapping point lights 0 Answers

[Deferred Decals] Add simple specular channel to deffered decals 0 Answers

Is it possible to avoid writing to certain g-buffers? 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