Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 Voodoomedia · May 02, 2020 at 09:05 PM · shaderrendertextureuvscreenspaceuv coordinates

CustomRenderTexture ignores "ComputeScreenPos"

Hi everyone!

I wrote a pretty simple shader, it draws an ellipse based on given uv screen coordinates of the mouse position.
It works well in a material applied to a gameObject, the coordinates are updated via script following the input screen position and the ellipse is displayed in a right way.

Now the problem
I've created a CustomRenderTexture, applied a material with that shader and I've noticed that the ellipse is now distorted since the screen position computated by ComputeScreenPos(o.vertex) is now converted in texture's uv space.
So for example, the bottom of the screen coordinates (0,0)screen are converted to (0,0) local uv space [the ellipse in the left bottom of the texture], another example the center of the screen let say (540,960) are now (0.5,0.5) [the ellipse is now in the middle of the texture not of the screen!]

I would like to know if CustomRenderTexture can read screen space and how.

Let me know if you need more details
Thank you!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Egad_McDad · May 05, 2020 at 02:09 AM

Hey @Voodoomedia , the best way to accomplish what you are trying to do is to first calculate the clip space in the vertex shader and then pass that value to the fragment shader. Once there, you can divide the clipspace.x by your screen width and clipspace.y by your screen height.


The reason this works is because clip space will give you the position of where that fragment/pixel is on the screen. One thing to note is that clip space is different from platform to platform, so for a more robust calculation you should look into ComputeScreenPos() (its near the bottom of the page). I couldn't get that function working myself, but its there.

Comment
Add comment · Show 4 · 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 Voodoomedia · May 07, 2020 at 12:47 PM 0
Share

@Egad_$$anonymous$$cDad Thanks for the reply, I'm not sure to be able to do this.. but I'll try :)

avatar image Voodoomedia · May 07, 2020 at 12:54 PM 0
Share

I've put more information about my problem on this thread, in case you're able to address me to some solution! Thanks! https://forum.unity.com/threads/customrendertexture-ignores-computescreenpos.881785

avatar image Egad_McDad Voodoomedia · May 07, 2020 at 09:50 PM 0
Share

Hey, I popped into that thread, added my own thoughts on how I would do it

avatar image Voodoomedia Egad_McDad · May 08, 2020 at 10:10 AM 0
Share

Thanks I've replied on the thread!

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

195 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

Related Questions

Custom Render Texture, globalTexcoord not on range 0 to 1? 0 Answers

Creating a shader with "local" screenspace uv? 0 Answers

How can I convert the texture coordinates of the multi-spite to 0-1? 0 Answers

How do I get mesh data into post-processing shader (or render a mesh shader to a texture)? 0 Answers

How to scale and offset UV coordinates from the center of the texture? 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