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 $$anonymous$$ · Oct 26, 2020 at 05:31 PM · renderinganti-aliasingshadowmapantialiasinganti aliasing

Encoding geometry information for Sub-Pixel Shadow Mapping

I'm trying to implement the SPSM approach described in this paper: http://jmarvie.free.fr/Publis/2014_I3D/i3d_2014_SubPixelShadowMapping.pdf

First, why am I trying to do this: I am currently using a shadow map, rendered from the view point of a character to display their view cone on the ground. Using regular shadow mapping works fine so far, but produces jagged edges, mainly where obstacles obstruct the view. I hope SPSM might provide better results.

I'm running into problems while doing step 3.3, the encoding of triangle information in the shadow map. There are two distinct problems.

  1. Getting all the information needed into the fragment shader for writing into a render texture.

  2. Encoding the data into a suitable 128bits-RGBA format.


Regarding 1: I need the following data for the SPSM:

  • All three triangle vertices of the closest occluding triangle

  • Depth value at texel center

  • Depth derivatives

I tried getting the triangle information from the geometry shader while calculating the other two in the fragment shader. My first naive approach looks like this:

 struct appdata
 {
     float4 vertex : POSITION;
 };
 
 struct v2g
 {
     float4 pos : POSITION;
     float3 viewPos : NORMAL;
 };
 
 struct g2f
  {
     float4 vertex : SV_POSITION;
     float4 v0 : TEXCOORD1;
     float4 v1 : TEXCOORD2;
     float4 v2 : TEXCOORD3;
  };
 
 v2g vert(appdata v)
 {
     v2g o;
     UNITY_INITIALIZE_OUTPUT(v2g, o);
     o.pos = UnityObjectToClipPos(v.vertex);
     return o;
 }
 
 [maxvertexcount(3)]
 void geom(triangle v2g input[3], inout TriangleStream<g2f> outStream)
 {
     g2f o;
 
     float4 vert0 = input[0].pos; 
     float4 vert1 = input[1].pos; 
     float4 vert2 = input[2].pos; 
 
     o.vertex = vert0;
     o.v0 = vert0;
     o.v1 = vert1;
     o.v2 = vert2;
     outStream.Append(o);
 
     o.vertex = vert1;
     o.v0 = vert0;
     o.v1 = vert1;
     o.v2 = vert2;
     outStream.Append(o);
 
     o.vertex = vert2;
     o.v0 = vert0;
     o.v1 = vert1;
     o.v2 = vert2;
     outStream.Append(o);
 }
 
 float4 frag(g2f i) : SV_TARGET
 {
     float4 col;
 
     half depth = i.vertex.z;
     half dx = ddx(i.vertex.z);
     half dy = ddy(i.vertex.z);
 
     float r1 = i.v0.x; // _ScreenParams.x; <– this ranges from aroung -5 to 5
     float g1 = i.v0.y; // _ScreenParams.y;
 
     float r2 = i.vertex.x // _ScreenParams.x; <– this ranges from 0 to 1920
     float g2 = i.vertex.y // _ScreenParams.y;
 
     col = float4(r2, g2, 0, 1);
 
     return col;
 }

I'm currently rendering the interpolated vertex position as the fragment color for debugging. When rendering it like this I get the following output:

alt text

If I render the non-interpolated position of the "first" vertex of each triangle I get the following:

alt text

It looks correct so far. What confuses me, is that i.vertex.x has values ranging from 0 to screen width (e.g. 1920) and i.v0.x has value ranging from around -5 to +5. Shouldn't both be at least roughly the same (I know one is interpolated while the other is not) since they are both transformed from object to clip space? Or is the SV_POSITION semantic working some magic behind the scenes?

Regarding 2: My second problem is the actual encoding of the values into a 128bits-RGBA format. The paper describes the encoding very briefly on page 3. Is there a way to pack two half into one float? Or a clever way to bring those values in the range of [0, 1) so I can use Unity's encoding? What about the two derivatives (8bit values)?

Alternatively, I'm very glad for any advice on how to improve the "shadow quality" for the view cone rendering in a different way, apart from using a higher resolution or more shadow maps.

screenshot-2020-10-26-180502.png (36.1 kB)
screenshot-2020-10-26-180825.png (28.6 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

158 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

Related Questions

How do I get antialiasing with the Lightweight Render Pipeline (LWRP)? 1 Answer

RenderTexture Antialiasing not working 0 Answers

Heavy flickering 2D mesh in medium and high distances 0 Answers

Is it possible to get the subsample buffers used in MSAA from Unity? 0 Answers

anti-aliasing settings 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