From 85e2c1bc253f18fabcde33d12ee5af51aa3fe46c Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Thu, 10 May 2012 09:12:14 +0300 Subject: [PATCH] tests: various for loop variants --- tests/vertex/loops-forvarious-in.txt | 74 +++++++++++++++++++++++++ tests/vertex/loops-forvarious-out.txt | 71 ++++++++++++++++++++++++ tests/vertex/loops-forvarious-outES.txt | 71 ++++++++++++++++++++++++ 3 files changed, 216 insertions(+) create mode 100644 tests/vertex/loops-forvarious-in.txt create mode 100644 tests/vertex/loops-forvarious-out.txt create mode 100644 tests/vertex/loops-forvarious-outES.txt diff --git a/tests/vertex/loops-forvarious-in.txt b/tests/vertex/loops-forvarious-in.txt new file mode 100644 index 0000000..4f6d470 --- /dev/null +++ b/tests/vertex/loops-forvarious-in.txt @@ -0,0 +1,74 @@ +float4 unity_LightColor[4]; +float4 unity_LightPosition[4]; +float4 unity_LightAtten[4]; + +float4x4 UNITY_MATRIX_MVP; +float4x4 UNITY_MATRIX_MV; +float4x4 UNITY_MATRIX_IT_MV; + +struct appdata { + float4 vertex : POSITION; + float3 normal : NORMAL; +}; + +struct v2f { + half4 pos : POSITION; + half4 color : TEXCOORD0; +}; + +float3 ShadeMyVertexLights (float4 vertex, float3 normal) +{ + float3 viewpos = mul(UNITY_MATRIX_MV, vertex).xyz; + float3 viewN = mul((float3x3) UNITY_MATRIX_IT_MV, normal); + float3 lightColor = float3(0.0,0.0,0.0); + + for (int i = 0; i < 2; i++) { + float3 toLight = unity_LightPosition[i].xyz - viewpos.xyz; + float lengthSq = dot(toLight, toLight); + float atten = 1.0 / (1.0 + lengthSq * unity_LightAtten[i].z); + float diff = max (0, dot (viewN, normalize(toLight))); + lightColor += unity_LightColor[i].rgb * (diff * atten); + } + return (lightColor * 2.0); +} + +v2f main (appdata v) +{ + v2f o; + o.pos = mul(UNITY_MATRIX_MVP, v.vertex); + o.color = 0; + + for (int i = 0; i < 2; ++i) + o.color += unity_LightColor[i]; + + // same variable + for (int i = 0; i < 4; ++i) + o.color += unity_LightColor[i]; + + // different start/end conditions + for (int j = 3; j >= 0; j = j-1) + o.color += unity_LightColor[j]; + + // scope variables + for (int i = 0; i < 2; ++i) { + float4 l = unity_LightColor[i] * unity_LightAtten[i].x; + o.color += l; + } + + // scope variables again + for (int i = 0; i < 2; ++i) { + float4 l = unity_LightColor[i] * unity_LightAtten[i].z; + o.color += l; + } + + // weird loop construct + int k = 1; + for (; k < 3; ) + { + o.color += unity_LightColor[k].x; + int z = k + 1; + k = z; + } + + return o; +} diff --git a/tests/vertex/loops-forvarious-out.txt b/tests/vertex/loops-forvarious-out.txt new file mode 100644 index 0000000..2d0f31d --- /dev/null +++ b/tests/vertex/loops-forvarious-out.txt @@ -0,0 +1,71 @@ + +#line 14 +struct v2f { + vec4 pos; + vec4 color; +}; +#line 9 +struct appdata { + vec4 vertex; + vec3 normal; +}; +uniform mat4 UNITY_MATRIX_MVP; +uniform vec4 unity_LightAtten[4]; +uniform vec4 unity_LightColor[4]; +v2f xlat_main( in appdata v ); +#line 35 +v2f xlat_main( in appdata v ) { + v2f o; + int i = 0; + int i_1 = 0; + int j = 3; + int i_2 = 0; + vec4 l; + int i_3 = 0; + vec4 l_1; + int k = 1; + int z; + #line 38 + o.pos = (UNITY_MATRIX_MVP * v.vertex); + o.color = vec4( 0.00000); + for ( ; (i < 2); (++i)) { + o.color += unity_LightColor[i]; + } + #line 45 + for ( ; (i_1 < 4); (++i_1)) { + o.color += unity_LightColor[i_1]; + } + #line 49 + for ( ; (j >= 0); j = (j - 1)) { + o.color += unity_LightColor[j]; + } + #line 53 + for ( ; (i_2 < 2); (++i_2)) { + l = (unity_LightColor[i_2] * unity_LightAtten[i_2].x); + o.color += l; + } + #line 59 + for ( ; (i_3 < 2); (++i_3)) { + l_1 = (unity_LightColor[i_3] * unity_LightAtten[i_3].z); + o.color += l_1; + } + #line 65 + while ( (k < 3) ) { + o.color += unity_LightColor[k].x; + #line 69 + z = (k + 1); + k = z; + } + #line 73 + return o; +} +varying vec4 xlv_TEXCOORD0; +void main() { + v2f xl_retval; + appdata xlt_v; + xlt_v.vertex = vec4( gl_Vertex); + xlt_v.normal = vec3( gl_Normal); + xl_retval = xlat_main( xlt_v); + gl_Position = vec4( xl_retval.pos); + xlv_TEXCOORD0 = vec4( xl_retval.color); +} diff --git a/tests/vertex/loops-forvarious-outES.txt b/tests/vertex/loops-forvarious-outES.txt new file mode 100644 index 0000000..d335ed2 --- /dev/null +++ b/tests/vertex/loops-forvarious-outES.txt @@ -0,0 +1,71 @@ + +#line 14 +struct v2f { + mediump vec4 pos; + mediump vec4 color; +}; +#line 9 +struct appdata { + highp vec4 vertex; + highp vec3 normal; +}; +uniform highp mat4 UNITY_MATRIX_MVP; +uniform highp vec4 unity_LightAtten[4]; +uniform highp vec4 unity_LightColor[4]; +v2f xlat_main( in appdata v ); +#line 35 +v2f xlat_main( in appdata v ) { + v2f o; + highp int i = 0; + highp int i_1 = 0; + highp int j = 3; + highp int i_2 = 0; + highp vec4 l; + highp int i_3 = 0; + highp vec4 l_1; + highp int k = 1; + highp int z; + #line 38 + o.pos = (UNITY_MATRIX_MVP * v.vertex); + o.color = vec4( 0.00000); + for ( ; (i < 2); (++i)) { + o.color += unity_LightColor[i]; + } + #line 45 + for ( ; (i_1 < 4); (++i_1)) { + o.color += unity_LightColor[i_1]; + } + #line 49 + for ( ; (j >= 0); j = (j - 1)) { + o.color += unity_LightColor[j]; + } + #line 53 + for ( ; (i_2 < 2); (++i_2)) { + l = (unity_LightColor[i_2] * unity_LightAtten[i_2].x); + o.color += l; + } + #line 59 + for ( ; (i_3 < 2); (++i_3)) { + l_1 = (unity_LightColor[i_3] * unity_LightAtten[i_3].z); + o.color += l_1; + } + #line 65 + while ( (k < 3) ) { + o.color += unity_LightColor[k].x; + #line 69 + z = (k + 1); + k = z; + } + #line 73 + return o; +} +varying mediump vec4 xlv_TEXCOORD0; +void main() { + v2f xl_retval; + appdata xlt_v; + xlt_v.vertex = vec4( gl_Vertex); + xlt_v.normal = vec3( gl_Normal); + xl_retval = xlat_main( xlt_v); + gl_Position = vec4( xl_retval.pos); + xlv_TEXCOORD0 = vec4( xl_retval.color); +}