Priyank.Jain2 Posted January 18, 2017 Share Posted January 18, 2017 Hi, I want to set some portion of terrain object as transparent. In our previous version(2014-06-04) we were adding surface material and than use "setMaterialDiffuseScale" to control the visibility (we are using custom material for fragment base ambient shader to use diffuse alpha). Now with Unigine 2.3.1 instead of materials you have to add overlay layers and use "setMaterialAlbedoScale" for same thing. I have tried same approach on a sample but unable to make the terrain transparent. Basically we want to have some x-ray kind of functionality where in we can see what is underneath the terrain. How can we achieve that? Link to comment
silent Posted January 18, 2017 Share Posted January 18, 2017 Hi Priyank, There is no way to make terrain transparent out of the box. Generally, adding an ability to make terrain's surfaces transparent will result in huge performance drop. For your use-case you can try to use Camera class (just put it under terrain and render image to texture) and use this texture in decal that will be projected onto terrain or any other surface. The second solution will be to use holes texture to remove terrain geometry in the specific spot (not sure if that will fit your needs). You also can try to check how Alpha blend is done for mesh_base material and try to write custom shader for terrain that will render it in forward pass, but with transparency (will cause performance degradation). Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Priyank.Jain2 Posted January 19, 2017 Author Share Posted January 19, 2017 Thanks for the pointers, This is the same way we have handled transparency in previous implementation(by editing the existing ambient shader). <shader pass="ambient" object="terrain" defines="BASE_AMBIENT,AMBIENT" receive_world_shadow_defines=",SHADOW" terrain_defines="PATCH,0,0" ambient="1" detail_0_defines=",DETAIL_0_OVERLAY,DETAIL_0_OVERLAP" detail_1_defines=",DETAIL_1_OVERLAY,DETAIL_1_OVERLAP" detail_2_defines=",DETAIL_2_OVERLAY,DETAIL_2_OVERLAP" detail_3_defines=",DETAIL_3_OVERLAY,DETAIL_3_OVERLAP" triplanar_defines=",PATCH_TRIPLANAR" ambient_light_defines=",AMBIENT_LIGHT" vertex="core/shaders/default/terrain/vertex_base.shader" fragment="our_own_shader"/> So now you mean same thing should work here as well? Is there any sample which I can refer? Link to comment
silent Posted January 19, 2017 Share Posted January 19, 2017 Hi Priyank, There is no sample available. Terrain out of the box is not supporting any kind of transparency in shader - you have to add missing code similar that we have right now in other materials with transparency (for example, mesh_base). That code from old shaders will not work. How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Priyank.Jain2 Posted January 23, 2017 Author Share Posted January 23, 2017 Thanks, I have tried the same approach but looks like ambient pass for terrain needs some other flags/states to be set. Please check attached test project where in I have used my test ambient shader with hard-coded color values, but that is not making any difference when I chose terrain transparency as "alpha blend" or "Custom" (with src alpha and one minus src alpha) Let me know if I am doing something wrong or missing something. Note: Attached sample doesn't have core.ung, editor.ung and Qt5CoreUnigine_x64.dll terrain_u2.zip Link to comment
silent Posted January 23, 2017 Share Posted January 23, 2017 Hi Priyank, Thank you for the test scene!The thing is there is no alpha blend or any alpha transparency support in the default fragment shader of terrain (data/core/shaders/terrain/fragment/*), so enabling states in material file will not lead to the different results. I'm afraid you have to write your own terrain fragment shader with alpha blend (with all light passes, ambient pass and so on). Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Priyank.Jain2 Posted January 24, 2017 Author Share Posted January 24, 2017 Ok, So in the test scene I have used the default terrain fragment shader and in the ambient pass tried to set some hard coded value to OUT_color, just for testing but that also did not worked. Can you please help in understanding the most hacky way of doing that(atleast for testing purpose)? What are the shaders and passes I can reuse from "terrain_base" ? Link to comment
Akshay.Patil Posted February 6, 2017 Share Posted February 6, 2017 Hello , 1 ) We have created our own material for terrain derived from "terrain_base" (unigine_2_3_1\data\core\materials\default\unigine_terrain.mat) And we have disabled the deferred pass and enabled the ambient pass and done few changes to "terrain_base" so that we get values for states subtract_layers, material_detail, material_roughness, material_normal, num_materials, num_layers in ambient pass by modifying its pass_defines attribute On shader side we are use deffered shader as it is (unigine_2_3_1\data\core\shaders\terrain\vertex\deferred.vert) and we are using the fragment shader (unigine_2_3_1\data\core\shaders\terrain\fragment\deferred.frag) with a bit of modification as we can not write to gbuffer i am skipping the setGbuffer. So we are exactly doing the same thing as in deferred shader and trying to output the color myself by doing some light computations in our shader but they are not working good (Not getting exact lighting as we have in deferred shader) Can you help us which UUSL functions should we use in our ambient shader to match the lighting in deferred shader ?? 2) We are setting up terrain through unigine script only But i am having bit difficulty because of TextureArray functionality We are setting up layers and adding materials through API only. But they does not seem to work at all, Looks just the albedo color for material is getting applied and not the textures But when we created the AlbedoTextureArray using editor and applied it to our terrain through API again , strangely things started working. Looks like when we just add materials and layers , AlbedoTextureArray is not getting created internally . Is it a known issue or Am I missing something ? 3) Also why we need to define AlbedoTextureArray when we are creating layers and materials ? Link to comment
Akshay.Patil Posted March 15, 2017 Share Posted March 15, 2017 Hello , I am using the sample attached by priyank in folder terrain_u2.zip But i am facing camera related issues. If i launch the editor and use Editor camera i am able to save its postion and restore back on same position But I am not able to save/ restore game camera position . I am using camera lock unlock sequence as mentioned in manual Is there any file where this settings are saved ? Link to comment
silent Posted March 15, 2017 Share Posted March 15, 2017 Hi Akshay, Game camera is controlled only via code (engine.game.getPlayer() / engine.game.setPlayer()). How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Akshay.Patil Posted March 15, 2017 Share Posted March 15, 2017 Thanks , i am having one additional problem i am not able to navigate inside standalone app for terrain_u2 , while the same is possible in the app i created fresh using brower Link to comment
silent Posted March 15, 2017 Share Posted March 15, 2017 Please, check the sample code and modify it to be like the other samples. Or ask Priyank to modify it for you :) How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Recommended Posts