Пример #1
0
        public FragmentInput VS(VertexInput input)
        {
            SN.Vector4 worldPos  = SMath.Mul(World, new SN.Vector4(input.Position, 1));
            SN.Vector4 worldNorm = SMath.Mul(World, new SN.Vector4(input.Normal, 0));

            FragmentInput output;

            output.SystemPosition = SMath.Mul(WorldViewProjection, new SN.Vector4(input.Position, 1));
            output.PositionWS     = new SN.Vector3(worldPos.X, worldPos.Y, worldPos.Z);
            output.NormalWS       = new SN.Vector3(worldNorm.X, worldNorm.Y, worldNorm.Z);
            output.TexCoords      = input.TexCoords;

            return(output);
        }
Пример #2
0
        public SN.Vector4 FS(FragmentInput input)
        {
            SN.Vector3 normalWS = SN.Vector3.Normalize(input.NormalWS);

            if (!SMath.IsFrontFace)
            {
                normalWS = SN.Vector3.Negate(normalWS);
            }

            SN.Vector3 v     = SN.Vector3.Normalize(CameraPosition - input.PositionWS);
            SN.Vector3 L     = SN.Vector3.Normalize(LightPosition - input.PositionWS);
            float      nDotL = SMath.Saturate(SN.Vector3.Dot(normalWS, L));

            return(SMath.Sample(DiffuseTexture, DiffuseSampler, input.TexCoords) * DiffuseColor * nDotL);
        }