Jump to content

[SOLVED] Trying to do a shader


photo

Recommended Posts

I been try to do a point cloud using "deferred" pass material, and I'm been testing differents option.  For sample this sample if I put a material as "particles" work fine, I found a particle implementation shaders with the shader for "geometry, vertex and fragment" on ambient and don't work, I try many samples I found on the forums and don't work on my side. I try to modify that I been testing and I don't get nothing yet. The only shader I get running was using a  UUSL for other a "object_mesh_static" node, but nothing yet for a "object_dynamic".  In the HELP documentation only I found two reference to a UUSL geometry shader only as "https://developer.unigine.com/en/docs/2.9/code/uusl/types?rlang=cpp",  and a table "https://developer.unigine.com/en/docs/2.9/code/uusl/semantics?rlang=cpp" nothing about a working sample shader. 

Any help on this way I will appreciate very much.

void AppWorldLogic::InitObjectDynamic03()
{
	ObjectDynamicPtr  pod;
	pod = ObjectDynamic::create();

	pod->setName("POINTS");
	//pod->setMaterial("particles", "*"); // this work
	pod->setMaterial("MyParticles", "*");
	pod->setSurfaceProperty("surface_base", "*");

	pod->setSurfaceMode(ObjectDynamic::MODE_LINES, 0); // ObjectDynamic::MODE_POINTS, 
	pod->setMaterialNodeType(Node::OBJECT_MESH_DYNAMIC);
	pod->setInstancing(0);

	pod->setVertexFormat(attributesParticle, 2);
	pod->addPoints(20);
	for (int i = 0; i < pod->getNumIndices(); i++)
	{
		// vec3 vertex = vec3(Game::get()->getRandomFloat(0.0f, 1.0f), Game::get()->getRandomFloat(0.0f, 1.0f), Game::get()->getRandomFloat(1.0f, 2.0f));
		vec3 vertex = vec3((i % 2)*0.2, i%2, i*0.1);
		pod->addVertexFloat(0, vertex, 3);
		// vec2 xy = vec2(Game::get()->getRandomFloat(0.2f, 0.8f), Game::get()->getRandomFloat(0.0f, 3.1415));
		vec2 xy = vec2(0.8, 3.14);
		pod->setVertexFloat(1, xy, 2);
	}
	pod->flushVertex();

	BoundBox bb = BoundBox(vec3(-128, -128, 2), vec3(128, 128, 64));
	pod->setBoundBox(bb);
}

 

 

fragment.shader

geometry.shader

MyParticles.basemat

vertex.shader

AppWorldLogic.cpp

AppWorldLogic.h

 

/Roberto

 

Edited by roberto.voxelfarm
Link to comment

Now I try just put a more single red lines or red points but not even a single red pixel on screen. What can be wrong?

AppWorldLogic.cpp

void AppWorldLogic::TestPtPoint01()
{
	ObjectDynamicPtr  pod = ObjectDynamic::create();
	pod->setMaterial("ptcloud", "*");
	pod->setSurfaceProperty("surface_base", "*");

	pod->setSurfaceMode(ObjectDynamic::MODE_LINES, 0);		// ObjectDynamic::MODE_POINTS, 
	pod->setMaterialNodeType(Node::OBJECT_MESH_DYNAMIC);
	pod->setInstancing(0);
	pod->setVertexFormat(attributesPoint, 1);
	pod->addPoints(20);
	BoundBox bb(vec3(0, 0, 0), vec3(0.01f, 0.01f, 0.01f));
	for (int i = 0; i < pod->getNumIndices(); i++)
	{
		vec4 vertex = vec4((i % 2) * 0.2f, (i % 2), i*0.1f, 0.0f);
		pod->addVertexFloat(0, vertex, 4);
		bb.expand(vec3(vertex.x, vertex.y, vertex.z));
	}
	pod->flushVertex();

	pod->setBoundBox(bb);
}

 

"ptcloud.basemat, ptcloud.shader,  I try to use this but ptcloud-geo.shader

<?xml version="1.0" encoding="utf-8"?>
<base_material name="ptcloud" editable="0" version="2.5.0.2">
  <shader pass="deferred" node="object_dynamic" deferred="1" defines="BASE_DEFERRED"
          vertex="mat/ptcloud/ptcloud.shader" fragment="mat/ptcloud/ptcloud.shader"/>
  <!--  geometry="mat/ptcloud/ptcloud-geo.shader"  -->
</base_material>
#ifdef VERTEX

	#include <core/shaders/common/common.h>

	STRUCT(VERTEX_IN)
		INIT_ATTRIBUTE(float4, 0, POSITION) 	// Vertex position
	END

	STRUCT(VERTEX_OUT)
		INIT_POSITION			// Out projected position
	END

	MAIN_BEGIN(VERTEX_OUT, VERTEX_IN)
		float4 row_0, row_1, row_2;
		row_0 = s_transform[0];
		row_1 = s_transform[1];
		row_2 = s_transform[2];

		float4 vertex = mul4(row_0, row_1, row_2, IN_ATTRIBUTE(0));
		OUT_POSITION = getPosition(vertex);
	MAIN_END

