void Start() { for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { Ray currentRay = Camera.main.ViewportPointToRay(new Vector3((float)i / width, (float)j / height, Camera.main.nearClipPlane)); RaycastHit hitInfo; bool didHit = Physics.Raycast(currentRay, out hitInfo); if (didHit) { ShaderScript currentShader = hitInfo.transform.GetComponent <ShaderScript>(); canvas.SetPixel(i, j, currentShader.calcColor(hitInfo, 0)); } else { canvas.SetPixel(i, j, Color.black); } } } canvas.Apply(); }
// Use this for initialization void Start() { //iterate through pixels for (int i = 0; i < width; ++i) { for (int j = 0; j < height; ++j) { Ray currentPixelRay = Camera.main.ViewportPointToRay( new Vector3((float)i / width, (float)j / height, Camera.main.nearClipPlane)); RaycastHit hitInfo; bool hit = Physics.Raycast(currentPixelRay, out hitInfo); if (hit) { ShaderScript shader = hitInfo.transform.GetComponent <ShaderScript>(); if (shader != null) { tex.SetPixel(i, j, shader.calcColor(hitInfo)); } else { tex.SetPixel(i, j, Color.cyan); } } } } tex.Apply(); }