Search Unity

Question Help with ortographic camera and inverted hull outline

Discussion in 'Shaders' started by Gabriel-Oliveira-Almeida, Jan 4, 2023.

  1. Gabriel-Oliveira-Almeida

    Gabriel-Oliveira-Almeida

    Joined:
    Jan 13, 2016
    Posts:
    5
    Hi!
    This code is a vertex shader to create a inverted hull outline, and have a problem whit this code and orthographic camera.
    Is almost right, but some vertex stay in odd positions and create some artifacts.
    Any help in make this code orthographic compatible?

    Code (CSharp):
    1. VertexOutput output = (VertexOutput)0;
    2. input.positionOS.xyz = DistortionVertex(input.positionOS.xyz, _DistortionFactor);
    3. float3 objWS = TransformObjectToWorld(input.positionOS.xyz);
    4. float eyeDepth = -TransformWorldToView(input.positionOS.xyz).z;
    5. float3 outlineMult = (( input.normalOS * 2E-05 ) * (( _EnableCameraDistanceMult * eyeDepth * input.vertexColor.g)));
    6. float3 dirCamera = ObjSpaceViewDir( float4( outlineMult , 0.0 ));
    7. float4 distCamera = normalize( ( float4( dirCamera , 0.0 ) - input.positionOS ));
    8. float rampDepth = clamp( ( input.vertexColor.b + _DepthOffset ) , 0.0 , 1.0 );
    9. float4 finalPos = lerp( float4(outlineMult , 0.0 ) , -distCamera , ( 1.0 - rampDepth ));
    10. finalPos += float4(input.positionOS.xyz,0);
    11. float4 clipPosition = TransformObjectToHClip(finalPos);
    12. float3 clipNormal = mul((float3x3) UNITY_MATRIX_VP, mul((float3x3) UNITY_MATRIX_M, input.normalOS));
    13. float2 offset = (normalize(clipNormal.xy) * (_OutlineSize/100) * clipPosition.w) * (input.vertexColor * 2) ;
    14. float aspect = _ScreenParams.x / _ScreenParams.y;
    15. offset.y *= aspect;
    16. clipPosition.xy += offset;
    17. output.positionCS = clipPosition;
    18. output.uv = input.uv;
    19. return output;