RenderToTexture.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "atomic component";
  2. var component = function(self) {
  3. var node = self.node;
  4. var model = node.getComponent("StaticModel");
  5. var scene = Atomic.player.loadScene("Scenes/RenderToTextureScene.scene");
  6. // Create a renderable texture (1024x1024, RGB format), enable bilinear filtering on it
  7. var renderTexture = new Atomic.Texture2D();
  8. renderTexture.setSize(1024, 1024, Atomic.graphics.getRGBFormat(), Atomic.TEXTURE_RENDERTARGET);
  9. renderTexture.filterMode = Atomic.FILTER_BILINEAR;
  10. // Create a new material from scratch, use the diffuse unlit technique, assign the render texture
  11. // as its diffuse texture, then assign the material box object
  12. var renderMaterial = new Atomic.Material();
  13. renderMaterial.setTechnique(0, Atomic.cache.getResource("Technique", "Techniques/Diff.xml"));
  14. renderMaterial.setTexture(Atomic.TU_DIFFUSE, renderTexture);
  15. model.setMaterial(renderMaterial);
  16. // Get the texture's RenderSurface object (exists when the texture has been created in rendertarget mode)
  17. // and define the viewport for rendering the second scene, similarly as how backbuffer viewports are defined
  18. // to the Renderer subsystem. By default the texture viewport will be updated when the texture is visible
  19. // in the main view
  20. var cameras = scene.getComponents("Camera", true);
  21. var surface = renderTexture.getRenderSurface();
  22. var rttViewport = new Atomic.Viewport(scene, cameras[0]);
  23. surface.setViewport(0, rttViewport);
  24. self.start = function() {
  25. }
  26. self.update = function(timeStep) {
  27. }
  28. }
  29. exports.component = component;