Baking ambient occlusion to vertexcolors

Hi guys,

We are testing out unreal for a project which we currently have up and running in unity. In this project we are baking our own lighting info on the fly since we need to support generated levels and destructible geometry. We bake to vertexcolors. I made a quick search and found a post stating that you cannot change vertexcolor attributes runtime.

Is this true, and if it is, would it be a big deal for me to change the sourcecode to support it?


Hey SkurkSE -

Yes currently you cannot change Vertex Color at runtime. However you can download the source code from GitHub and tweak to your specifications. Your modified Source could then be shared with your team as long as they have a license to use the engine as well and if you would like to you can also post a pull request on GitHub and our developers will evaluate whether it can go into the full engine version.

Hopefully that will get you started -

Eric Ketchum

I managed todo this without changing any sourcecode btw. I simply ran the actual vertex buffer update on the renderthread. I will post the code when i get home if i remember.

As promised I am answering myself with code example for anyone finding the post later.

Updating the buffer itself is pretty straight forward. This is a STATIC method which makes all vertices red:

    static void UpdateVertexColors(AAmboccTest *param1);

    void AAmboccTest::UpdateVertexColors(AAmboccTest *param1)
    	UStaticMesh *mesh = param1->TheMesh->StaticMesh;
    	FColorVertexBuffer *pColBuffer = &(mesh->RenderData->LODResources[0].ColorVertexBuffer);
    	uint32 cVtx = pColBuffer->GetNumVertices();
    	FColor* Buffer = (FColor*)RHILockVertexBuffer(pColBuffer->VertexBufferRHI, 0, cVtx*sizeof(FColor), RLM_WriteOnly);
    	for (uint32 i = 0; i < cVtx; i++)
    		FColor *pcol = Buffer + i;
    		pcol->R = 255;
    		pcol->G = 0;
    		pcol->B = 0;

TheMesh in the above example is a UStaticMeshComponent. The trick is that this code needs to be run on the renderthread in order to lock/unlock the buffers. I did this by queueing a this method as a rendercommand with itself as the parameter :


Thats it. Now to the problem of duplicating mesh vertexbuffers :frowning: