Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Inx51 · Jan 18, 2017 at 03:54 PM · unity 5script.shadersmaterials

Send large array of world positions to Shader (or any other way of sending a large ammount of Vector3s to shader)

Hi! I have a large array of points/positions in world space (large as in it might scale up to a million in "depth") I need a way to transfer this data in some way to the shader for processing..

The basic idea is to let the shader messure the distance between the vertex and the provided world positions in the array and depending on the length of the distance color the material/shader.

So basically..

if(distance(v.vertex.xyz, largeArray[i].xyz) < 1.0f) { //Do stuff for coloring }

The issue is that I cant use the "normal" arrays for this.. since they have a max-depth of somewhere around 1100 (if Im not misstaken).. so I need an alternative way to do this.. any ideas?.. Also.. Im up for any other sulotions as well since I do realize that iterating over all the points might sort of kill the GPU.. so if you have any other suggestions then please feel free to share them.. I was sort of thinking if I could use a 3DTexture in someway maybe.. but couldn't really get my head around it..

Br, Inx

Comment
Add comment · Show 4
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 doublemax · Jan 18, 2017 at 03:58 PM 0
Share

Did you look into compute shaders yet?

https://docs.unity3d.com/560/Documentation/$$anonymous$$anual/ComputeShaders.html

avatar image Glurth · Jan 18, 2017 at 05:54 PM 0
Share

I would use a regular 2DTexture to provide this data.
Let the RGB vaule of the first pixel in the texture [0,0] define the x,y,z coordinates, of the first point you wish to check, Let the RGB vaule of the second pixel in the texture [1,0] define the x,y,z coordinates, of the second point you wish to check, etc...

Of course, these colors will all be normalized values (0.0 to 1.0), so you will probably need some multiplier value, from the material, to convert(scale) to world-space.

The edge size of this texture will need to be: the sqrt of the # of points to check.

I suspect there is plenty of stuff out there on how to create and assign this texture to the material, and how to access it inside the shader.

Alas, no idea's to help performance of that.

edit: not familiar with compute-shaders myself, that may very well be the better way to go.

avatar image Rezar · May 03, 2017 at 03:23 PM 0
Share

Hi! Just wanted to ask if you came up with a solution, I'm having the EXACT same question for a while now :)

avatar image Rezar · May 03, 2017 at 03:47 PM 0
Share

Hi! Just wanted to ask if you came up with a solution, I'm having the EXACT same question for a while now :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by termway · May 04, 2017 at 04:18 PM

You should look at Compute Buffer and/or Compute Shaders.

The simplest way would be to use structured buffered but it's only DirectX11. Something like this :

 CGPROGRAM
 #pragma target 5.0
 #pragma vertex vert
 #pragma fragment frag
 
 uniform StructuredBuffer<float3> positions;
 uniform StructuredBuffer<float3> colors;
 
 struct VertexColor
 {
     float4 position : POSITION;
     float4 color: COLOR;
 };
 
 VertexColor vert(uint id : SV_VertexID)
 {
     VertexColor output;
     output.position = mul(UNITY_MATRIX_MVP, float4(positions[id], 1)); 
     output.color = float4(colors[id], 1);
     return output;
 }


In scripts :

 ComputeBuffer positionsBuffer = new ComputeBuffer(points[m].Size, sizeof(float) * 3, ComputeBufferType.Default);
 ComputeBuffer colorsBuffer = new ComputeBuffer(points[m].Size, sizeof(float) * 3, ComputeBufferType.Default);
 //...
 positionsBuffer.SetData(...);
 colorsBuffer.SetData(...);
 //
 material.SetBuffer("positions", positionsBuffer);
 material.SetBuffer("colors", colorsBuffer);


Comment
Add comment · 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

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

IClone character hair issue 2 Answers

Hello everyone, I would like to create a Geometry dash like triangle Transporter in unity. 0 Answers

Fresnel shader and mixed textures 0 Answers

Trees that I painted on terrain are really dark and also missing parts in it's hirearchy... 0 Answers

[Shooting shots Scripting] How to make the compiler know that I mean the empty quad by the Public Transform? 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