CubeTexture.hx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. class CubeTexture extends hxd.App {
  2. var skyTexture : h3d.mat.Texture;
  3. override function init() {
  4. skyTexture = new h3d.mat.Texture(128, 128, [Cube, MipMapped]);
  5. var bmp = hxd.Pixels.alloc(skyTexture.width, skyTexture.height, h3d.mat.Texture.nativeFormat);
  6. var faceColors = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFF00, 0x00FFFF, 0xFF00FF];
  7. for( i in 0...6 ) {
  8. for( x in 0...128 )
  9. for( y in 0...128 )
  10. bmp.setPixel(x,y, (x + y) & 1 == 0 ? faceColors[i] : (faceColors[i]>>1)&0x7F7F7F);
  11. skyTexture.uploadPixels(bmp, 0, i);
  12. }
  13. skyTexture.mipMap = Linear;
  14. var sky = new h3d.prim.Sphere(30, 128, 128);
  15. sky.addNormals();
  16. var skyMesh = new h3d.scene.Mesh(sky, s3d);
  17. skyMesh.material.mainPass.culling = Front;
  18. skyMesh.material.mainPass.addShader(new h3d.shader.CubeMap(skyTexture));
  19. skyMesh.material.shadows = false;
  20. var sp = new h3d.prim.Sphere(0.5, 64, 64);
  21. sp.addNormals();
  22. var m = new h3d.scene.Mesh(sp, null, s3d);
  23. m.material.mainPass.enableLights = true;
  24. m.material.shadows = false;
  25. m.material.mainPass.addShader(new h3d.shader.CubeMap(skyTexture, true));
  26. var pt = new h3d.scene.fwd.PointLight(s3d);
  27. pt.x = 2;
  28. pt.y = 1;
  29. pt.z = 4;
  30. pt.enableSpecular = true;
  31. pt.params.set(0, 1, 0);
  32. cast(s3d.lightSystem,h3d.scene.fwd.LightSystem).ambientLight.set(0.1, 0.1, 0.1);
  33. new h3d.scene.CameraController(5, s3d).loadFromCamera();
  34. }
  35. override function update(dt:Float) {
  36. if( hxd.Key.isPressed("M".code) ) {
  37. skyTexture.mipMap = switch( skyTexture.mipMap ) {
  38. case None: Nearest;
  39. case Nearest: Linear;
  40. case Linear: None;
  41. }
  42. }
  43. }
  44. static function main() {
  45. new CubeTexture();
  46. }
  47. }