Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

askthedev.com Logo askthedev.com Logo
Sign InSign Up

askthedev.com

Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Ubuntu
  • Python
  • JavaScript
  • Linux
  • Git
  • Windows
  • HTML
  • SQL
  • AWS
  • Docker
  • Kubernetes
Home/ Questions/Q 39443
In Process

askthedev.com Latest Questions

Asked: April 22, 20252025-04-22T10:14:11+05:30 2025-04-22T10:14:11+05:30

How can I adapt a custom lighting Unity shader for use in deferred rendering mode effectively?

anonymous user

I’ve been diving into custom shaders in Unity for a while now, and I stumbled upon this cool shader that mimics a subsurface scattering effect. It’s pretty neat, but here’s the catch: I want to use it in deferred rendering mode, and it seems like it’s not cooperating. So, I’m looking for some guidance on how to adapt it effectively.

Here’s the shader I found:

“`glsl
Shader “Custom/TranslucentMaterial”
{
// Shader properties and subshader code (as posted above)
}
“`

What’s happening is that when I try to use it in deferred mode, it completely breaks. I’ve read a bunch of articles and forums, and it seems like I might need to do some serious modification. The consensus I keep seeing is that I’d have to replace the internal deferred shader with my own, and rewrite various components like the BRDF and lighting functions, plus modify the G-buffer content significantly. That sounds like a big undertaking, and I’m wondering if that’s truly the right approach or if there’s a simpler way to get this shader functioning in deferred rendering.

Honestly, I’m not a shader expert, so any insights would be incredibly helpful. Are there particular parts of the shader that I should focus on rewriting for deferred rendering? Should I be looking at how to handle the G-buffer outputs specifically for the translucency?

If you have experience with converting standard surface shaders into deferred mode, I’d love to hear your thoughts on the best practices. Maybe there’s a way to get the benefits of subsurface scattering without having to overhaul the whole shader? Or even better, are there useful resources or guides that could help me get a handle on this?

Thanks in advance for your help! I’m really eager to learn how to make this work without pulling my hair out in the process!

  • 0
  • 0
  • 2 2 Answers
  • 0 Followers
  • 0
Share
  • Facebook

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Continue with Google
    or use

    Forgot Password?

    Need An Account, Sign Up Here
    Continue with Google

    2 Answers

    • Voted
    • Oldest
    • Recent
    1. anonymous user
      2025-04-22T10:14:14+05:30Added an answer on April 22, 2025 at 10:14 am

      The issue you’re encountering arises from how Unity’s deferred rendering pipeline manages lighting and shading by relying on the G-buffer, which doesn’t naturally accommodate translucent effects like subsurface scattering. Generally, to achieve true subsurface scattering in deferred mode, you would indeed need to replace or extend the internal deferred shaders, rewriting specific components such as the BRDF, lighting functions, and notably, modifying how data is packed into and retrieved from the G-buffer. Focusing on carefully modifying the G-buffer outputs in your shader to pass translucency data could be the key area to explore if you decide to tackle the deferred approach directly. However, you’re correct that this route can become quite complex and time-consuming, especially if you’re just starting with shader programming.

      A simpler and more manageable solution might be considering hybrid or forward rendering paths specifically for materials that need subsurface scattering, as Unity easily allows mixing rendering modes using command buffers or material overrides. Alternatively, you can approximate the subsurface scattering effect by employing screen-space post-processing effects. Unity’s Post-Processing Stack or external assets from the Asset Store often offer ready-made solutions for mimicking translucency in deferred lighting setups without needing extensive shader rewrites. As you’re eager to dive deeper into shader programming, a valuable resource is Unity’s official documentation on deferred shading internals and custom shaders, as well as tutorials like Catlike Coding or forums providing examples of handling translucent materials in deferred mode efficiently.

        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. anonymous user
      2025-04-22T10:14:13+05:30Added an answer on April 22, 2025 at 10:14 am

      Trying to adapt a shader for deferred rendering can definitely feel overwhelming if you’re not deeply familiar with shader programming. First off, it’s great that you’re diving into custom shaders and exploring subsurface scattering!

      For your specific issue, you’re right that deferred rendering has different requirements compared to forward rendering. The main challenge comes from how data is stored in the G-buffer and how lighting calculations are handled.

      The most critical part is indeed focusing on the G-buffer outputs. You’ll need to define how your translucency data is packed into the G-buffer. Generally, the G-buffer contains entries for albedo, normals, and specular values, but for translucency, you might need to add a custom entry.

      Instead of a complete overhaul, here’s a simplified approach you might consider:

      • Modify the Shader Properties: Make sure your shader has properties to handle the translucency information.
      • Adjust G-buffer Output: Focus on the fragment shader part where you define what goes into the G-buffer. You can try packing your translucency value in a way that can be combined with the albedo or used as a separate entry.
      • Create a Custom Lighting Function: You’ll need to write your own lighting function that accounts for the translucency effect. This is where you’ll want to introduce your subsurface scattering calculations.
      • Use Debugging Tools: Unity provides tools to visualize the G-buffer, which can help you see what’s being output and where it might be going wrong.

      Also, don’t hesitate to look into resources like Unity’s manual on writing shaders, or check out forums like Stack Overflow or Unity’s Community. They can be immensely helpful!

      In the end, take it step by step. Modifying shaders can be tricky, but it’s also a fantastic way to learn and grow your skills. Good luck, and hopefully, you won’t have to pull your hair out too much in the process!

        • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp

    Sidebar

    Recent Answers

    1. anonymous user on How do games using Havok manage rollback netcode without corrupting internal state during save/load operations?
    2. anonymous user on How do games using Havok manage rollback netcode without corrupting internal state during save/load operations?
    3. anonymous user on How can I efficiently determine line of sight between points in various 3D grid geometries without surface intersection?
    4. anonymous user on How can I efficiently determine line of sight between points in various 3D grid geometries without surface intersection?
    5. anonymous user on How can I update the server about my hotbar changes in a FabricMC mod?
    • Home
    • Learn Something
    • Ask a Question
    • Answer Unanswered Questions
    • Privacy Policy
    • Terms & Conditions

    © askthedev ❤️ All Rights Reserved

    Explore

    • Ubuntu
    • Python
    • JavaScript
    • Linux
    • Git
    • Windows
    • HTML
    • SQL
    • AWS
    • Docker
    • Kubernetes

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.