< prev index next >

src/java.desktop/macosx/native/libawt_lwawt/awt/shaders.metal

Print this page

112     return out;
113 }
114 
115 vertex GradShaderInOut vert_txt_grad(TxtVertexInput in [[stage_in]],
116                                      constant TransformMatrix& transform [[buffer(MatrixBuffer)]]) {
117     GradShaderInOut out;
118     float4 pos4 = float4(in.position, 0.0, 1.0);
119     out.position = transform.transformMatrix*pos4;
120     out.texCoords = in.texCoords;
121     return out;
122 }
123 
124 fragment half4 frag_col(ColShaderInOut in [[stage_in]]) {
125     return in.color;
126 }
127 
128 fragment unsigned int frag_stencil(StencilShaderInOut in [[stage_in]]) {
129     return in.color;
130 }
131 






132 fragment half4 frag_txt(
133         TxtShaderInOut vert [[stage_in]],
134         texture2d<float, access::sample> renderTexture [[texture(0)]],
135         constant TxtFrameUniforms& uniforms [[buffer(1)]]
136         )
137 {
138     constexpr sampler textureSampler (mag_filter::linear,
139                                   min_filter::linear);
140     float4 pixelColor = renderTexture.sample(textureSampler, vert.texCoords);
141     float srcA = uniforms.isSrcOpaque ? 1 : pixelColor.a;
142     // TODO: consider to make shaders without IF-conditions
143     if (uniforms.mode) {
144         float4 c = mix(pixelColor, uniforms.color, srcA);
145         return half4(c.r, c.g, c.b , c.a);
146     }
147 
148     return half4(pixelColor.r,
149                  pixelColor.g,
150                  pixelColor.b, srcA*uniforms.extraAlpha);
151 }
152 
153 fragment half4 frag_txt_tp(TxtShaderInOut vert [[stage_in]],
154                        texture2d<float, access::sample> renderTexture [[texture(0)]],
155                        texture2d<float, access::sample> paintTexture [[texture(1)]])
156 {
157     constexpr sampler textureSampler (address::repeat,
158       mag_filter::nearest,
159       min_filter::nearest);
160 
161     float4 renderColor = renderTexture.sample(textureSampler, vert.texCoords);
162     float4 paintColor = paintTexture.sample(textureSampler, vert.tpCoords);
163     return half4(paintColor.r*renderColor.a,
164                  paintColor.g*renderColor.a,
165                  paintColor.b*renderColor.a,
166                  renderColor.a);
167 }
168 
169 fragment half4 frag_txt_grad(GradShaderInOut in [[stage_in]],
170                          constant GradFrameUniforms& uniforms [[buffer(0)]],
171                          texture2d<float, access::sample> renderTexture [[texture(0)]])
172 {
173     constexpr sampler textureSampler (address::repeat, mag_filter::nearest,
174                                       min_filter::nearest);
175 
176     float4 renderColor = renderTexture.sample(textureSampler, in.texCoords);
177 
178     float3 v = float3(in.position.x, in.position.y, 1);
179     float  a = (dot(v,uniforms.params)-0.25)*2.0;
180     float4 c = mix(uniforms.color1, uniforms.color2, a);
181     return half4(c.r*renderColor.a,
182                  c.g*renderColor.a,
183                  c.b*renderColor.a,
184                  renderColor.a);
185 }
186 
187 fragment half4 aa_frag_txt(
188         TxtShaderInOut vert [[stage_in]],
189         texture2d<float, access::sample> renderTexture [[texture(0)]],
190         constant TxtFrameUniforms& uniforms [[buffer(1)]]
191 )
192 {
193     constexpr sampler textureSampler (mag_filter::linear, min_filter::linear);
194     float4 pixelColor = renderTexture.sample(textureSampler, vert.texCoords);
195     return half4(pixelColor.r, pixelColor.g, pixelColor.b, pixelColor.a);
196 }
197 
198 fragment half4 frag_grad(GradShaderInOut in [[stage_in]],
199                          constant GradFrameUniforms& uniforms [[buffer(0)]]) {
200     float3 v = float3(in.position.x, in.position.y, 1);
201     float  a = (dot(v,uniforms.params)-0.25)*2.0;
202     float4 c = mix(uniforms.color1, uniforms.color2, a);
203     return half4(c);
204 }
205 
206 
207 vertex TxtShaderInOut vert_tp(VertexInput in [[stage_in]],
208        constant AnchorData& anchorData [[buffer(FrameUniformBuffer)]],
209        constant TransformMatrix& transform [[buffer(MatrixBuffer)]])
210 {
211     TxtShaderInOut out;
212     float4 pos4 = float4(in.position, 0.0, 1.0);
213     out.position = transform.transformMatrix * pos4;

112     return out;
113 }
114 
115 vertex GradShaderInOut vert_txt_grad(TxtVertexInput in [[stage_in]],
116                                      constant TransformMatrix& transform [[buffer(MatrixBuffer)]]) {
117     GradShaderInOut out;
118     float4 pos4 = float4(in.position, 0.0, 1.0);
119     out.position = transform.transformMatrix*pos4;
120     out.texCoords = in.texCoords;
121     return out;
122 }
123 
124 fragment half4 frag_col(ColShaderInOut in [[stage_in]]) {
125     return in.color;
126 }
127 
128 fragment unsigned int frag_stencil(StencilShaderInOut in [[stage_in]]) {
129     return in.color;
130 }
131 
132 // NOTE:
133 // 1. consider to make shaders without IF-conditions
134 // 2. we can pass interpolation mode via uniforms and select corresponding sampler in shader
135 //  but it can cause performance problems (something like getTextureSampler(hint) will be invoked
136 //  for every pixel)
137 
138 fragment half4 frag_txt(
139         TxtShaderInOut vert [[stage_in]],
140         texture2d<float, access::sample> renderTexture [[texture(0)]],
141         constant TxtFrameUniforms& uniforms [[buffer(1)]],
142         sampler textureSampler [[sampler(0)]]
143 ) {


144     float4 pixelColor = renderTexture.sample(textureSampler, vert.texCoords);
145     float srcA = uniforms.isSrcOpaque ? 1 : pixelColor.a;

146     if (uniforms.mode) {
147         float4 c = mix(pixelColor, uniforms.color, srcA);
148         return half4(c.r, c.g, c.b , c.a);
149     }
150 
151     return half4(pixelColor.r,
152                  pixelColor.g,
153                  pixelColor.b, srcA*uniforms.extraAlpha);
154 }
155 
156 fragment half4 frag_txt_tp(TxtShaderInOut vert [[stage_in]],
157                        texture2d<float, access::sample> renderTexture [[texture(0)]],
158                        texture2d<float, access::sample> paintTexture [[texture(1)]],
159                        sampler textureSampler [[sampler(0)]]
160 ) {



161     float4 renderColor = renderTexture.sample(textureSampler, vert.texCoords);
162     float4 paintColor = paintTexture.sample(textureSampler, vert.tpCoords);
163     return half4(paintColor.r*renderColor.a,
164                  paintColor.g*renderColor.a,
165                  paintColor.b*renderColor.a,
166                  renderColor.a);
167 }
168 
169 fragment half4 frag_txt_grad(GradShaderInOut in [[stage_in]],
170                          constant GradFrameUniforms& uniforms [[buffer(0)]],
171                          texture2d<float, access::sample> renderTexture [[texture(0)]])
172 {
173     constexpr sampler textureSampler (address::repeat, mag_filter::nearest,
174                                       min_filter::nearest);
175 
176     float4 renderColor = renderTexture.sample(textureSampler, in.texCoords);
177 
178     float3 v = float3(in.position.x, in.position.y, 1);
179     float  a = (dot(v,uniforms.params)-0.25)*2.0;
180     float4 c = mix(uniforms.color1, uniforms.color2, a);
181     return half4(c.r*renderColor.a,
182                  c.g*renderColor.a,
183                  c.b*renderColor.a,
184                  renderColor.a);
185 }
186 
187 fragment half4 aa_frag_txt(
188         TxtShaderInOut vert [[stage_in]],
189         texture2d<float, access::sample> renderTexture [[texture(0)]],
190         constant TxtFrameUniforms& uniforms [[buffer(1)]],
191         sampler textureSampler [[sampler(0)]]
192 ) {

193     float4 pixelColor = renderTexture.sample(textureSampler, vert.texCoords);
194     return half4(pixelColor.r, pixelColor.g, pixelColor.b, pixelColor.a);
195 }
196 
197 fragment half4 frag_grad(GradShaderInOut in [[stage_in]],
198                          constant GradFrameUniforms& uniforms [[buffer(0)]]) {
199     float3 v = float3(in.position.x, in.position.y, 1);
200     float  a = (dot(v,uniforms.params)-0.25)*2.0;
201     float4 c = mix(uniforms.color1, uniforms.color2, a);
202     return half4(c);
203 }
204 
205 
206 vertex TxtShaderInOut vert_tp(VertexInput in [[stage_in]],
207        constant AnchorData& anchorData [[buffer(FrameUniformBuffer)]],
208        constant TransformMatrix& transform [[buffer(MatrixBuffer)]])
209 {
210     TxtShaderInOut out;
211     float4 pos4 = float4(in.position, 0.0, 1.0);
212     out.position = transform.transformMatrix * pos4;
< prev index next >