- Home /
Can you use a texture atlas as a colorpicker?
I would like to use a multicolor texture like a colorpicker to set each object to a different color, by zooming and offsetting the texture to use a pixel of a different color for each object texture.
When i write:
cube.renderer.sharedMaterial.SetTextureScale ("_MainTex", Vector2(.001,.001)); cube.renderer.sharedMaterial.SetTextureOffset ("_MainTex", Vector2(seed*.43243,seed*.87547));
the set scale op batches ok and the set offset op breaks the batch process.
What do you mean with "breaks the batch process"? I probably would not do it with a texture; you're limiting yourself to the colors you have on the texture and you will have to use point filtering. Wouldn't a shader with configurable color or vertex colors be a more obvious choice?
Oh $$anonymous$$adDave, please Explain! i have made configurable multicolor shaders. Please explain how to use a different color for different intantiations of a mesh?
Save, Yes sorry i changed the lines alot of times, the second line makes the cubes always the same color, whereas writing it with .material. ins$$anonymous$$d of .shared$$anonymous$$aterial. its multicolors.
$$anonymous$$adDave, by breaking the batch process, i mean that if you add a line that does SetTextureOffset, the prefabs will all call seperate materials and not be batched any more. i tried mainTextureOffset, which can be used in shared$$anonymous$$aterial but can't change the texture offset of different instances. It seems there is now way to edit colors of batched models with a diffuse shader and with direct texture commands, it may be possible to shift the model's UV's when instantiated, and perhaps there is a GetPixel way??? and perhaps a VertexLit way also! try to color sharedmaterial and diffuse = no batching works.
Answer by MadDave · Sep 07, 2012 at 10:15 AM
Ok, I think I got you. If you need to render all cubes in just one draw (i.e. batched) the only option I see is giving each cube different geometry. You could use different UVs and a texture or different vertex colors. Texture offset is ultimately a shader parameter and different shader parameters per cube require separate draw calls. In real life (i.e. DirectX/OpenGL programming without Unity) you would use instancing (rendering with multiple vertex streams) to achieve something like that. But AFAIK you cannot make that happen with unity.
Your answer
Follow this Question
Related Questions
batch textures, shared materials, instantiation, sharedmaterial array 1 Answer
Creating Batch file to run unity with commands 1 Answer
How to Undo SharedMaterial set in CustomEditor? 1 Answer
Spout: shared texture breaks model UVs 0 Answers
Why would my texture split across the triangle at runtime? 0 Answers