0
Completed

Vertex offset mode: relative/absolute switching

Gabe Newell 4 weeks ago • updated 4 weeks ago 2

I have parts of my shader that require "absolute" and other parts that require the "relative" mode to work properly. What can I do to use both modes in a single script? Or rather what can I do to make a part of a shader turn from absolute into a relative mode?

Answer

Answer
Completed

That's usually a matter of either transforming with the local to world / world to local matrices, and/or adding the object position to the portion you want to be relative. Either make it absolute, and add the object position to the parts that should be relative, or make it relative, and subtract the object position from the parts that should be absolute. There may be additional quirks when it comes to static batching, as object position won't be valid in that case. And some matrix hackery might be necessary if you're dealing with rotated and scaled objects

Answer
Completed

That's usually a matter of either transforming with the local to world / world to local matrices, and/or adding the object position to the portion you want to be relative. Either make it absolute, and add the object position to the parts that should be relative, or make it relative, and subtract the object position from the parts that should be absolute. There may be additional quirks when it comes to static batching, as object position won't be valid in that case. And some matrix hackery might be necessary if you're dealing with rotated and scaled objects