#elif FRAGMENT

	#include <core/shaders/mesh/common/fragment.h>

	STRUCT(FRAGMENT_IN)
		INIT_POSITION
	END

	MAIN_BEGIN_DEFERRED(FRAGMENT_IN)
		GBuffer gbuffer = GBufferDefault();

		gbuffer.albedo = float3(1.0, 0.0, 0.0);
		gbuffer.transparent = 1.0;

		setGBuffer(gbuffer);
	MAIN_END

#endif
	#include <core/shaders/common/common.h>

	STRUCT(GEOMETRY_OUT)
		INIT_POSITION
		INIT_OUT(float4, 0)
	END

	STRUCT(GEOMETRY_IN)
		INIT_POSITION
	END

	GEOM_TYPE_IN(LINE_IN)
	GEOM_COUNT_IN(1)

	GEOM_TYPE_OUT(TRIANGLE_OUT)

	MAIN_GEOM_BEGIN(STRUCT_OUT, STRUCT_IN)

		float4 center = getPosition(float4(IN_GEOM_POSITION(0).xyz, 1.0f));

		OUT_POSITION = center;
		EMIT_VERTEX;
		END_PRIMITIVE;
	END_GEOM

ptcloud.basematptcloud.shaderptcloud-geo.shader

Link to comment

Hi Roberto.

The Material Node Type you set on object should match the type that you declared in the material with "node="object_dynamic"". Otherwise the engine cannot get the desired shader. I changed folowing line in last attached c++ code and few red lines appears:

pod->setMaterialNodeType(Node::OBJECT_DYNAMIC);

Also last component of position attribute must be 1.0 for proper transformation:

vec4 vertex = vec4(..., 1.0f);
pod->addVertexFloat(0, vertex, 4);

 

Also note: if you write deferred shader and depth pre pass is on (render_depth_pre_pass=1) you should also write shader with "pass="depth_pre_pass"" shader which writes depth.

For correct line rendering you also should turn off TAA (render_taa) and sharpen (render_sharpen)

AppWorldLogic.h AppWorldLogic.cpp

  • Like 1
Link to comment

Thank you consta for the sample,

I try to run your recommendation and this give me a fatal exception.  I check that material, shader and texture_render don't are null.

939592848_2019-09-3009-18-02vfLibSample02(Debugging)-MicrosoftVisualStudio.png.7ab2d7680ded44a65dff83333eb5f9d1.png

 	ucrtbase.dll!abort�()	Unknown
 	Unigine_x64d.dll!Log::fatal(const char * format, ...) Line 315	C++
 	Unigine_x64d.dll!Unigine::Log::fatal(const char * format, ...) Line 38	C++
 	vfLibSample02_x64d.exe!Unigine::Ptr<Unigine::MeshDynamic>::operator->() Line 55	C++      <<<<==== mesh_dynamic04->render(MeshDynamic::MODE_LINES, 0);  
 	vfLibSample02_x64d.exe!AppWorldLogic::renderCallback04(Unigine::Renderer * renderer) Line 227	C++
 	vfLibSample02_x64d.exe!Unigine::CallbackObject1<AppWorldLogic,void (__cdecl AppWorldLogic::*)(Unigine::Renderer *),Unigine::Renderer *>::run(Unigine::Renderer * arg0) Line 506	C++
 	Unigine_x64d.dll!RenderCallbackWrapper::run(RenderRenderer * renderer) Line 4208	C++
 	[Inline Frame] Unigine_x64d.dll!Signal::ReentrancyFrame::runNext(RenderRenderer *) Line 67	C++
 	Unigine_x64d.dll!Signal::invoke<RenderRenderer * __ptr64>(RenderRenderer * <args_0>) Line 39	C++
 	Unigine_x64d.dll!Render::runCallbacks(int callback, RenderScreen * screen) Line 3848	C++
 	Unigine_x64d.dll!RenderRenderer::render_screen(RenderScene * scene, RenderScreen * screen) Line 5674	C++
 	Unigine_x64d.dll!RenderRenderer::render_scene(RenderScene * scene, Texture * depth_out) Line 5817	C++
 	Unigine_x64d.dll!RenderRenderer::renderWorld(Texture * depth_out) Line 289	C++
 	Unigine_x64d.dll!Viewport::render_frame(Camera * camera) Line 1151	C++
 	Unigine_x64d.dll!Viewport::render(Camera * camera) Line 278	C++
 	Unigine_x64d.dll!Viewport::renderEngine(Camera * camera) Line 250	C++
>	Unigine_x64d.dll!Engine::do_render() Line 2875	C++
 	Unigine_x64d.dll!AppWindow::doRender() Line 1437	C++
 	[Inline Frame] Unigine_x64d.dll!Engine::doRender() Line 3325	C++
 	Unigine_x64d.dll!Engine::main(Unigine::SystemLogic * system_logic, Unigine::WorldLogic * world_logic, Unigine::EditorLogic * editor_logic) Line 3346	C++
 	vfLibSample02_x64d.exe!wmain(int argc, wchar_t * * argv) Line 44	C++
 	[External Code]	

