Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 MayMOL · May 17 at 01:36 PM · shadershader programmingshader-replacement

Get shadowmap in HDRP with commandBuffer

The code I've been working on for ages has this line of code

cmd.DrawRenderer(rc.renderer, srcMaterial, rc.submeshIndex, shadowPass);

which it takes the material's shadowpass and put the result into a RenderTexture.

However, the ShadowCaster pass in URP is simple that only have one half type output

 half4 ShadowPassFragment(Varyings input) : SV_TARGET
 {
     Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
     return 0;
 }

And here's the HDRP Lit code for shadow:

 void Frag(  PackedVaryingsToPS packedInput
             #if defined(SCENESELECTIONPASS) || defined(SCENEPICKINGPASS)
             , out float4 outColor : SV_Target0
             #else
                 #ifdef WRITE_MSAA_DEPTH
                 // We need the depth color as SV_Target0 for alpha to coverage
                 , out float4 depthColor : SV_Target0
                     #ifdef WRITE_NORMAL_BUFFER
                     , out float4 outNormalBuffer : SV_Target1
                     #endif
                 #else
                     #ifdef WRITE_NORMAL_BUFFER
                     , out float4 outNormalBuffer : SV_Target0
                     #endif
                 #endif
 
                 // Decal buffer must be last as it is bind but we can optionally write into it (based on _DISABLE_DECALS)
                 #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)
                 , out float4 outDecalBuffer : SV_TARGET_DECAL
                 #endif
             #endif
 
             #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS)
             , out float outputDepth : DEPTH_OFFSET_SEMANTIC
             #endif
         )
 {
     UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(packedInput);
     FragInputs input = UnpackVaryingsToFragInputs(packedInput);
 
     // input.positionSS is SV_Position
     PositionInputs posInput = GetPositionInput(input.positionSS.xy, _ScreenSize.zw, input.positionSS.z, input.positionSS.w, input.positionRWS);
 
 #ifdef VARYINGS_NEED_POSITION_WS
     float3 V = GetWorldSpaceNormalizeViewDir(input.positionRWS);
 #else
     // Unused
     float3 V = float3(1.0, 1.0, 1.0); // Avoid the division by 0
 #endif
 
     SurfaceData surfaceData;
     BuiltinData builtinData;
     GetSurfaceAndBuiltinData(input, V, posInput, surfaceData, builtinData);
 
 #if defined(_DEPTHOFFSET_ON) && !defined(SCENEPICKINGPASS)
     outputDepth = posInput.deviceDepth;
 
 
 #if SHADERPASS == SHADERPASS_SHADOWS
     // If we are using the depth offset and manually outputting depth, the slope-scale depth bias is not properly applied
     // we need to manually apply.
     float bias = max(abs(ddx(posInput.deviceDepth)), abs(ddy(posInput.deviceDepth))) * _SlopeScaleDepthBias;
     outputDepth += bias;
 #endif
 
 #endif
 
 #ifdef SCENESELECTIONPASS
     // We use depth prepass for scene selection in the editor, this code allow to output the outline correctly
     outColor = float4(_ObjectId, _PassValue, 1.0, 1.0);
 #elif defined(SCENEPICKINGPASS)
     outColor = _SelectionID;
 #else
 
     // Depth and Alpha to coverage
     #ifdef WRITE_MSAA_DEPTH
         // In case we are rendering in MSAA, reading the an MSAA depth buffer is way too expensive. To avoid that, we export the depth to a color buffer
         depthColor = packedInput.vmesh.positionCS.z;
 
         #ifdef _ALPHATOMASK_ON
         // Alpha channel is used for alpha to coverage
         depthColor.a = SharpenAlpha(builtinData.opacity, builtinData.alphaClipTreshold);
         #endif
     #endif
 
     #if defined(WRITE_NORMAL_BUFFER)
     EncodeIntoNormalBuffer(ConvertSurfaceDataToNormalData(surfaceData), outNormalBuffer);
     #endif
 
     #if defined(WRITE_DECAL_BUFFER) && !defined(_DISABLE_DECALS)
     DecalPrepassData decalPrepassData;
     // We don't have the right to access SurfaceData in a shaderpass.
     // However it would be painful to have to add a function like ConvertSurfaceDataToDecalPrepassData() to every Material to return geomNormalWS anyway
     // Here we will put the constrain that any Material requiring to support Decal, will need to have geomNormalWS as member of surfaceData (and we already require normalWS anyway)
     decalPrepassData.geomNormalWS = surfaceData.geomNormalWS;
     decalPrepassData.decalLayerMask = GetMeshRenderingDecalLayer();
     EncodeIntoDecalPrepassBuffer(decalPrepassData, outDecalBuffer);
     #endif
 
 #endif // SCENESELECTIONPASS
 }

Can anybody please tell me which one in HDRP is equivalent to the URP version, and how am I going to get the same shadowmap for the command buffer as URP?

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

213 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 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

I'am new to shaders and I'am making games for mobile devices should I switch over to LWRP? 0 Answers

Fog of War overlay for overhead map. 1 Answer

How can i combine shaders? 0 Answers

shadertoy to unity,Shadertoy to unity 0 Answers

For a glass shader: How to "Fallback" completely 100% transparent that works in all device or that it do not render at all? 0 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