Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Sospitas · Jul 14, 2014 at 01:51 PM · c#raycastingtexturesrendertexture

Render Textures and Raycasting

Hi guys,

I have a few questions regarding Render Textures and Ray Casting which are causing some problems within my game.

1 - Firstly, is there any way to hot-swap out the texture to which a camera is rendering? Currently my game has pretty low FPS on mobile devices (sometimes getting sub-20 FPS) which is obviously not good for the game. I am trying to stop the game from updating the RenderTexture until something has actually changed if this isn't already done. My game does not have a lot of objects within the scene at present, and the profiler is saying that Camera.render for RenderForwardOpaque is taking up about 80-90% of the CPU.

2 - My second question is to do with Ray casting, Render Textures and scrolling UVs. I am currently ray casting at the object to which my RenderTexture is being applied. Using RaycastHit.textureCoord, I am then performing another ray cast from my RenderTexture camera using the textureCoord and ViewportPointToRay so that I can get the corresponding object to where the "touch" event happened.

This is all working fine until I get towards the edges of my objects/texture area. The problem is arising because I am scrolling the UVs and incrementing a uvOffset value. This incrementing of the offset value is causing my ray cast direction to move as the texture scrolls, but when the texture scrolls past a certain point the ray cast is no longer hitting an object and thus returning null which is causing problems for the gameplay. Basically, what I need is a way in which I can "fix" the offset programmatically so that my ray casts are no longer missing my objects.

I am sorry if this is a bit rambly. I just typed all of this out initially and then my Macbook decided to drop from the internet as I hit submit, causing me to lose it all :(

If you need any more explanation as to what the problems are, please ask and I will try to create some (badly drawn) diagrams for you.

Any help you can give regarding this would be greatly appreciated!

Thanks, Sospitas

Comment
Add comment · Show 5
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 Sospitas · Jul 14, 2014 at 02:30 PM 0
Share

Turns out I fixed one of my own problems. The uv scrolling was as simple as just setting it back to 0.5f if it went below -0.5f. It was showing a visible "jump" when I tried it earlier, so I must have been overcomplicating my code somehow.

I still have the performance issue though, so any help with that will still be appreciated! :)

avatar image AndyMartin458 · Jul 14, 2014 at 05:11 PM 0
Share

Try to isolate what the render texture camera needs to see vs. the main camera. Do this by turning off some layers for the render camera and also reduce its field of view.

avatar image Sospitas · Jul 14, 2014 at 07:18 PM 0
Share

I have positioned the camera so that all that it can see is the objects that it is rendering to a texture (The edges of the camera preview are lined up with the exact edges of the objects. I used an editor extension to maximize the camera preview to allow me to line this up better).

There is nothing else in the scene apart from the objects that the RenderTexture is aligned with, the sphere on which the RenderTexture is applied, a point light, a directional light and the 2 cameras.

avatar image rutter · Jul 14, 2014 at 07:28 PM 1
Share

Any chance you can batch some more draw calls? Atlased textures and static batching can save a lot of performance trouble on mobile. Culling may help, too, but it sounds like your frustum cull should handle most of that.

I haven't tried it, but what happens if you disable the camera that's generating the RenderTexture? You might try enabling it only when you need the texture updated.

avatar image Sospitas · Jul 14, 2014 at 08:11 PM 0
Share

Okay, I just tried to disable the render texture camera, and it left the texture visible on the sphere. I'm pretty sure I've tried that before and the sphere went black, maybe I did something else?

Anyways, thank you :) I'll give this some testing, but I'm not sure how much of a performance boost I'll get. The texture needs to scroll a considerable amount during the gameplay

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

24 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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Mouse Aim for a 2.5D game 1 Answer

modify textures at runtime? 3 Answers

An OS design issue: File types associated with their appropriate programs 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