Jump to content

Blending two LUT textures


photo

Recommended Posts

We have seen example demos/ambient/ambient, where is blending two environment textures:

int init() {
engine.render.setEnvironmentTextureName("ambient/textures/environment_0.png");
engine.render.getEnvironmentCoefficients(environment_0);

engine.render.setEnvironmentTextureName("ambient/textures/environment_1.png");
engine.render.getEnvironmentCoefficients(environment_1);

return 1;
}

int update() {

float k = sin(engine.game.getTime()) * 0.5f + 0.5f;

vec3 environment[9];
forloop(int i = 0; 9) {
	environment[i] = lerp(environment_0[i],environment_1[i],k);
}

engine.render.setEnvironmentCoefficients(environment);

return 1;
}

 

We wont use similar blending for setColorTextureName() function - blend two LUT textures, but we don't find setColorCoefficients function, is it possible? Thanks.

Link to comment

We wont use similar blending for setColorTextureName() function - blend two LUT textures, but we don't find setColorCoefficients function, is it possible? Thanks.

 

There is no "setColorCoefficients" functions as these are different concepts. Environment lighting based on compact BRDF representation calculated from provided environment cube map is used in UNIGINE pixel-shaders to simulate different lighting colors from different hemispherical directions without too much performance penalty. If you need something analogous for LUT textures than you have to implement this on your own.

Link to comment

I have no choice :(

Could you say please, what shader's names for realization environment blending textures (setEnvironmentTextureName functionality) and for LUT effect realization (setColorTextureName functionality)? I don't want change original shaders, I want add new, based on this two.

Link to comment

I have no choice :(

Could you say please, what shader's names for realization environment blending textures (setEnvironmentTextureName functionality) and for LUT effect realization (setColorTextureName functionality)? I don't want change original shaders, I want add new, based on this two.

 

Please describe your original aim, may be there is a better way.

Link to comment

We need blend two LUT textures - for example, when user pass from indoor to outdoor - we want change LUT-texture. Now we can do it immediately by setColorTextureName() function, but we want do this gradually (like you blend environment textures in demos/ambient/ambient example)

Link to comment

You can call setColorTextureName() function every frame. This is not a very complex function. Blend two LUT images on script by Image::blend() function and save result into the temporary file. After call setColorTextureName().

This is a temporary solution for current Unigine version. I will add setColorTextureImage() function in next update.

Link to comment

This is an example of upcoming setColorTextureImage() functionality:

 

void update_scene() {

Image lut = new Image();
Image lut_0 = new Image("samples/render/textures/lut_blue.dds");
Image lut_1 = new Image("samples/render/textures/lut_orange.dds");

while(1) {

	lut.copy(lut_0);
	lut.blend(lut_1,0,0,0,0,lut.getWidth(),lut.getHeight(),abs(sin(engine.game.getTime())));

	engine.render.setColorTextureImage(lut);

	sleep(1.0f / 20.0f);
}
}

Link to comment

Ok, I have some additional question about Image::blend() function... I use next code:

Image imageLayer_0 = new Image();
Image imageLayer_1 = new Image();

imageLayer_0.load("source/textures/water.png");
imageLayer_1.load("source/textures/sky.png");

imageLayer_0.blend(imageLayer_1, 0, 0, 0, 0, 
imageLayer_0.getWidth(), imageLayer_0.getHeight(), 1.0f); // I need blend second image with first with 0.5f scale value, 1.0f - it's only for test

imageLayer_0.save("source/temp/lut.png");

Water:post-151-0-81859100-1298377608_thumb.png

Sky:post-151-0-94421800-1298377599_thumb.png

Result:post-151-0-88136400-1298377618_thumb.png

 

This blending like Photoshop's Linear Dodge (Add) blend type. How I could change blending type?

I need this result:

post-151-0-99662800-1298377829_thumb.jpg

This is 100% alpha of first and 50% alpha of second image - Photoshop's Normal blend type

Link to comment

I will add setColorTextureImage() function in next update.

 

I use Unigine not much time, but want to share my opinion - it's could be more flexible and transparent for newbies, if all functions, like engine.render.setColorTextureName would work only with Image instances instead of file loading. It would be easy to understand, because it is one universal pattern. And if developer wants to use the Image, he passes an Image instance to function (he don't need to save image file, and load it again), if he wants to use texture file - he must create Image instance to load this texture and, again, pass it in function image instance, IMHO.

Link to comment

if developer wants to use the Image, he passes an Image instance to function (he don't need to save image file, and load it again), if he wants to use texture file - he must create Image instance to load this texture and, again, pass it in function image instance, IMHO.

 

This would cause problems for state serialization and resource streaming because texture state couldn't be restored in case of reload due to missing file backup.

Link to comment
  • 1 month later...

We try to use new ability from demo scene lookup_00 and encounter with problem:

if we change blending images in demo scene like:

Image lut = new Image();
Image lut_0 = new Image("samples/render/textures/lookup_first.dds");
Image lut_1 = new Image("samples/render/textures/lookup_first.dds");

 

then we get next result:

post-151-0-71002800-1300871172_thumb.jpg

Correct behavior - effect from lut-texture should not change, cause we blending one image with the same.

Problem in images blending algorithm.

Be better, if blend function take additional parameter (blending constants), and blending algorithms could be expand with the lapse of time.

Link to comment

The blending function is:

 

RGB:RGB case: dest_rgb + src_rgb * scale;

RGB:RGBA case: dest_rgb * (1.0f - src_alpha * scale) + src_rgb * src_alpha * scale;

RGBA:RGBA case: dest_rgba * (1.0f - src_alpha * scale) + src_rgba * src_alpha * scale;

 

lookup_00 sample changes blending scale parameter and both images in RGB format.

Link to comment
×
×
  • Create New...