protot/3rdparty/bgfx/3rdparty/glsl-optimizer/tests/fragment/z-unishader-dirlm-outES3Met...

218 lines
9.4 KiB
Plaintext

#include <metal_stdlib>
#pragma clang diagnostic ignored "-Wparentheses-equality"
using namespace metal;
struct xlatMtlShaderInput {
float4 xlv_TEXCOORD0;
float4 xlv_TEXCOORD1;
float3 xlv_TEXCOORD2;
float4 xlv_TEXCOORD3;
float3 xlv_TEXCOORD4;
float4 xlv_TEXCOORD5;
};
struct xlatMtlShaderOutput {
half4 _fragData [[color(0)]];
};
struct xlatMtlShaderUniform {
float3 _WorldSpaceCameraPos;
float _DetailNormalMapScale;
float _BumpScale;
float _Exposure;
float4 _Color;
float _SelfIllumScale;
};
fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]]
, texture2d<half> _MainTex [[texture(0)]], sampler _mtlsmp__MainTex [[sampler(0)]]
, texture2d<half> _DetailAlbedoMap [[texture(1)]], sampler _mtlsmp__DetailAlbedoMap [[sampler(1)]]
, texture2d<half> _AlphaMap [[texture(2)]], sampler _mtlsmp__AlphaMap [[sampler(2)]]
, texture2d<half> _Occlusion [[texture(3)]], sampler _mtlsmp__Occlusion [[sampler(3)]]
, texture2d<half> _DetailNormalMap [[texture(4)]], sampler _mtlsmp__DetailNormalMap [[sampler(4)]]
, texture2d<half> _BumpMap [[texture(5)]], sampler _mtlsmp__BumpMap [[sampler(5)]]
, texture2d<half> _SpecGlossMap [[texture(6)]], sampler _mtlsmp__SpecGlossMap [[sampler(6)]]
, texture2d<half> _ShadowMapTexture [[texture(7)]], sampler _mtlsmp__ShadowMapTexture [[sampler(7)]]
, texturecube<half> _SpecCube [[texture(8)]], sampler _mtlsmp__SpecCube [[sampler(8)]]
, texture2d<half> unity_Lightmap [[texture(9)]], sampler _mtlsmp_unity_Lightmap [[sampler(9)]]
, texture2d<half> unity_LightmapInd [[texture(10)]], sampler _mtlsmp_unity_LightmapInd [[sampler(10)]]
, texture2d<half> _SelfIllum [[texture(11)]], sampler _mtlsmp__SelfIllum [[sampler(11)]])
{
xlatMtlShaderOutput _mtl_o;
half3 lightDir_1 = 0;
half3 env_2 = 0;
float3 tmpvar_3 = 0;
float3 tmpvar_4 = 0;
tmpvar_3 = _mtl_i.xlv_TEXCOORD3.xyz;
tmpvar_4 = (((_mtl_i.xlv_TEXCOORD2.yzx * _mtl_i.xlv_TEXCOORD3.zxy) - (_mtl_i.xlv_TEXCOORD2.zxy * _mtl_i.xlv_TEXCOORD3.yzx)) * _mtl_i.xlv_TEXCOORD3.www);
float3x3 tmpvar_5;
tmpvar_5[0].x = tmpvar_3.x;
tmpvar_5[0].y = tmpvar_4.x;
tmpvar_5[0].z = _mtl_i.xlv_TEXCOORD2.x;
tmpvar_5[1].x = tmpvar_3.y;
tmpvar_5[1].y = tmpvar_4.y;
tmpvar_5[1].z = _mtl_i.xlv_TEXCOORD2.y;
tmpvar_5[2].x = tmpvar_3.z;
tmpvar_5[2].y = tmpvar_4.z;
tmpvar_5[2].z = _mtl_i.xlv_TEXCOORD2.z;
half3 normal_6 = 0;
normal_6.xy = ((_BumpMap.sample(_mtlsmp__BumpMap, (float2)(_mtl_i.xlv_TEXCOORD0.xy)).wy * (half)(2.0)) - (half)(1.0));
normal_6.xy = ((half2)((float2)(normal_6.xy) * _mtl_u._BumpScale));
normal_6.z = sqrt(((half)(1.0) - clamp (
dot (normal_6.xy, normal_6.xy)
, (half)0.0, (half)1.0)));
half3 normal_7 = 0;
normal_7.xy = ((_DetailNormalMap.sample(_mtlsmp__DetailNormalMap, (float2)(_mtl_i.xlv_TEXCOORD0.zw)).wy * (half)(2.0)) - (half)(1.0));
normal_7.xy = ((half2)((float2)(normal_7.xy) * _mtl_u._DetailNormalMapScale));
normal_7.z = sqrt(((half)(1.0) - clamp (
dot (normal_7.xy, normal_7.xy)
, (half)0.0, (half)1.0)));
half3 tmpvar_8 = 0;
tmpvar_8.xy = (normal_6.xy + normal_7.xy);
tmpvar_8.z = (normal_6.z * normal_7.z);
half3 tmpvar_9 = 0;
tmpvar_9 = normalize(tmpvar_8);
half3 tmpvar_10 = 0;
tmpvar_10 = ((half3)((float3)(tmpvar_9) * tmpvar_5));
float3 tmpvar_11 = 0;
tmpvar_11 = normalize((_mtl_i.xlv_TEXCOORD1.xyz - _mtl_u._WorldSpaceCameraPos));
half4 tmpvar_12 = 0;
tmpvar_12 = _SpecGlossMap.sample(_mtlsmp__SpecGlossMap, (float2)(_mtl_i.xlv_TEXCOORD0.xy));
half tmpvar_13 = 0;
tmpvar_13 = dot (tmpvar_12.xyz, (half3)float3(0.299, 0.587, 0.114));
half tmpvar_14 = 0;
tmpvar_14 = ((half)(1.0) - tmpvar_12.w);
half4 tmpvar_15 = 0;
tmpvar_15.xyz = ((half3)(tmpvar_11 - (float3)(((half)(2.0) * (
((half)dot ((float3)tmpvar_10, tmpvar_11))
* tmpvar_10)))));
tmpvar_15.w = (tmpvar_14 * (half)(5.0));
half4 tmpvar_16 = 0;
tmpvar_16 = _SpecCube.sample(_mtlsmp__SpecCube, (float3)(tmpvar_15.xyz), level(tmpvar_15.w));
half tmpvar_17 = 0;
tmpvar_17 = (tmpvar_16.w * tmpvar_16.w);
half2 tmpvar_18 = 0;
tmpvar_18.x = tmpvar_17;
tmpvar_18.y = (tmpvar_16.w * tmpvar_17);
env_2 = (((half3)((float3)((tmpvar_16.xyz *
dot ((half2)float2(0.7532, 0.2468), tmpvar_18)
)) * _mtl_u._Exposure)) * _Occlusion.sample(_mtlsmp__Occlusion, (float2)(_mtl_i.xlv_TEXCOORD0.xy)).x);
half4 tmpvar_19 = 0;
tmpvar_19 = unity_Lightmap.sample(_mtlsmp_unity_Lightmap, (float2)(_mtl_i.xlv_TEXCOORD4.xy));
half4 tmpvar_20 = 0;
tmpvar_20 = unity_LightmapInd.sample(_mtlsmp_unity_LightmapInd, (float2)(_mtl_i.xlv_TEXCOORD4.xy));
float3x3 tmpvar_21;
tmpvar_21[0].x = 0.816497;
tmpvar_21[0].y = -0.408248;
tmpvar_21[0].z = -0.408248;
tmpvar_21[1].x = 0.0;
tmpvar_21[1].y = 0.707107;
tmpvar_21[1].z = -0.707107;
tmpvar_21[2].x = 0.57735;
tmpvar_21[2].y = 0.57735;
tmpvar_21[2].z = 0.57735;
half3 tmpvar_22 = 0;
tmpvar_22 = (((half)(8.0) * tmpvar_20.w) * tmpvar_20.xyz);
float3 v_23 = 0;
v_23.x = tmpvar_21[0].x;
v_23.y = tmpvar_21[1].x;
v_23.z = tmpvar_21[2].x;
float3 v_24 = 0;
v_24.x = tmpvar_21[0].y;
v_24.y = tmpvar_21[1].y;
v_24.z = tmpvar_21[2].y;
float3 v_25 = 0;
v_25.x = tmpvar_21[0].z;
v_25.y = tmpvar_21[1].z;
v_25.z = tmpvar_21[2].z;
lightDir_1 = ((half3)((float3)(normalize((
((tmpvar_22.x * (half3)(v_23)) + (tmpvar_22.y * (half3)(v_24)))
+
(tmpvar_22.z * (half3)(v_25))
))) * tmpvar_5));
half3 tmpvar_26 = 0;
tmpvar_26 = normalize(lightDir_1);
lightDir_1 = tmpvar_26;
half3 lightColor_27 = 0;
lightColor_27 = (_ShadowMapTexture.sample(_mtlsmp__ShadowMapTexture, ((float2)(_mtl_i.xlv_TEXCOORD5).xy / (float)(_mtl_i.xlv_TEXCOORD5).w)).x * ((
((half)(8.0) * tmpvar_19.w)
* tmpvar_19.xyz) * dot (
clamp (((half3)(tmpvar_21 * (float3)(tmpvar_9))), (half)0.0, (half)1.0)
, tmpvar_22)));
float3 viewDir_28 = 0;
viewDir_28 = -(tmpvar_11);
half3 tmpvar_29 = 0;
tmpvar_29 = normalize(((half3)((float3)(tmpvar_26) + viewDir_28)));
half tmpvar_30 = 0;
tmpvar_30 = max ((half)0.0, dot (tmpvar_10, tmpvar_26));
half tmpvar_31 = 0;
tmpvar_31 = max ((half)0.0, dot (tmpvar_10, tmpvar_29));
half tmpvar_32 = 0;
tmpvar_32 = max ((half)0.0, ((half)dot ((float3)tmpvar_10, viewDir_28)));
half tmpvar_33 = 0;
tmpvar_33 = max ((half)0.0, ((half)dot (viewDir_28, (float3)tmpvar_29)));
half VdotH_34 = 0;
VdotH_34 = (tmpvar_33 + (half)(1e-05));
half tmpvar_35 = 0;
tmpvar_35 = (((half)1.0/((
pow (tmpvar_14, (half)4.0)
+ (half)(1e-05)))) - (half)(2.0));
half tmpvar_36 = 0;
half tmpvar_37 = 0;
tmpvar_37 = max ((half)0.0, dot (tmpvar_26, tmpvar_29));
tmpvar_36 = ((half)(0.5) + (((half)(2.0) * tmpvar_37) * (tmpvar_37 * tmpvar_14)));
half4 tmpvar_38 = 0;
tmpvar_38.xyz = (((
(min ((((half3)(_mtl_u._Color.xyz * (float3)(_MainTex.sample(_mtlsmp__MainTex, (float2)(_mtl_i.xlv_TEXCOORD0.xy)).xyz))) * ((half)(2.0) * _DetailAlbedoMap.sample(_mtlsmp__DetailAlbedoMap, (float2)(_mtl_i.xlv_TEXCOORD0.zw)).xyz)), ((half3)(float3(1.0, 1.0, 1.0)) - tmpvar_13)) * (((
((half)(1.0) + ((tmpvar_36 - (half)(1.0)) * pow (((half)(1.00001) - tmpvar_30), (half)5.0)))
*
((half)(1.0) + ((tmpvar_36 - (half)(1.0)) * pow (((half)(1.00001) - tmpvar_32), (half)5.0)))
) * tmpvar_30) * lightColor_27))
+
(tmpvar_12.xyz * (env_2 + (lightColor_27 * max ((half)0.0,
((((tmpvar_13 +
(((half)(1.0) - tmpvar_13) * pow (abs(((half)(1.0) - tmpvar_33)), (half)5.0))
) * min ((half)1.0,
min (((((half)(2.0) * tmpvar_31) * tmpvar_32) / VdotH_34), ((((half)(2.0) * tmpvar_31) * tmpvar_30) / VdotH_34))
)) * max ((half)0.0, (
pow (tmpvar_31, tmpvar_35)
*
((tmpvar_35 + (half)(1.0)) / (half)(6.28318))
))) / (((half)(4.0) * tmpvar_32) + (half)(1e-05)))
))))
) + (
((((half)(1.0) - dot (tmpvar_12.xyz, (half3)float3(0.299, 0.587, 0.114))) * ((half)(1.0) - tmpvar_14)) * pow (abs(((half)(1.0) - tmpvar_32)), (half)5.0))
* env_2)) + ((half3)((float3)(_SelfIllum.sample(_mtlsmp__SelfIllum, (float2)(_mtl_i.xlv_TEXCOORD0.xy)).xyz) * _mtl_u._SelfIllumScale)));
tmpvar_38.w = ((half)((float)(_AlphaMap.sample(_mtlsmp__AlphaMap, (float2)(_mtl_i.xlv_TEXCOORD0.xy)).w) * _mtl_u._Color.w));
half4 tmpvar_39 = 0;
tmpvar_39 = tmpvar_38;
_mtl_o._fragData = tmpvar_39;
return _mtl_o;
}
// stats: 146 alu 12 tex 0 flow
// inputs: 6
// #0: xlv_TEXCOORD0 (high float) 4x1 [-1]
// #1: xlv_TEXCOORD1 (high float) 4x1 [-1]
// #2: xlv_TEXCOORD2 (high float) 3x1 [-1]
// #3: xlv_TEXCOORD3 (high float) 4x1 [-1]
// #4: xlv_TEXCOORD4 (high float) 3x1 [-1]
// #5: xlv_TEXCOORD5 (high float) 4x1 [-1]
// uniforms: 6 (total size: 52)
// #0: _WorldSpaceCameraPos (high float) 3x1 [-1] loc 0
// #1: _DetailNormalMapScale (high float) 1x1 [-1] loc 16
// #2: _BumpScale (high float) 1x1 [-1] loc 20
// #3: _Exposure (high float) 1x1 [-1] loc 24
// #4: _Color (high float) 4x1 [-1] loc 32
// #5: _SelfIllumScale (high float) 1x1 [-1] loc 48
// textures: 12
// #0: _MainTex (low 2d) 0x0 [-1] loc 0
// #1: _DetailAlbedoMap (low 2d) 0x0 [-1] loc 1
// #2: _AlphaMap (low 2d) 0x0 [-1] loc 2
// #3: _Occlusion (low 2d) 0x0 [-1] loc 3
// #4: _DetailNormalMap (low 2d) 0x0 [-1] loc 4
// #5: _BumpMap (low 2d) 0x0 [-1] loc 5
// #6: _SpecGlossMap (low 2d) 0x0 [-1] loc 6
// #7: _ShadowMapTexture (low 2d) 0x0 [-1] loc 7
// #8: _SpecCube (low cube) 0x0 [-1] loc 8
// #9: unity_Lightmap (low 2d) 0x0 [-1] loc 9
// #10: unity_LightmapInd (low 2d) 0x0 [-1] loc 10
// #11: _SelfIllum (low 2d) 0x0 [-1] loc 11