kzaharov Posted January 14, 2019 Share Posted January 14, 2019 in the sdk 2.7 there are 2 very similar samples: 1. data\samples\render\auxiliary_03.cpp (individual objects one by one becoming blurred) 2. data\samples\shaders\post_selection_00.cpp (individual objects highlighting one by one) The main difference between them is that uses different postmaterials. Is it possible to do so: at the same time some arbitrary object becomes blurred, and the other highlighted? I can't figure it out by looking at the code. Link to comment
thomalex Posted January 15, 2019 Share Posted January 15, 2019 Hello @kzaharov, It isn't possible to solve this task by changing only the world script since the PostMaterials affect the whole auxiliary buffer, you will have to modify some shaders too. But it is simple and I'm going to tell you how to do it step by step. The idea is to use different post materials depending on the color of a pixel in the auxiliary buffer, in other words to apply masking by color channel. 1. Let's work with one of these samples. As you noticed, they are almost identical, so it doesn't matter which one. I have chosen the post_selection_00 one. Firstly, you need to set Render Materials the same way as in the auxiliary_03.cpp to enable blurring. This belongs to the end of the create_scene function: ... engine.render.setPostMaterials("post_filter_selection"); engine.render.setRenderMaterials("post_hblur_mask,post_vblur_mask"); return "Object selection"; } This will make the current mesh highlighted and blurred at the same time. 2. Next, let's add some logic to get two current meshes each time - one to be highlighted and one to be blurred - and paint them in different ways. I've decided to use red color for the first one and green for the other. This is how the update_scene function looks now: void update_scene() { int num_selected = 0; int num_blurred = 0; while(1) { // clear the previous meshes meshes[num_selected].setMaterialState("auxiliary",0,0); meshes[num_selected].setMaterialParameter("auxiliary_color",vec4_one,0); meshes[num_blurred].setMaterialState("auxiliary",0,0); meshes[num_blurred].setMaterialParameter("auxiliary_color",vec4_one,0); // get next two ones num_selected = engine.game.getRandom(0,meshes.size()); num_blurred = engine.game.getRandom(0,meshes.size()); // paint them appropriately meshes[num_selected].setMaterialState("auxiliary",1,0); meshes[num_selected].setMaterialParameter("auxiliary_color",vec4(1.0f,0.0f,0.0f,0.0f),0); meshes[num_blurred].setMaterialState("auxiliary",1,0); meshes[num_blurred].setMaterialParameter("auxiliary_color",vec4(0.0f,1.0f,0.0f,0.0f),0); sleep(0.25f); } } That's what we have on this step. The following images show the auxiliary buffer and the final render. Almost there! But one mesh is blurred and highlighted at the same time while the other is not. This is caused by the Mask parameter of the post_hblur_mask and post_vblur_mask materials which performs masking by red channel by default. You can find its realization in the corresponding shader: core/shaders/screen_space/post/blur_mask.frag. 3. So now we simply apply a similar approach for the shaders of filter selection, which are stored at data/samples/shaders/shaders/screen_space/fragment/. Basically, here we need only the filter_selection_sample.frag, we modify it so it takes only the green color channel instead of the whole auxiliary buffer. float4 auxiliary = TEXTURE_BIAS_ZERO(TEX_AUXILIARY,uv); OUT_COLOR = auxiliary; The lines above are to be turned into the following: float auxiliary_green = TEXTURE_BIAS_ZERO(TEX_AUXILIARY,uv).y; OUT_COLOR = float4(0, auxiliary_green, 0, 0); Where y is the green component. And here we are: there are two meshes with different post effects applied. There is an issue with the color of highlight, it is always green unlike the random one in the post_selection_00.cpp sample. I would solve it in the shader code, but there are other ways for sure. The modified world script post_selection_00.cpp and the modified filter_selection_sample.frag shader (the original shader is to be replaced with this one.) are attached. All was made by using the sdk 2.7. Hope it helps, best regards! filter_selection_sample.frag post_selection_00.cpp 2 Link to comment
kzaharov Posted January 17, 2019 Author Share Posted January 17, 2019 And one more question. I need shader for postprocess material wich will change color of object, making it red or green etc. Similar effect shown on image at https://developer.unigine.com/en/docs/2.7.3/content/materials/library/postprocess/). Is there such a shader in the sdk? Link to comment
kzaharov Posted January 20, 2019 Author Share Posted January 20, 2019 A bit to deal with this issue. Just use lerp function of UUSL to mix color. One more question: How to get image of auxiliary buffer like in thomalex's post? Link to comment
Greg.Mildenhall Posted January 20, 2019 Share Posted January 20, 2019 One way to get an image of the auxiliary buffer is to use the console: render_show_textures 2 render_show_textures_offset <whichever number is auxiliary> render_show_textures_number 1 Link to comment
Recommended Posts