#Hi, I want to make a shader so that the object appears only if you look at it with a flashlight

1 messages · Page 1 of 1 (latest)

sacred prism
#

Everything is ready, but on some objects there is an artifact that highlights it.
Here's custom func.:
void surf_float(
float3 _WorldPos,
float3 _LightPos,
float3 _LightDir,
float _LightAngleCos,
float _Smoothness,
float3 _BakedLightPos,
float3 _BakedLightDir,
float _BakedLightAngleCos,
float _TextureAlpha,

out float intersectionFactor,
out float combinedVisibility,
out float alphaOutput

)
{
float3 toPixel = normalize(_WorldPos - _LightPos.xyz);
float dotProduct = dot(toPixel, _LightDir);
float currentVisibility = smoothstep(_LightAngleCos, _LightAngleCos + _Smoothness, dotProduct);

float3 toPixelBaked = normalize(_WorldPos - _BakedLightPos.xyz);
float dotProductBaked = dot(toPixelBaked, _BakedLightDir);
float bakedVisibility = smoothstep(_BakedLightAngleCos, _BakedLightAngleCos + _Smoothness, dotProductBaked);

combinedVisibility = currentVisibility * _TextureAlpha;

float visibilityFade = smoothstep(0.0, _Smoothness, min(currentVisibility, bakedVisibility));
float intensityFade = 1.0 - visibilityFade;

intersectionFactor = 1.0 - smoothstep(0.0, 0.2, intensityFade);

alphaOutput = combinedVisibility * _TextureAlpha;
alphaOutput = max(alphaOutput, 0.01 * _TextureAlpha);

}
alphaOutput multiplies with sample texture of main texture and goes to Alpha of master Node. How to fix it, pls

soft grove
#

What does it mean that "on some objects there is an artifact that highlights it"?

soft grove
# sacred prism Look:

I think you mean the transparent area of the card/stamp is cutting through the alpha of the glow behind it?

sacred prism
#

Something like it

soft grove
#

Since the pink thing doesn't seem to have any semi-transparency, the simplest thing to do is to make it opaque instead of transparent and enable alpha clipping

sacred prism
#

If i change to opaque, i have this, but it's definitely not, what i want

deft yew
#

Did you try alpha clipping as Spazi also mentioned?

sacred prism
#

Yep

#

I mean, if i choose transparent and alpha clipping nothing changed

#

If i choose opaque, there is no this option

soft grove
soft grove
#

It feels like we are missing some important piece of context

sacred prism
soft grove
sacred prism
#

I found problem

#

The problem is that this leaf lies as if in a box. The box is considered a solid object and Unity thinks that the leaf is inside another body and shines through. I made a texture with a transparent center and this is what I have.

#

If you lift the sheet as if from the box, the error disappears.

soft grove
#

I don't really understand what that means

soft grove
#

Or one of the other settings exposes it

#

I don't recall the HDRP graphs inside out, but I can't think of any situation when alpha clipping wouldn't be available to opaque materials

sacred prism
soft grove
# sacred prism ъ

The first image shows the right spot, but it's Transparent again, not Opaque