}
}
}
private Texture updateNoiseTexture() {
Texture texture = CoreRegistry.get(AssetManager.class).tryLoadAsset(new AssetUri(AssetType.TEXTURE, "engine:ssaoNoise"), Texture.class);
if (texture == null) {
ByteBuffer noiseValues = BufferUtils.createByteBuffer(SSAO_NOISE_SIZE * SSAO_NOISE_SIZE * 4);
for (int i = 0; i < SSAO_NOISE_SIZE * SSAO_NOISE_SIZE; ++i) {
Vector3f noiseVector = new Vector3f(random.nextFloat(-1.0f, 1.0f), random.nextFloat(-1.0f, 1.0f), 0.0f);
noiseVector.normalize();
noiseValues.put((byte) ((noiseVector.x * 0.5 + 0.5) * 255.0f));
noiseValues.put((byte) ((noiseVector.y * 0.5 + 0.5) * 255.0f));
noiseValues.put((byte) ((noiseVector.z * 0.5 + 0.5) * 255.0f));
noiseValues.put((byte) 0x0);
}
noiseValues.flip();
texture = Assets.generateAsset(new AssetUri(AssetType.TEXTURE, "engine:ssaoNoise"), new TextureData(SSAO_NOISE_SIZE, SSAO_NOISE_SIZE,
new ByteBuffer[]{noiseValues}, Texture.WrapMode.REPEAT, Texture.FilterMode.NEAREST), Texture.class);
}
return texture;
}