Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadows? #7

Open
CAREFACE720 opened this issue Apr 18, 2018 · 6 comments
Open

Shadows? #7

CAREFACE720 opened this issue Apr 18, 2018 · 6 comments

Comments

@CAREFACE720
Copy link

CAREFACE720 commented Apr 18, 2018

Hey, I've been using this amazing shader, really love going back in time!

Is there any chance for you to add shadows aswell? Like simple circle pixelated shadows on the ground of the meshes, that would be great!

@CAREFACE720
Copy link
Author

Well, nevermind, I managed to find a solution for them

@benguiden
Copy link

Hey was it an easy solution and could you guide me in the right direction to getting shadows working?

@CAREFACE720
Copy link
Author

CAREFACE720 commented Apr 23, 2018

Well, might not be the best method but I guess it works fine for my project at least.

I am using the BlobShadowProjector from the Standard Assets. You can follow these steps if you do not know about it.

With this projector, the shadow gets messed up on the floor that has the Psx shader, so you have to edit the Psx shader and make it to ignore the Projector, something like this in the Psx shader you're using for the floor, at the Tags section:
SubShader{ Tags { "RenderType" = "Opaque" "IgnoreProjector"="True" }

And the trick is, to create a fake floor, that is invisible and only receives the shadows, and put it like 0.1 above the floor that has the Psx shader.
So you need another shader for the fake floor, which is this one that I found in the unity forums, and I already set it IgnoreProjector to False, so you can just create a new shader and copy/paste this:

Shader "psx/ShadowForPSXshader" {
Properties {
    _Color ("Shadow Color", Color) = (1,1,1,1)
    _ShadowInt ("Shadow Intensity", Range(0,1)) = 1.0
    _Cutoff ("Alpha cutoff", Range(0,1)) = 1.0
}
 
 
SubShader {
    Tags {
        "Queue"="AlphaTest"
        "IgnoreProjector"="False"
        "RenderType"="TransparentCutout"
    }
    LOD 200
    ZWrite off
    Blend zero SrcColor
 
CGPROGRAM
#pragma surface surf ShadowOnly alphatest:_Cutoff
 
fixed4 _Color;
float _ShadowInt;
 
struct Input {
    float2 uv_MainTex;
};
 
inline fixed4 LightingShadowOnly (SurfaceOutput s, fixed3 lightDir, fixed atten)
{
    fixed4 c;
    c.rgb = lerp(s.Albedo, float3(1.0,1.0,1.0), atten);
    c.a = 1.0-atten;
    return c;
}
 
 
void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = lerp(float3(1.0,1.0,1.0), _Color.rgb, _ShadowInt);
    o.Alpha = 0;
}
ENDCG
}
 
Fallback "Transparent/Cutout/VertexLit"
}

Final step is to create a material and drag this shadow shader that you just created into it, then drag the material on the objects you wants them to receive the blobshadows on it.
I've only tested on plain floors, so I don't know how it goes with slopes, probably fine, just don't forget to put the fake floor above the floor that has the Psx shader.
If you want a more pixelated shadow, just edit the texture that came with the BlobShadowBrojector, and apply a mosaic filter on it at photoshop or something.

Hope it helps, and good luck. Heres the result on my project:
image

@benguiden
Copy link

Oh fantastic I'll try that method out 😁 Thanks for your help!

@CAREFACE720
Copy link
Author

Edited the shader, it had some mistakes. The "Alpha cutoff" must be set to value 1, and o.alpha to 0 value.

To recap, in case someone trying to achieve this:

  • Set up a blobShadow from the Standard Asset Store.
  • Open and edit the Psx Shaders and add at the tags section this line of code to ignore the blobShadow:
    "IgnoreProjector"="True"
  • Create a New Shader and copy/paste the Shadow code above.
  • Create a New Material and drag the Shadow Shader into it.
  • Apply the Edited Psx Shader into your Ground Object.
  • Create a new child Plane object (a fake floor) into your Ground object, and apply the Shadow Material.
  • Lift the Plane by 0.1 from the Ground.
  • With a blobShadow applied on the character, it should now cast a nice shadow on the fake floor with no flickering.

@TheTimeKeepers
Copy link

Edited the shader, it had some mistakes. The "Alpha cutoff" must be set to value 1, and o.alpha to 0 value.

To recap, in case someone trying to achieve this:

* [Set up](https://www.youtube.com/watch?v=hQcZA3dYGxg) a blobShadow from the Standard Asset Store.

* Open and edit the Psx Shaders and add at the tags section this line of code to ignore the blobShadow:
  `"IgnoreProjector"="True"`

* Create a New Shader and copy/paste the Shadow code above.

* Create a New Material and drag the Shadow Shader into it.

* Apply the Edited Psx Shader into your Ground Object.

* Create a new child Plane object (a fake floor) into your Ground object, and apply the Shadow Material.

* Lift the Plane by 0.1 from the Ground.

* With a blobShadow applied on the character, it should now cast a nice shadow on the fake floor with no flickering.

Hey just wanted to thank you for making this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants