I'm trying to do post processing in threejs scene
here I'm using EffectComposer for doing it
but im not able to enble sRGBEncoding in renderTarget.
const renderTarget = new THREE.WebGLRenderTarget(
sizes.width,
sizes.height,
{
minFilter:THREE.LinearFilter,
magFilter:THREE.LinearFilter,
format:THREE.RGBAFormat,
encoding:THREE.sRGBEncoding
}
)
and my effectComposer is like that
const effectComposer = new EffectComposer(renderer,renderTarget);
effectComposer.setPixelRatio(Math.min(window.devicePixelRatio,2));
effectComposer.setSize(sizes.width,sizes.height)
but sRGBEncoding is not working
When using post processing, use a gamma correction pass at the end of your pass chain. This will ensure a sRGB encoded output:
composer.addPass( new ShaderPass( GammaCorrectionShader ) );
Full example: https://threejs.org/examples/webgl_postprocessing_3dlut
Related
I'm building an app that user required to send a selfie but some user just block the camera to take a picture and the result is all black, is there a way to detect if image is black?
I'm thinking of using face detection but I haven't tried it and its way to much for my simple app.
One way you can try is using palette_generator package to extract colors in the image and then computing average luminance of the image, like so.
import 'package:palette_generator/palette_generator.dart';
Future<bool> isImageBlack(ImageProvider image) async {
final double threshold = 0.2; //<-- play around with different images and set appropriate threshold
final double imageLuminance = await getAvgLuminance(image);
print(imageLuminance);
return imageLuminance < threshold;
}
Future<double> getAvgLuminance(ImageProvider image) async {
final List<Color> colors = await getImagePalette(image);
double totalLuminance = 0;
colors.forEach((color) => totalLuminance += color.computeLuminance());
return totalLuminance / colors.length;
}
Before use camera check if your app has permission for that.
For this porpouse i've recommend to use the permission handler
Few lines from official documentation
var status = await Permission.camera.status;
if (status.denied) {
// We didn't ask for permission yet or the permission has been denied before but not permanently.
}
I want to use sibl.
const loadHDR = () => {
new THREE.RGBELoader().load('./resource/textures/HDR/Etnies_Park_Center_3k.hdr', (texture, textureData)=> {
texture.encoding = THREE.RGBEEncoding;
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
texture.flipY = true;
console.log(texture)
textureData.height = 1200
textureData.width = 1200
textureData.exposure = 10
console.log(textureData)
const cubemap = new THREE.EquirectangularToCubeGenerator(texture, { resolution: 3200, type: THREE.UnsignedByteType });
exrBackground = cubemap.renderTarget;
cubeMapTexture = cubemap.update(renderer);
texture.dispose();
})
}
This is my code. and
console.log(textureData)
The above code results show the revised values well.
But cubemap's exposure does not change.
Another problem is reading .ibl file
I have to read the position of the sun in webgl, but I can't read the file.
I am using webpack. fs library no exist.
I've been trying to adjust exposure with RGBELoader as well. It looks like you have to set it as a property to the renderer, since the properties that you list are only returned by the module in the callback function. They don't "set" anything.
It looks like the functions related to environment maps have changed significantly since you asked this question. For instance, THREE.EquirectangularToCubeGenerator apparently no longer exists. It looks like pmremGenerator.fromEquirectangular is intended as the replacement, but I'm not entirely sure.
Here is my code, which loads an Equirectangular image and converts it to a cube map, then applies it as a background. The exposure can be set with renderer.toneMappingExposure, which works in r112. Note that this is the module version.
new RGBELoader()
.load('filename.hdr', (hdrEquiRect, textureData) => {
hdrCubeRenderTarget = pmremGenerator.fromEquirectangular(hdrEquiRect);
pmremGenerator.compileCubemapShader();
scene.background = hdrCubeRenderTarget.texture;
renderer.toneMapping = LinearToneMapping;
renderer.toneMappingExposure = 0.5;
});
This example uses renderer.toneMappingExposure to adjust the exposure of the HDRi background:
https://threejs.org/examples/?q=hdr#webgl_materials_envmaps_hdr
Edit - since r116 you also need to set renderer.toneMapping to LinearToneMapping1.
I am loading image from script to texture from URL. It is loading successfully, but the image is not reflecting on the texture.
How can I fix this?
you should UV unwrapped your model(that you want to put your image on it as a texture) you save the uv and then import it to unity then you can apply texture to it , here is tutorial that will show you how to do it in blender
Alright, if I'm gathering from the image correctly, it looks like you're using NGUI. If so, then you don't use Mesh Renderer. It's been a little bit since I used NGUI, but you need a reference to the game object or to the UITexture component that is on the game object. So I'll provide some code samples below for both scenarios. But you don't use a mesh renderer unless you're wrapping the texture around a 3D model. If this is for the UITexture then you would attach the image on there.
Game Object Reference:
imageObject.GetComponent<UITexture>().mainTexture = textureToUse;
UITexture Reference:
uiTextureReference.mainTexture = textureToUse;
I think that is what you were looking for, otherwise you need to do unwrapping and what not.
It is very easy if you are using NGUI.
Create a UITexture.
Refer it in you class either by declaring it public variable of getting it at runtime.
Import MiniJSON class that is easily available on internet. (Do not hesitate if you failed to find MiniJSON.Json, it could be MiniJSON.Deserialize or only Json.Deseiralize)
Following is the code snippet to get Facebook Display Picture with User_API_ID
string myImageUrl = "https://graph.facebook.com/"+API_ID+"/picture?type=large&redirect=0";
WWW myImageGraphRequest = new WWW(myImageUrl);
yield return myImageGraphRequest;
if (!string.IsNullOrEmpty(myImageGraphRequest.error))
Debug.Log("Could not fetch own User Image due to: " + myImageGraphRequest.error);
else
{
var myImageData = MiniJSON.Json.Deserialize (myImageGraphRequest.text) as Dictionary<string, object>;
var myImageLinkWithData = myImageData["data"] as Dictionary<string, object>;
string myImageLink = (string)myImageLinkWithData["url"];
WWW myImageRequest = new WWW(myImageLink);
yield return myImageRequest;
if (!string.IsNullOrEmpty(myImageRequest.error))
Debug.Log("Could not get user facebook image: " + myImageRequest.error);
else
{
userDP.mainTexture = myImageRequest.texture;
}
}
userDP is your UITexture.
Is possible to load an image (logo) before loading the original image using Universal Image Loader?
How would be the implementation in this case?
Thanks in advance.
Using DisplayImageOptions in the field 'showImageOnLoading':
IMAGE_OPTIONS = new DisplayImageOptions.Builder() //
.showImageOnLoading(R.drawable.loader) //
.resetViewBeforeLoading(false) //
.bitmapConfig(Config.RGB_565) //
.imageScaleType(ImageScaleType.IN_SAMPLE_INT) //
.delayBeforeLoading(500) //
.cacheOnDisc(true) //
.cacheInMemory(true) //
.build();
I would like to load a model using three.js and then apply a transformation matrix on top of it. This is the code I am using:
var loader = new THREE.OBJMTLLoader();
loader.addEventListener('load', function (event)
{
var object = event.content;
object.matrixAutoUpdate = false;
object.applyMatrix(object_accumulated_matrix);
scene.add(object);
},
{
useWorker: true
});
// should check if ".mtl" file exists but there is no access to the filesystem
loader.load(dir_file_name + ".obj", dir_file_name + ".mtl");
and these are the contents of the object_accumulated_matrix variable:
({elements:{0:1, 1:0, 2:0, 3:0, 4:0, 5:1, 6:0, 7:322, 8:0, 9:0, 10:1, 11:0, 12:0, 13:0, 14:0, 15:1}})
There is a 322 translation value on the Y-axis but I can not seem to get it to work. I have also tried:
object.matrix.copy(object_accumulated_matrix);
but that did not work either.
I would appreciate any help.
Thank you.
Your object_accumulated_matrix is transposed.
You can also try
object.geometry.applyMatrix( object_accumulated_matrix );
which will modify the geometry itself.