Jump to content

[SOLVED] About GEOM_TYPE_IN on shaders how I can IN a vertex Point.


photo

Recommended Posts

I try to recreate a shader like the sample on https://learnopengl.com/Advanced-OpenGL/Geometry-Shader on the sample is use a vertex point as geometry in.

Using UUSL the GEOM_TYPE_IN. How I can put a POINT or a Vertex?,  for now my two valid options are 

GEOM_TYPE_IN(LINE_IN) or  GEOM_TYPE_IN(TRIANGLE_IN)

 I try parameters like  VERTEX_IN, POINT_IN etc but all of then give me  "error X3000: unrecognized identifier" VERTEX_IN or POINT_IN

In fact if you do a search on all your documentation for GEOM_TYPE_IN shader definition don't appear nothing.  The only reference to the LINI_IN or TRIANGLE_IN appear on the https://developer.unigine.com/en/docs/2.9/code/uusl/semantics?rlang=cpp under the "Geometry Shader Semantics#" section.

 

This is the shader sample from the web site, were for each vertex IN emit 5 vertex OUT as triangle strip

#version 330 core
layout (points) in;
layout (triangle_strip, max_vertices = 5) out;

void build_house(vec4 position)
{    
    gl_Position = position + vec4(-0.2, -0.2, 0.0, 0.0);    // 1:bottom-left
    EmitVertex();   
    gl_Position = position + vec4( 0.2, -0.2, 0.0, 0.0);    // 2:bottom-right
    EmitVertex();
    gl_Position = position + vec4(-0.2,  0.2, 0.0, 0.0);    // 3:top-left
    EmitVertex();
    gl_Position = position + vec4( 0.2,  0.2, 0.0, 0.0);    // 4:top-right
    EmitVertex();
    gl_Position = position + vec4( 0.0,  0.4, 0.0, 0.0);    // 5:top
    EmitVertex();
    EndPrimitive();
}

void main() {    
    build_house(gl_in[0].gl_Position);
}  

/roberto

Link to comment

Hi roberto,

Try this

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

	STRUCT(GEOMETRY_OUT)
		INIT_POSITION
	END

	STRUCT(GEOMETRY_IN)
		INIT_POSITION
	END

	GEOM_COUNT_IN(1)
	GEOM_TYPE_IN(POINT_IN)	
		
	GEOM_MAX_VERTICES(5)
	GEOM_TYPE_OUT(TRIANGLE_OUT)
	
	MAIN_GEOM_BEGIN(GEOMETRY_OUT, GEOMETRY_IN)


		OUT_POSITION = IN_GEOM_POSITION(0) + float4(-0.2, -0.2, 0.0, 0.0);
		EMIT_VERTEX;

		OUT_POSITION = IN_GEOM_POSITION(0) + float4( 0.2, -0.2, 0.0, 0.0);
		EMIT_VERTEX;	
	
		OUT_POSITION = IN_GEOM_POSITION(0) + float4(-0.2,  0.2, 0.0, 0.0);
		EMIT_VERTEX;

		OUT_POSITION = IN_GEOM_POSITION(0) + float4( 0.2,  0.2, 0.0, 0.0);
		EMIT_VERTEX;

		OUT_POSITION = IN_GEOM_POSITION(0) + float4( 0.0,  0.4, 0.0, 0.0);
		EMIT_VERTEX;

		END_PRIMITIVE;
		
	END_GEOM

You should also render vertex buffer with that mode that you declared as input in geometry shader. For example mesh dynamic in c++ code:

mesh_dynamic->render(MeshDynamic::MODE_POINTS, 0);

then in your shader:

	GEOM_COUNT_IN(1)
	GEOM_TYPE_IN(POINT_IN)	

image.png

Appropriate files attached.

 

For easier understanding of error you can append EXPORT_SHADER(some_name) to the end of your shader to see your result code in GLSL or HLSL. Corresponding *.glsl or *.hlsl file will appear in data/ after each shaders recompilation.

There are also built-in defines DIRECT3D11 and OPENGL. In shader you can write in native language:

#ifdef OPENGL
 // GLSL code
#elif DIRECT3D11
 // HLSL code
#endif


 

AppWorldLogic.cpp AppWorldLogic.h ptcloud.basemat ptcloud.shader

  • Like 1
Link to comment

Thank you Consta I appreciate this.

I make a small modification for use with ObjectDynamic then I don't have to put callback.

void AppWorldLogic::InitObjectDynamic03_4()
{
	ObjectDynamicPtr omd = ObjectDynamic::create(ObjectDynamic::DYNAMIC_VERTEX);

	ObjectDynamic::Attribute cFormate[] = { { 0, ObjectDynamic::TYPE_FLOAT, 4 } };
	omd->setVertexFormat(cFormate, 1);
	omd->setSurfaceMode(ObjectDynamic::MODE_POINTS, 0);
	omd->setMaterialNodeType(Node::OBJECT_DYNAMIC);
	omd->setVertexFormat(attributesPoint, 1);

	for (int i = 0; i < 3; i++)
	{
		vec4 vertex = vec4(i * 0.7, 0, 0, 1.0f);
		omd->addVertexFloat(0, vertex, 4);
		omd->addIndex(i);
	}

	omd->flushVertex();
	omd->flushIndices();

	MaterialPtr mat = Materials::get()->findMaterial("pthouse");
	omd->setMaterial(mat, "*");
	omd->setEnabled(1);
}

ptHouse.basemat

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

And the shader without any change

1438720956_2019-10-0210-16-22UNIGINEEvaluationKit(NOTFORCOMMERCIALUSE).png.f026c023edc94200f3fa03ee36fa331a.png

/Roberto

Link to comment
  • silent changed the title to [SOLVED] About GEOM_TYPE_IN on shaders how I can IN a vertex Point.
×
×
  • Create New...