Can't access POP Tex / UV in GLSL MAT

Hey guys,

I’ve been trying to write a GLSL MAT for POPs that uses the POP Texture. I have the Tex attribute but using TDTexCoord(0) yields 0,0,0. The same MAT works perfectly on SOPs. Any ideas? Happy to write the shader code below but figured I wouldn’t do it right away to not spam.

TYA!

Omer

Hi @jaomer

the Write a GLSL Material article on the wiki has some info on that:

Other Attributes
All other attributes you want to use need to be declared in your shader code. are passed as custom attributes. For forward compatibility with POPs in the future, these attributes should be declared using the ‘Attributes’ page on the GLSL MAT. The declared attributes can be accessed via a function call to TDAttrib_AttribName(). For example if you declare a custom attribute called ‘life’. You would access it in the shader using TDAttrib_life().

For convenience TDTexAttrib_AttribName(uint textureLayer) returns TDAttrib_AttribName() for POPs and uv[textureLayer] for SOPs so shader code can be more easily shared between POPs and SOPs

For POPs the attribute value for any vertex can be accessed by specifying a vertex index argument.

TDAttrib_AttribName(uint arrayIndex) = TDAttrib_AttribName(arrayIndex, gl_VertexID); //vertIndex is optional, defaults to gl_VertexID
TDAttrib_AttribName() = TDAttrib_AttribName(0, gl_VertexID);
//for points and primitive attributes lookups are performed based on the vertex;

const uint cTDAttribArraySize_AttribName //constant with size of array for array attributes

Other POP Attributes

To access any POP attribute by element index, you can use the Buffers page:

TDBuffer_AttribName(uint elementIndex) = TDBuffer_AttribName(elementIndex, 0); //arrayIndex is optional, defaults to 0

const uint TDBufferLength_AttribName(); //length of buffer
const uint cTDBufferArraySize_AttribName; //constant with size of array for array attributes```

Often times I make use of the Phong MAT’s Output Shader option if I’m not sure about naming conventions.

cheers
Markus

Thanks Markus. I tried this to no avail. Can you confirm my workflow is correct:

Create Box POP → Create Tex attribute (either in Box or after) → Create Geometry

in GLSL Mat, add the “Tex” attribute to the Attributes page (is this needed?)

In the Vertex shader, add an output attribute Vec3 Tex. In the Vertex shader main(), add oVert.Tex=TDTexAttrib_Tex(0), or TDAttrib_Tex()

In my pixel shader I tried to output the incoming iVert.tex to oFragColor[0] and got nothing.

Appreciate your patience & support as I’m fairly new to this world.

Many thanks

Omer

Hi @jaomer,

almost:

  1. on the Attributes page of the GLSL Mat, add the Tex attribute and set the Type to “float3”
  2. in the vertex shader create the output struct to send over the texture coordinates
  3. assign TDTexAttrib_Tex(0) to a member of the output struct
  4. on the pixel shader, assign the incoming texture coordinates to the color.

Vertex Shader

// Example Vertex Shader
out Vertex
{
	vec4 texCoord0_Tex;
} oVert;
void main() 
{
	{
	oVert.texCoord0_Tex.stp = TDTexAttrib_Tex(0);
	}
	vec3 pos = TDPos();
	vec4 worldSpacePos = TDDeform(pos);
	gl_Position = TDWorldToProj(worldSpacePos);
#ifndef TD_PICKING_ACTIVE
#else // TD_PICKING_ACTIVE
	// This will automatically write out the nessessary values
	// for this shader to work with picking.
	// See the documentation if you want to write custom values for picking.
	TDWritePickingValues();
#endif // TD_PICKING_ACTIVE
}

Pixel Shader

// Example Pixel Shader

// uniform vec4 exampleUniform;
in Vertex
{
	vec4 texCoord0_Tex;
} iVert;

out vec4 oFragColor;
void main()
{
	TDCheckDiscard();
	vec4 color = vec4(iVert.texCoord0_Tex.stp,1.0);
	TDAlphaTest(color.a);
	oFragColor = TDOutputSwizzle(color);
}

Hope this makes sense
cheers
Markus

Markus, you’re a lifesaver. Thank you very much, and have a good rest of your week.

Omer

1 Like

As a side note, starting from a phong/PBR with the features you need and outputting the GLSL MAT (output shader on first page) is a good way to get started with expected syntax and MAT setup, see attached.
(If the GLSL MAT created doesn’t work as expected then it should be reported so it can be fixed)

TextureMappingPhongToGLSLMAT.toe (5.8 KB)

Edit never mind, I saw @markus also mentionned that, but here’s a toe in case it’s helpful!