I’m working on an editor based script to generate prerendered textures, but this question should apply to runtime textures too. I’m currently iterating thru each pixel and doing a chain of operations on a list of floats, then applying them to a texture. Its working, but its slower than I think it should be. I was wondering if there is some way to make it go faster, like using a better datatype or somehow getting the gpu to do some of the work.
Here’s a greatly simplified version of what I’m doing:
void makeTextureForSave(int size){
texture = new Texture2D(size, size);
for(x = 0; x< size; x++){
for(int y = 0; y< size; y++){
float[] noise = getValue(new Vector3(x, y, 0));
Color color = new Color(noise[0],noise[1], noise[2]);
texture.SetPixel(x, y, color);
}
}
texture.Apply();
}
float[] getValue(Vector3 pos){
//greatly simplified
return color(getColorInput(),invert(screenBlend(perlinNoise(), voronoiNoise()));
}
float[] color(float[] in1, float[]in2){
//example
for(i=0; i<4; i++) output <em>= in1_*in2*;*_</em>
return output;
}
Can this be done faster?