Pass {
Tags { "RenderType" = "Opaque" }
Stencil {
ReadMask 0
WriteMask 0
Comp Always
Pass Replace
Fail Keep
ZFail Keep
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f {
float2 uv : TEXCOORD0;
float4 pos : SV_POSITION; // Clip space position
float3 worldPos : TEXCOORD1; // World position for reflections
};
// Uniforms
uniform float4 _CustomProjectionParams; // Renamed to avoid conflict
uniform float4 hlslcc_mtx4x4unity_ObjectToWorld[4];
uniform float4 hlslcc_mtx4x4unity_MatrixVP[4];
uniform float4 _MainTex_ST;
sampler2D _MainTex;
sampler2D _ReflectionMetal;
uniform float _ReflectionRow;
// Vertex Shader
v2f vert(appdata v) {
v2f o;
// Object to World transformation
float4 worldPosition = mul(hlslcc_mtx4x4unity_ObjectToWorld[0], v.vertex);
worldPosition += v.vertex.y * hlslcc_mtx4x4unity_ObjectToWorld[1]; // Y position adjustment
worldPosition += v.vertex.z * hlslcc_mtx4x4unity_ObjectToWorld[2]; // Z position adjustment
// Transform position to clip space
o.pos = mul(hlslcc_mtx4x4unity_MatrixVP[0], worldPosition);
// UV transformation
o.uv = v.uv * _MainTex_ST.xy + _MainTex_ST.zw;
// Save the world position
o.worldPos = worldPosition.xyz;
return o;
}
// Fragment Shader
half4 frag(v2f i) : SV_Target {
// Sample the main texture
float4 mainColor = tex2D(_MainTex, i.uv);
// Compute reflection
float4 reflectionColor = tex2D(_ReflectionMetal, i.uv * _ReflectionRow);
// Combine colors based on reflection intensity
half4 finalColor = (mainColor * (1.0 - reflectionColor.w)) + (reflectionColor * reflectionColor.w);
return finalColor;
}
ENDCG
}
}
}
To remove the X-ray shader-related code and functionality from the provided shader code, you will primarily focus on eliminating definitions related to the X-ray, specifically the _XRayItemStencilRef property, any associated stencil configurations, and updates to the fragment shader that pertain to X-ray effects.
Here’s the revised shader code without the X-ray related elements:
Removed the _XRayItemStencilRef property from the Properties block.
Eliminated any lines that are related to X-ray functionality in the shader, specifically related to stencil operations for X-ray effects (none were found in the provided code, but ensure that any references are removed if they exist in a larger context).
The shader continues to maintain its basic functionality without any X-ray-related logic.
This code should work in your Unity project as long as you have no other dependencies on the X-ray features in other scripts or shaders.