uzadow Posted June 27, 2018 Posted June 27, 2018 Hi, I have a simple custom material that should be rendered in the forward pass, and I can't seem to access the texture I pass in. Currently, the object appears black, when it should be displaying the texture. Simply writing the texture coordinates to the frag color gives a correct result, though. Any idea why this is? Where am I going wrong? This is my material definition: <?xml version="1.0" encoding="utf-8"?> <base_material version="2.0" name="video_texture" editable="0" parameters_prefix="m"> <options transparent="2"/> <!-- States --> <state name="ambient">1</state> <!-- Deferred rendering shaders --> <shader pass="ambient" node="object_mesh_static" ambient="1" defines="BASE_AMBIENT" vertex="shaders/video_texture.vert" fragment="shaders/video_texture.frag"/> <!-- Bindings --> <bind node="object_mesh_dynamic" to="object_mesh_static"/> <bind node="object_mesh_skinned" to="object_mesh_static"/> <!-- Textures --> <texture unit="0" name="albedo" anisotropy="1" shader="fragment" pass="deferred, ambient">core/textures/common/white.dds</texture> </base_material> The Vertex shader: // Include Unified Unigine Shader Language (UUSL) header #include <core/shaders/common/common.h> // Input data struct STRUCT(VERTEX_IN) INIT_ATTRIBUTE(float4,0,POSITION) // Vertex position INIT_ATTRIBUTE(float4,1,TEXCOORD0) // Vertex texcoord (uv) END // Our output vertex data struct STRUCT(VERTEX_OUT) INIT_POSITION // Out projected position INIT_OUT(float4,0) // Texcoord (uv) END MAIN_BEGIN(VERTEX_OUT,VERTEX_IN) // Get transform with scale and rotation (without translation) float4 row_0 = s_transform[0]; float4 row_1 = s_transform[1]; float4 row_2 = s_transform[2]; // Get Modelview-space transform float4 in_vertex = float4(IN_ATTRIBUTE(0).xyz,1.0f); float4 position = mul4(row_0,row_1,row_2,in_vertex); // Set output UV float4 texcoord = IN_ATTRIBUTE(1); OUT_DATA(0) = texcoord; // Set output position OUT_POSITION = getPosition(position); MAIN_END The fragment shader: // Include the UUSL language header #include <core/shaders/common/fragment.h> // Adds a texture sampler INIT_TEXTURE(0, TEX_COLOR) STRUCT(FRAGMENT_IN) INIT_POSITION // Projected position INIT_IN(float4,0) // Texcoord (uv) END MAIN_BEGIN(FRAGMENT_OUT, FRAGMENT_IN) // Get the UV coords float2 texcoord = IN_DATA(0).xy; // Get the texture data float4 macro, macro_u, macro_r, macro_ur; float4 fragColor = TEXTURE(TEX_COLOR, texcoord); OUT_COLOR = fragColor; OUT_COLOR.a = 1.0f; MAIN_END
fox Posted June 28, 2018 Posted June 28, 2018 Hi uzadov, try replacing the following lines in your fragment shader: // Get the UV coords float2 texcoord = IN_DATA(0).xy; // Get the texture data float4 macro, macro_u, macro_r, macro_ur; float4 fragColor = TEXTURE(TEX_COLOR, texcoord); with these ones: // Get the UV coords float4 texcoord = IN_DATA(0); float4 macro, macro_u, macro_r, macro_ur; // Get the texture data float4 fragColor = TEXTURE(TEX_COLOR,texcoord.xy); This should help! Thanks!
uzadow Posted June 28, 2018 Author Posted June 28, 2018 Hi Fox, thanks for your support! Unfortunately, I just tried your suggestion, and there is no change. The quad is rendered in black. To check if the tex coordinates are correct, I output them: OUT_COLOR = float4(texcoord.x, texcoord.y, 0, 1); This gives me the expected color gradient on my quad. Right now I'm assuming that for some reason, it can't access the texture. Does that make sense?
silent Posted June 28, 2018 Posted June 28, 2018 Could you please provide an newly created project and your shaders with required textures and sources for debugging? It's hard to say what is going on here. Thanks! How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
uzadow Posted June 28, 2018 Author Posted June 28, 2018 Sure, no problem. Since it fails to upload here, I've placed the reproducer at: https://www.libavg.de/owncloud/index.php/s/dzm1SfDcrq4KBCq If you open the world file in the editor and navigate to materials, there is a test.basemat material. It should render a white texture, but it renders black. It does render white if I hardcode that in the shader.
fox Posted June 29, 2018 Posted June 29, 2018 Hi uzadow, Seems like the problem was in your material file, try removing a space in this line in the pass list (after the comma between "deferred" and "ambient"): <texture unit="0" name="albedo" anisotropy="1" shader="fragment" pass="deferred,ambient">core/textures/common/white.dds</texture> Thanks!
uzadow Posted June 30, 2018 Author Posted June 30, 2018 Yep, that was it. Thanks for the quick and precise support! A follow-up question: Is there a way to debug situations like this ourselves? Did I miss an error message somewhere?
fox Posted July 1, 2018 Posted July 1, 2018 Glad that everything is ok! Normally, all messages, warnings and errors are displayed in the console. However, looks like this one was an exception, sorry for any inconvenience caused! Thanks!
Recommended Posts