Amplifying your potential.

Manipulating vertex in projection space

Node-based Shader Editor
4 posts • Page 1 of 1

Manipulating vertex in projection space

Postby Limonada » Fri Dec 08, 2017 8:21 pm

Hello!

I'm working on a retro shader that emulates a lack of vertice precision, like how PSX behaved.
To do that, I need to manipulate coordinates in projection space. Is this possible using surface shader or custom lighting?

I managed to do that using a custom template, but then I couldn't use the lighting nodes anymore, like "light attenuation", etc... and I need the shader to be lit.
Limonada
 
Posts: 2
Joined: Fri Dec 08, 2017 7:29 pm

Re: Manipulating vertex in projection space

Postby Amplify_Borba » Mon Dec 11, 2017 2:21 pm

Limonada wrote:Hello!

I'm working on a retro shader that emulates a lack of vertice precision, like how PSX behaved.
To do that, I need to manipulate coordinates in projection space. Is this possible using surface shader or custom lighting?

I managed to do that using a custom template, but then I couldn't use the lighting nodes anymore, like "light attenuation", etc... and I need the shader to be lit.


Hello Limonada, thank you for getting in touch and for your support!

By choosing to use a template, you're responsible for performing all the illumination calculations since the lighting nodes we provide make use of Unity's lighting system.

If it would be possible for you to provide us your shader sample in order for us to see what kind of operations you're doing, we could investigate if it would be possible to do so in a Surface Shader in order to avoid the aforementioned lighting calculations.

Looking forward to your reply!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 915
Joined: Mon Jul 24, 2017 9:50 am

Re: Manipulating vertex in projection space

Postby Limonada » Thu Dec 21, 2017 4:16 pm

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?
Limonada
 
Posts: 2
Joined: Fri Dec 08, 2017 7:29 pm

Re: Manipulating vertex in projection space

Postby Amplify_Borba » Fri Dec 22, 2017 3:49 pm

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!
Customer Relations at Amplify Creations
Learn more about our offering: Amplify Creations Products
Amplify Shader Editor won the Asset Store Best Tool Award - Thank you for your support!
User avatar
Amplify_Borba
 
Posts: 915
Joined: Mon Jul 24, 2017 9:50 am


4 posts • Page 1 of 1

Return to Amplify Shader Editor

Who is online

Users browsing this forum: No registered users and 2 guests

cron