Jump to content
Developer Wiki and Function Reference Links ×

Questions about Using Shader Records

Cachino King

Recommended Posts

I'm having some more problems. After I successfully exported the model, I tried to export the material, but didn't understand some of the code written in the wiki: SDK:Using_Shader_Records

I looked up these functions with a few hints, But I don't know what is "fieldID". 



Shader Record Fields

The following utility routines can be used to easily get and set shader field values. Reminder: Field indices are one-based, first three fields are family, prototype, and version, and all colors use three fields each.

Shader record parameters can be retrieved and/or modified using SDK RecordHandler functions.


double GetShaderRecordDouble(MCObjectHandle shaderRecord, short fieldID)
	double result = 0.0;

	TRecordHandler recordHandler(shaderRecord);
	TRecordItem recordItem(kFieldReal);

	double doubleValue = 0.0;
	if (VERIFYN(kDaveD, recordHandler.GetFieldObject(fieldID, recordItem)) && VERIFYN(kDaveD, recordItem.GetFieldValue(doubleValue)))
		result = doubleValue;

	return result;




Is fieldID a Prototype value? Can I get transparency by writing it this way? 

	if (hMaterial == NULL)
		return 0.0f;

	MCObjectHandle	hTransShaderRec = ::GS_GetShaderRecord(gCBP, hMaterial, kShaderFamily_Transparency);
	if (hTransShaderRec == NULL)
		return 0.0f;

	float			transparency = 0.0f;

	VWTextureShaderBase transparencyShader(hTransShaderRec);
	transparency = transparencyShader.GetShaderRecordDouble(kShaderPrototypeTransparency_Plain);

	return transparency;


Also I found a function: 

GetParamReal(const TXString& univParamName) const;

Does this function get data about object materials? Where can I see an enumeration of univParamName? 

Link to comment

Field id is not the prototype value, but you don't really have to know the field id anyway.

You need an additional step to read the transparency value, in case you have a plain transparency shader.

Shaders are divided into families and families are divided into prototypes.


See the difference in the texture edit dialog:



You can use VWFC::VWTextureShaderBase::GetShaderRecordFamilyAndPrototype or each of the prototype helpers like VWTextureShaderTransparencyPlain::IsShaderRecordObject to determine what prototype it is.


After figuring out what prototype it is you can use the helpers to read the values:

		auto recordHandle = gSDK->GetShaderRecord(hMaterial, kShaderFamily_Transparency);

		// option 1
		if (VWFC::VWTextureShaderTransparencyPlain::IsShaderRecordObject(recordHandle))
			VWFC::VWTextureShaderTransparencyPlain shader{ recordHandle };
			auto opacity = shader.GetOpacity();

		// option 2
		auto family = kShaderFamily_Undefined;
		auto prototype = 0;
		if (!VWFC::VWTextureShaderBase::GetShaderRecordFamilyAndPrototype(recordHandle, family, prototype))
			// "None" Transparency Shader 

		if (prototype == kShaderPrototypeTransparency_Image)
			VWFC::VWTextureShaderTransparencyImage shader{ recordHandle };
			// read image file content with VectorWorks::Imaging::ICompressedImage
			auto imageHandle = shader.GetImage();
			auto refraction = shader.GetRefraction();
			auto bluriness = shader.GetTransparencyBlurriness();
			// ...


GetOpacity uses the field Id to get the value from the record. In this case it's 4, which is a constant that is only specific to plain transparency.

You can see those field values when you look at the record handles in the debug menu, or if you look at the .cpp files of the prototype helpers.

But as I said before, if you use the helper you don't have to know the field id is.



Edited by JHangstoerfer
Link to comment

Thank you very much! Now I understand the structure. 

On 3/15/2022 at 8:32 PM, JHangstoerfer said:
// read image file content with VectorWorks::Imaging::ICompressedImage

How do I use VectorWorks::Imaging::ICompressedImage if I want to export image maps?

I need Filepath, Brightness, Width, Height, uv and Rotation data, and I found some of them in struct CompressedImageDesc. 

So what do I do if I want to get data in this struct?

Link to comment
3 hours ago, Cachino King said:

Thank you very much! Now I understand the structure. 

How do I use VectorWorks::Imaging::ICompressedImage if I want to export image maps?

I need Filepath, Brightness, Width, Height, uv and Rotation data, and I found some of them in struct CompressedImageDesc. 

So what do I do if I want to get data in this struct?


I've only used GetImageStream from ICompressedImage.

You don't get a file path to the image because the file content of the images is embedded in the Vectorworks project.

You either use the file content bytes directly or you have to write them to the filesystem if you really want a Filepath. I think the compress image api can also write the files using the Save() call.


	VectorWorks::Imaging::ICompressedImagePtr imageApi(VectorWorks::Imaging::IID_CompressedImage);
	auto err = imageApi->CreateFromObject(imageHandle); // check err

	// Contains jpg or png data
	VectorWorks::Imaging::ImageStream imageStream{};
	err = imageApi->GetImageStream(imageStream); // check err
	// Use imageStream.bufferPtr as std::byte[] with size imageStream.bufferSizeInBytes

	// Never used this but it looks like meta information about the image
	VectorWorks::Imaging::CompressedImageDesc desc{};
	err = imageApi->GetCompressedImageDesc(desc); // check err


I don't know where you would fine extra info like brightness, uv and rotation but it sounds like this would be either in the material or in the geometry. ICompressedImage is just for the raw image file content.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...