docstr: Test a mesh with vertex textures can be extended to form a batch, and
  is rendered correctly with Phong, Gouraud and Flat Shaders with batched
  lighting and hard and soft blending.
docstr_tok: ["Test","a","mesh","with","vertex","textures","can","be","extended","to","form","a","batch",",","and","is","rendered","correctly","with","Phong",",","Gouraud","and","Flat","Shaders","with","batched","lighting","and","hard","and","soft","blending","."]
code: def test_simple_sphere_batched(self):
      """
      Test a mesh with vertex textures can be extended to form a batch, and
      is rendered correctly with Phong, Gouraud and Flat Shaders with batched
      lighting and hard and soft blending.
      """
      batch_size = 3
      device = torch.device("cuda:0")
  
      # Init mesh with vertex textures.
      sphere_meshes = ico_sphere(3, device).extend(batch_size)
      verts_padded = sphere_meshes.verts_padded()
      faces_padded = sphere_meshes.faces_padded()
      feats = torch.ones_like(verts_padded, device=device)
      textures = TexturesVertex(verts_features=feats)
      sphere_meshes = Meshes(
          verts=verts_padded, faces=faces_padded, textures=textures
      )
  
      # Init rasterizer settings
      dist = torch.tensor([2, 4, 6]).to(device)
      elev = torch.zeros_like(dist)
      azim = torch.zeros_like(dist)
      R, T = look_at_view_transform(dist, elev, azim)
      cameras = FoVPerspectiveCameras(device=device, R=R, T=T)
      raster_settings = RasterizationSettings(
          image_size=512, blur_radius=0.0, faces_per_pixel=4
      )
  
      # Init shader settings
      materials = Materials(device=device)
      lights_location = torch.tensor([0.0, 0.0, +2.0], device=device)
      lights_location = lights_location[None].expand(batch_size, -1)
      lights = PointLights(device=device, location=lights_location)
      blend_params = BlendParams(0.5, 1e-4, (0, 0, 0))
  
      # Init renderer
      rasterizer_tests = [
          RasterizerTest(
              MeshRasterizer, HardPhongShader, "phong", "hard_phong"
          ),
          RasterizerTest(
              MeshRasterizer,
              HardGouraudShader,
              "gouraud",
              "hard_gouraud",
          ),
          RasterizerTest(
              MeshRasterizer, HardFlatShader, "flat", "hard_flat"
          ),
          RasterizerTest(
              MeshRasterizerOpenGL,
              SplatterPhongShader,
              "splatter",
              "splatter_phong",
          ),
      ]
      for test in rasterizer_tests:
          reference_name = test.reference_name
          debug_name = test.debug_name
          rasterizer = test.rasterizer(
              cameras=cameras, raster_settings=raster_settings
          )
  
          shader = test.shader(
              lights=lights,
              cameras=cameras,
              materials=materials,
              blend_params=blend_params,
          )
          renderer = MeshRenderer(rasterizer=rasterizer, shader=shader)
          images = renderer(sphere_meshes)
          for i in range(batch_size):
              image_ref = load_rgb_image(
                  "test_simple_sphere_batched_%s_%s_%s.png"
                  % (reference_name, type(cameras).__name__, i),
                  DATA_DIR,
              )
              rgb = images[i, ..., :3].squeeze().cpu()
              if DEBUG:
                  filename = (
                      "DEBUG_simple_sphere_batched_%s_%s_%s.png"
                      % (
                          debug_name,
                          type(cameras).__name__,
                          i,
                      )
                  )
                  Image.fromarray(
                      (rgb.numpy() * 255).astype(np.uint8)
                  ).save(DATA_DIR / filename)
              self.assertClose(rgb, image_ref, atol=0.05)
  
imports: import os
  import unittest
  from collections import namedtuple
  from itertools import product
  import numpy
  import torch
  from PIL import Image
  from pytorch3d.io import load_obj, load_objs_as_meshes
  from pytorch3d.renderer import AmbientLights, FoVOrthographicCameras, FoVPerspectiveCameras, look_at_view_transform, Materials, MeshRasterizer, MeshRenderer, MeshRendererWithFragments, OrthographicCameras, PerspectiveCameras, PointLights, RasterizationSettings, TexturesAtlas, TexturesUV, TexturesVertex
  from pytorch3d.renderer.fisheyecameras import FishEyeCameras
  from pytorch3d.renderer.mesh.shader import BlendParams, HardFlatShader, HardGouraudShader, HardPhongShader, SoftPhongShader, SoftSilhouetteShader, SplatterPhongShader, TexturedSoftPhongShader
  from pytorch3d.renderer.opengl import MeshRasterizerOpenGL
  from pytorch3d.structures.meshes import join_meshes_as_batch, join_meshes_as_scene, Meshes
  from pytorch3d.utils.ico_sphere import ico_sphere
  from pytorch3d.utils.torus import torus
  from .common_testing import get_pytorch3d_dir, get_tests_dir, load_rgb_image, TestCaseMixin
label_desc: Use image node_id 5 for calling the TestRenderMeshes obj's underlying member method code with example usage: obj.test_simple_sphere_batched() without return types