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 #19

Open
Meldeber opened this issue Jan 19, 2025 · 0 comments
Open

Shadows #19

Meldeber opened this issue Jan 19, 2025 · 0 comments

Comments

@Meldeber
Copy link

Meldeber commented Jan 19, 2025

amazing shader really . i modified shader . now objects with this shader they are casting shadows but they don't receive . is there anyone who can help me out?
here is my modified shader :

Shader "psx/vertexlit" {
Properties{
_MainTex("Base (RGB)", 2D) = "white" {}
}
SubShader{
Tags { "RenderType" = "Opaque" }
LOD 200

    Pass {
        Lighting On
        CGPROGRAM

            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct v2f
            {
                fixed4 pos : SV_POSITION;
                half4 color : COLOR0;
                half4 colorFog : COLOR1;
                float2 uv_MainTex : TEXCOORD0;
                half3 normal : TEXCOORD1;
            };

            float4 _MainTex_ST;
            uniform half4 unity_FogStart;
            uniform half4 unity_FogEnd;

            v2f vert(appdata_full v)
            {
                v2f o;

                // Vertex snapping
                float4 snapToPixel = UnityObjectToClipPos(v.vertex);
                float4 vertex = snapToPixel;
                vertex.xyz = snapToPixel.xyz / snapToPixel.w;
                vertex.x = floor(160 * vertex.x) / 160;
                vertex.y = floor(120 * vertex.y) / 120;
                vertex.xyz *= snapToPixel.w;
                o.pos = vertex;

                // Vertex lighting 
                o.color = float4(ShadeVertexLightsFull(v.vertex, v.normal, 4, true), 1.0);
                o.color *= v.color;

                float distance = length(mul(UNITY_MATRIX_MV, v.vertex));

                // Affine Texture Mapping
                float4 affinePos = vertex; //vertex;                
                o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex);
                o.uv_MainTex *= distance + (vertex.w * (UNITY_LIGHTMODEL_AMBIENT.a * 8)) / distance / 2;
                o.normal = distance + (vertex.w * (UNITY_LIGHTMODEL_AMBIENT.a * 8)) / distance / 2;

                // Fog
                float4 fogColor = unity_FogColor;

                float fogDensity = (unity_FogEnd - distance) / (unity_FogEnd - unity_FogStart);
                o.normal.g = fogDensity;
                o.normal.b = 1;

                o.colorFog = fogColor;
                o.colorFog.a = clamp(fogDensity, 0, 1);

                // Cut out polygons
                if (distance > unity_FogStart.z + unity_FogColor.a * 255)
                {
                    o.pos.w = 0;
                }

                return o;
            }

            sampler2D _MainTex;

            float4 frag(v2f IN) : COLOR
            {
                // Darken the texture by multiplying with a factor (0.8 in this case)
                half4 c = tex2D(_MainTex, IN.uv_MainTex / IN.normal.r) * IN.color * 0.5;
                half4 color = c * (IN.colorFog.a);
                color.rgb += IN.colorFog.rgb * (1 - IN.colorFog.a);
                return color;
            }
        ENDCG
    }

    // Shadow pass
    Pass {
        Tags { "LightMode"="ShadowCaster" }
        CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #include "UnityCG.cginc"

            struct v2f
            {
                float4 pos : SV_POSITION;
            };

            v2f vert(appdata_full v)
            {
                v2f o;
                o.pos = UnityObjectToClipPos(v.vertex);
                return o;
            }

            half4 frag(v2f IN) : SV_Target
            {
                return half4(0, 0, 0, 0);
            }
        ENDCG
    }
}

}

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

1 participant