/roberto

Link to comment

Thank you for your recommendation, that work fine. But now I will like to include a Geometric shader, that for each vertex I will like to add an extra one.  For this I include in the material a Geometric shader that I put below but this give me a compiler error.  The only sample I found about that was:

"....\UNIGINE_Evaluation_Sim_Windows_2.9.0.2\demos\orbits_demo_2.9.0.2\data\orbits\trajectory\shaders\trajectory.geom"

Compilation log:
	(2151,64-76): error X3000: unrecognized identifier 'TYPE_GEOM_OUT'
	hlsl 2151: void main(TYPE_GEOM_IN GEOMETRY_IN input[COUNT_GEOM_IN], inout TYPE_GEOM_OUT<GEOMETRY_OUT> stream) { 

Material

<base_material name="ptobjdynamic" editable="0" version="2.5.0.2">
  <shader pass="deferred" node="object_dynamic" deferred="1" defines="BASE_DEFERRED" 
          vertex="mat/ptcloud/ptcloud.shader"
          geometry="mat/ptcloud/ptcloud-geo.shader" fragment="mat/ptcloud/ptcloud.shader"/>
</base_material>

My shader ptcloud-geo.shader

	#include <core/shaders/common/common.h>

	STRUCT(GEOMETRY_OUT)
		INIT_POSITION
		INIT_OUT(float4, 0)
	END

	STRUCT(GEOMETRY_IN)
		INIT_POSITION
	END

	GEOM_MAX_VERTICES(2)
	GEOM_TYPE_IN(LINE_IN)
	GEOM_COUNT_IN(1)

	
	MAIN_GEOM_BEGIN(GEOMETRY_OUT, GEOMETRY_IN)

		float4 left = getPosition(float4(IN_GEOM_POSITION(0).xyz, 1.0f));

		OUT_POSITION = left;
		EMIT_VERTEX;

		left.y = 2;
		OUT_POSITION = left;
		EMIT_VERTEX;

		END_PRIMITIVE;
	END_GEOM

 

 

// All this bellow work fine

void AppWorldLogic::InitObjectDynamic03_1()
{
	ObjectDynamicPtr  pod = ObjectDynamic::create();

	pod->setName("POINTS");
	pod->setMaterial("ptobjdynamic", "*");
	pod->setSurfaceProperty("surface_base", "*");

	pod->setSurfaceMode(ObjectDynamic::MODE_LINES, 0);
	pod->setMaterialNodeType(Node::OBJECT_DYNAMIC);
	pod->setInstancing(0);

	pod->setVertexFormat(attributesPoint, 1);
	pod->addPoints(20);
	for (int i = 0; i < pod->getNumIndices(); i++)
	{
		vec4 vertex = vec4((i % 2) * 0.2f, (i % 2), i*0.1f, 1.0f);
		pod->addVertexFloat(0, vertex, 4);
	}
	pod->flushVertex();

	BoundBox bb = BoundBox(vec3(-128, -128, 2), vec3(128, 128, 64));
	pod->setBoundBox(bb);
}
<?xml version="1.0" encoding="utf-8"?>
<base_material name="ptcloud" editable="0" version="2.5.0.2">
  <shader pass="deferred" 
          node="object_mesh_dynamic"
		      deferred="1"
		      defines="BASE_DEFERRED"
          vertex="mat/ptcloud/ptcloud.shader"
          fragment="mat/ptcloud/ptcloud.shader"/>
  <!--
  geometry="mat/ptcloud/ptcloud-geo.shader"
  -->
</base_material>

#ifdef VERTEX

	#include <core/shaders/common/common.h>

	STRUCT(VERTEX_IN)
		INIT_ATTRIBUTE(float4, 0, POSITION) 	// Vertex position
	END

	STRUCT(VERTEX_OUT)
		INIT_POSITION			// Out projected position
	END

	MAIN_BEGIN(VERTEX_OUT, VERTEX_IN)
		float4 vertex = mul4(s_modelview, IN_ATTRIBUTE(0));
		OUT_POSITION = getPosition(vertex);
	MAIN_END

#elif FRAGMENT

	#include <core/shaders/mesh/common/fragment.h>

	STRUCT(FRAGMENT_IN)
		INIT_POSITION
	END

	MAIN_BEGIN_DEFERRED(FRAGMENT_IN)
		GBuffer gbuffer = GBufferDefault();

		gbuffer.albedo = float3(1.0, 1.0, 0.0);
		gbuffer.transparent = 1.0;

		setGBuffer(gbuffer);
	MAIN_END

#endif

2118056782_2019-09-3010-22-10UNIGINEEvaluationKit(NOTFORCOMMERCIALUSE).jpg.d23600a17da8c53d47f61916f3c070fc.jpg

Link to comment
  • silent changed the title to [SOLVED] Trying to do a shader
×
×
  • Create New...