+18
На рассмотрении
Projector Tutorial
Would anyone have any examples on how to use the Projection Parameters to make a shader work with Unity Projectors? I am using them as a decal type system and the shaders that come with Unity just dont cut it. Thanks!!
Сервис поддержки клиентов работает на платформе UserEcho
I'm attempting the same:
what you need is:
uniform float4x4 _Projector;
(correctly naming a matrix property in SF works for this)
then within "vert" :
o.posProjector = mul(_Projector, v.vertex);
then within "frag" :
if (i.posProj.w <= 0.0) return float4(0,0,0,0); // behind projector, ignore
return tex2D(_MainTex, i.posProjector.xy / i.posProjector.w); // return decal
Generally the above would be used in conjunction with a falloff:
vert:
o..projClip = mul(_ProjectorClip, input.vertex);
frag:
float4 fallOff = tex2Dproj(_FalloffTex, i.projClip);
result:
return float4( tex2D(_MainTex, i.posProjector.xy / i.posProjector.w), fallOff.a );
I spent an hour trying to learn shader forge hoping it'd speed up this crazy projector I have to make. Kinda sad it seems impossible (currently).
[EDIT]
in my opinion the most important node (for this) that shader forge is missing is:
Geometry Data/Projector Position :: o.posProjector = mul(_Projector, v.vertex);
mul() is the matrix multiply node, so it should work! Could you try it out?
Apologies I'm still learning shader forge. How do I use "v.vertex" as an input to matrix multiplier? That's where I got stuck.
It turns out it was just too much work & near impossible to get a projection shader working in Shader Forge, which is sad, but it doesn't mean Shader Forge didn't help me. In the end the best route was to create the shader, and then edit the output result manually and turn it into a projection shader by hand. I'm hoping it'll be supported some time in the future, but for now, at least, I managed to get my blood splatter projection shader working.
Tools: Allegorithmic Substance (procedural textures making random splat shapes in-game) -> Shader Forge base custom shader -> manually edited and turned into a projection shader
Result:
For those curious about implementation.
Allegorithmic Substance:
Shader Forge Shader:
That UV on the left (feeding into the relay) is what needs to be replaced with projection UVs but I was unable to figure that part out using Shader Forge :(
Really sorry to revive this years-old thread, but I'm also looking to build a decal shader in Shader Forge.
Judging by those two comments below, your shader seems to work. So can you, or anyone, please reupload a screenshot that is actually readable so I may also try it out?
Hello Clive, I cannot thank you enough for making this great contribution, I had agreed with Joachim in providing a couple of shaders that already implemented this to have an example to start working on a node that could allow us to achieve this, but I have had enormous amounts of work with very close deadlines. Joachim was very comprehensive with this feature since is a thing that can empower SF shaders with such awesome realism.
If the code that you shared is all what is needed to build the projection shader this can really help Joachim to build it and published it in the next version or so, if there is new breakthrough, like the code that you manually programmed in the shader, please share with us to count with this so usefully feature in Shader Forge.
Thank you all!
Ahhh, attempting to do the same thing! I'm making a spinning projection in Unity - works and shows up, but always appears at (0,0,0), despite where the prefab is in worldspace.
Thanks for any help!