1#!amber 2# Copyright 2022 Google LLC 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16DEVICE_FEATURE sampleRateShading 17 18SHADER vertex vert_shader GLSL 19#version 440 20layout(location = 0) in vec4 inPosNDC; 21layout(location = 1) in vec2 inPosScreen; 22layout(location = 0) out vec2 outPosScreenArr[10]; 23 24void main (void) 25{ 26 gl_Position = inPosNDC; 27 28 for (int i = 0; i < 10; i++) 29 outPosScreenArr[i] = inPosScreen + vec2(i); 30} 31END 32 33SHADER fragment frag_shader GLSL 34#version 440 35layout(location = 0) sample in vec2 inPosScreenArr[10]; 36layout(location = 0) out vec4 fs_out_color; 37 38void main (void) 39{ 40 int index = int(gl_FragCoord.x) % 10; 41 vec2 ref = interpolateAtCentroid(inPosScreenArr[0]) + vec2(index); 42 43 if (distance(ref, interpolateAtCentroid(inPosScreenArr[index])) < 0.01 44 && abs(ref.y - interpolateAtCentroid(inPosScreenArr[index].y)) < 0.01 45 && abs(ref.y - interpolateAtCentroid(inPosScreenArr[index])).y < 0.01) 46 { 47 fs_out_color = vec4(0.0, 1.0, 0.0, 1.0); 48 } 49 else 50 { 51 fs_out_color = vec4(1.0, 0.0, 0.0, 1.0); 52 } 53} 54END 55 56BUFFER position DATA_TYPE vec4<float> DATA 57-1.0 -1.0 0.0 1.0 58 1.0 -1.0 0.0 1.0 59 1.0 1.0 0.0 1.0 60-1.0 1.0 0.0 1.0 61END 62 63BUFFER position_screen DATA_TYPE vec2<float> DATA 64 0.0 0.0 6564.0 0.0 6664.0 64.0 67 0.0 64.0 68END 69 70IMAGE framebufferMS FORMAT R8G8B8A8_UNORM DIM_2D WIDTH 64 HEIGHT 64 SAMPLES 4 71IMAGE framebuffer FORMAT R8G8B8A8_UNORM DIM_2D WIDTH 64 HEIGHT 64 72 73PIPELINE graphics pipeline 74 ATTACH vert_shader 75 ATTACH frag_shader 76 VERTEX_DATA position LOCATION 0 77 VERTEX_DATA position_screen LOCATION 1 78 FRAMEBUFFER_SIZE 64 64 79 BIND BUFFER framebufferMS AS color LOCATION 0 80 BIND BUFFER framebuffer AS resolve 81END 82 83RUN pipeline DRAW_ARRAY AS TRIANGLE_FAN START_IDX 0 COUNT 4 84EXPECT framebuffer IDX 0 0 SIZE 64 64 EQ_RGBA 0 255 0 255 85