Limonada wrote:Thanks for the attention
The critical part of the shader is this:
- Code: Select all
o.pos = UnityObjectToClipPos (v.vertex);
//Vertex snapping
float4 snapToPixel = o.pos;
float4 vertex = snapToPixel;
vertex.xyz = snapToPixel.xyz / snapToPixel.w;
vertex.x = floor((_HorizontalRes / 2) * vertex.x) / (_HorizontalRes / 2);
vertex.y = floor((_VerticalRes / 2) * vertex.y) / (_VerticalRes / 2);
vertex.xyz *= snapToPixel.w;
o.pos = vertex;
This part needs to happen at the beginning. The problem of doing this is that the Unity's surface shader applies another UnityObjectToClipPos outside my control, distorting everything. Since Amplify Shader writes a surface shader, the same problem happens. I tried to do this operation and then convert back to object space (ugly hack), but couldn't do it properly, I'm not even sure if it's possible (I'm a tech artist, never had a deep understanding of the math behind those matrices).
I have this shader partially working as a fragment shader, but I was trying to convert it to Amplify to make it more friendly to other artists. I thought that the custom template could be used, but if the lighting calculations need to be done in the template as you said, the amplify shader version will still be a black box to the artists, defeating the purpose.
It looks like that my only option is making this work in a surface shader. Is it possible to convert the vertices back to object space? Or there's another way to get the same result without using clip space calculations?
While you may be able to make this work in a Surface Shader, it would require more calculations and research on this type of shaders, as they provide several built-in functions and features that will most likely need to be tweaked or heavily manipulated to perform according to your intended results.
It would definitely be possible to achieve this effect in a Custom Shader since you'd be able to build it from the ground up with only the bare essentials, and perform all the needed math on your side without having to look into the Surface Shader's core.
Having this kind of full control does require advanced knowledge on shader language, but then again this scenario is very specific and not that obvious for the average user.
Unfortunately, we're not sure what else to recommend for now as we are currently unable to tackle custom shader development to experiment on this type of shader, perhaps at a later time since it would likely become an useful addition to the wiki, but we can't really guarantee it.
Please let us know if you have any further questions, thanks!