{"id":290166,"date":"2018-10-01T17:30:02","date_gmt":"2018-10-01T13:30:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=290166"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=290166","title":{"rendered":"\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 GLSL \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u0432 \u043d\u0430 Kotlin"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/qr\/2o\/e4\/qr2oe43eauzbkvwv8r2tn2ze1do.jpeg\"\/><\/p>\n<p>  \u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>  \u041d\u0430\u0448\u0430 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u043e\u043d\u043b\u0430\u0439\u043d \u0438\u0433\u0440 \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043d\u0430\u0434 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 GLSL \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u0432 \u0434\u043b\u044f Android \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0438 <a href=\"https:\/\/github.com\/dananas\/kotlin-glsl\">\u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c\u0438<\/a>.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h3>\u041e \u043f\u0440\u043e\u0435\u043a\u0442\u0435<\/h3>\n<p>  \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0438\u0433\u0440\u0430 \u0431\u044b\u043b\u0430 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u0430\u044f \u043d\u0430 Flash, \u043d\u043e \u043d\u043e\u0432\u043e\u0441\u0442\u044c \u043e \u0441\u043a\u043e\u0440\u043e\u043c \u043f\u0440\u0435\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 Flash \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u043b\u0430 \u043d\u0430\u0441 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 HTML5. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u044f\u0437\u044b\u043a\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0431\u044b\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d Kotlin, \u0438 \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442 \u0438 \u043d\u0430 Android. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0431\u0435\u0437 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\u0445 \u0438\u0433\u0440\u0435 \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u043b\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c FPS, \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u043f\u0435\u0440\u0435\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0434\u0432\u0438\u0436\u043e\u043a. \u0420\u0430\u043d\u044c\u0448\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0445 \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u0432, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0448\u0435\u0439\u0434\u0435\u0440, \u0437\u0430\u0442\u043e\u0447\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0434 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u0443 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435.<\/p>\n<h3>\u0427\u0435\u0433\u043e \u043d\u0430\u043c \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u043b\u043e<\/h3>\n<p>  \u0428\u0435\u0439\u0434\u0435\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0432 \u0441\u0442\u0440\u043e\u043a\u0435, \u043d\u043e \u044d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0438 \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0431\u044b\u0447\u043d\u043e \u0448\u0435\u0439\u0434\u0435\u0440\u044b \u0445\u0440\u0430\u043d\u044f\u0442 \u0432 Assets \u0438\u043b\u0438 Raw \u0444\u0430\u0439\u043b\u0430\u0445, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f Android Studio. \u041d\u043e \u0438 \u0443 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0435\u0441\u0442\u044c \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a \u2014 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f: \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043f\u0440\u0430\u0432\u043a\u0438, \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b \u0448\u0435\u0439\u0434\u0435\u0440\u0430. <\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b:<\/p>\n<p>   \u2014 \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0448\u0435\u0439\u0434\u0435\u0440\u044b \u043d\u0430 Kotlin,<br \/>   \u2014 \u0438\u043c\u0435\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u043d\u0430 \u044d\u0442\u0430\u043f\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438,<br \/>   \u2014 \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u043c\u0435\u0436\u0434\u0443 \u0448\u0435\u0439\u0434\u0435\u0440\u0430\u043c\u0438,<br \/>   \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u00ab\u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440\u00bb Kotlin \u0432 GLSL.<\/p>\n<p>  \u0416\u0435\u043b\u0430\u0435\u043c\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: \u043a\u043e\u0434 \u0448\u0435\u0439\u0434\u0435\u0440\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a Kotlin class, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c attributes, varyings, uniforms \u2014 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u043d\u044b\u0445 \u0432\u0435\u0442\u0432\u043b\u0435\u043d\u0438\u0439 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u0434 \u0448\u0435\u0439\u0434\u0435\u0440\u0430. \u0411\u043b\u043e\u043a init \u2014 \u0442\u0435\u043b\u043e \u0448\u0435\u0439\u0434\u0435\u0440\u0430.<\/p>\n<h3>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u044b\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b Kotlin <a href=\"https:\/\/kotlinlang.org\/docs\/reference\/delegated-properties.html\">delegates<\/a>. \u041e\u043d\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0438 \u0432 runtime \u0443\u0437\u043d\u0430\u0432\u0430\u0442\u044c \u0438\u043c\u044f \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442\u044b get \u0438 set \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u0438 \u043e\u043f\u043e\u0432\u0435\u0449\u0430\u0442\u044c \u043e \u043d\u0438\u0445 ShaderBuilder \u2014 \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0432\u0441\u0435\u0445 \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u0432.<\/p>\n<pre><code>class ShaderBuilder {     val uniforms = HashSet&lt;String&gt;()     val attributes = HashSet&lt;String&gt;()     val varyings = HashSet&lt;String&gt;()     val instructions = ArrayList&lt;Instruction&gt;()     ...     fun getSource(): String = ... } <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u0432<\/b><\/p>\n<div class=\"spoiler_text\">Varying \u0434\u0435\u043b\u0435\u0433\u0430\u0442:<\/p>\n<pre><code>class VaryingDelegate&lt;T : Variable&gt;(private val factory: (ShaderBuilder) -&gt; T) {     private lateinit var v: T     operator fun provideDelegate(ref: ShaderBuilder, p: KProperty&lt;*&gt;): VaryingDelegate&lt;T&gt; {         v = factory(ref)         v.value = p.name         return this     }     operator fun getValue(thisRef: ShaderBuilder, property: KProperty&lt;*&gt;): T {         thisRef.varyings.add(&quot;${v.typeName} ${property.name}&quot;)         return v     }     operator fun setValue(thisRef: ShaderBuilder, property: KProperty&lt;*&gt;, value: T) {         thisRef.varyings.add(&quot;${v.typeName} ${property.name}&quot;)         thisRef.instructions.add(Instruction.assign(property.name, value.value))     } } <\/code><\/pre>\n<p>  \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u0432 \u043d\u0430 <a href=\"https:\/\/github.com\/dananas\/kotlin-glsl\">GitHub<\/a>.  <\/div>\n<\/div>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u0448\u0435\u0439\u0434\u0435\u0440\u0430:<\/p>\n<pre><code>\/\/ \u0422\u0430\u043a \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 useAlphaTest \u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u0448\u0435\u0439\u0434\u0435\u0440\u0430, \/\/ \u043c\u043e\u0436\u043d\u043e \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0432 \u0448\u0435\u0439\u0434\u0435\u0440, \u0438, \u0438\u0437\u043c\u0435\u043d\u044f\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0448\u0435\u0439\u0434\u0435\u0440\u044b. class FragmentShader(useAlphaTest: Boolean) : ShaderBuilder() {     private val alphaTestThreshold by uniform(::GLFloat)     private val texture by uniform(::Sampler2D)     private val uv by varying(::Vec2)     init {         var color by vec4()         color = texture2D(texture, uv)         \/\/ static branching         if (useAlphaTest) {             \/\/ dynamic branching             If(color.w lt alphaTestThreshold) {                 discard()             }         }         \/\/ \u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0432 ShaderBuilder.         gl_FragColor = color     } } <\/code><\/pre>\n<p>  \u0410 \u0432\u043e\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a GLSL (\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f FragmentShader(useAlphaTest = true).getSource()). \u0421\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0441\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043a\u043e\u0434\u0430:<\/p>\n<pre><code>uniform sampler2D texture; uniform float alphaTestThreshold; varying vec2 uv; void main(void) {     vec4 color;     color = texture2D(texture, uv);     if ((color.w &lt; alphaTestThreshold)) {         discard;     }     gl_FragColor = color; } <\/code><\/pre>\n<p>  \u0420\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u0448\u0435\u0439\u0434\u0435\u0440\u0430, \u0437\u0430\u0434\u0430\u0432\u0430\u044f \u0440\u0430\u0437\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430 \u0443\u0434\u043e\u0431\u043d\u043e, \u043d\u043e \u044d\u0442\u043e \u043d\u0435 \u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0433\u0434\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043a\u043e\u0434 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0448\u0435\u0439\u0434\u0435\u0440\u0430\u0445, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u044d\u0442\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 ShaderBuilderComponent \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u043f\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 ShaderBuilders:<\/p>\n<pre><code>class ShadowReceiveComponent : ShaderBuilderComponent() {     \u2026     fun vertex(parent: ShaderBuilder, inp: Vec4) {         vShadowCoord = shadowMVP * inp         ...         parent.appendComponent(this)     }      fun fragment(parent: ShaderBuilder, brightness: GLFloat) {         var pixel by float()         pixel = texture2D(shadowTexture, vShadowCoord.xy).x         ...         parent.appendComponent(this)     } } <\/code><\/pre>\n<p>  \u0423\u0440\u0430, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u0448\u0435\u0439\u0434\u0435\u0440\u044b \u043d\u0430 Kotlin, \u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441!<\/p>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c \u043f\u0440\u043e <a href=\"https:\/\/www.khronos.org\/opengl\/wiki\/Data_Type_(GLSL)#Swizzling\">Swizzling<\/a> \u0432 GLSL \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 Vec2, Vec3, Vec4.<\/p>\n<pre><code>class Vec2 {     var x by ComponentDelegate(::GLFloat)     var y by ComponentDelegate(::GLFloat) } class Vec3 {     var x by ComponentDelegate(::GLFloat)     ...     \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c 9\u0448\u0442 Vec2     var xx by ComponentDelegate(::Vec2)     var xy by ComponentDelegate(::Vec2)     ... } class Vec4 {     var x by ComponentDelegate(::GLFloat)     ...     \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c 16\u0448\u0442 Vec2     var xy by ComponentDelegate(::Vec2)     ...     \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c 64\u0448\u0442 Vec3     var xxx by ComponentDelegate(::Vec3)     ... } <\/code><\/pre>\n<p>  \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u044f \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0438\u0433\u0440\u043e\u0432\u043e\u043c \u0446\u0438\u043a\u043b\u0435 \u043f\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044e, \u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u044e\u0442 major \u0432\u044b\u0437\u043e\u0432\u044b GC, \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043b\u0430\u0433\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u0441\u0431\u043e\u0440\u043a\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u0432 \u043d\u0430 \u044d\u0442\u0430\u043f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0439.<\/p>\n<p>  \u041c\u044b \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0435\u0439 ShaderProgram:<\/p>\n<pre><code>@ShaderProgram(VertexShader::class, FragmentShader::class) class ShaderProgramName(alphaTest: Boolean) <\/code><\/pre>\n<p>  \u0418 annotation processor \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442 \u0432\u0441\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0448\u0435\u0439\u0434\u0435\u0440\u044b \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u043e\u0432 vertex \u0438 fragment \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0437\u0430 \u043d\u0430\u0441:<\/p>\n<pre><code>class ShaderProgramNameSources {     enum class Sources(vertex: String, fragment: String): ShaderProgramSources {         Source0(&quot;&lt;vertex code&gt;&quot;, &quot;&lt;fragment code&gt;&quot;)         ...     }     fun get(alphaTest: Boolean) {         if (alphaTest) return Source0         else return Source1     } } <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0448\u0435\u0439\u0434\u0435\u0440\u0430 \u0438\u0437 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<pre><code>val sources = ShaderProgramNameSources.get(replaceAlpha = true) println(sources.vertex) println(sources.fragment) <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 get \u2014 ShaderProgramSources \u2014 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 enum, \u0435\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 \u0440\u0435\u0435\u0441\u0442\u0440\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c (ShaderProgramSources) -&gt; CompiledShaderProgram.<\/p>\n<p>  \u041d\u0430 <a href=\"https:\/\/github.com\/dananas\/kotlin-glsl\">GitHub<\/a> \u0435\u0441\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0432\u043a\u043b\u044e\u0447\u0430\u044f annotation processor \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u0432 \u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.<\/div>\n<p>        <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d()}}}t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>     <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/post\/425027\/\"> https:\/\/habr.com\/post\/425027\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/qr\/2o\/e4\/qr2oe43eauzbkvwv8r2tn2ze1do.jpeg\"\/><\/p>\n<p>  \u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>  \u041d\u0430\u0448\u0430 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u043e\u0439 \u043e\u043d\u043b\u0430\u0439\u043d \u0438\u0433\u0440 \u0438 \u0441\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u043d\u0430\u0434 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043e\u043f\u044b\u0442\u043e\u043c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 GLSL \u0448\u0435\u0439\u0434\u0435\u0440\u043e\u0432 \u0434\u043b\u044f Android \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0438 <a href=\"https:\/\/github.com\/dananas\/kotlin-glsl\">\u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u043c\u0438<\/a>.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-290166","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/290166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=290166"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/290166\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=290166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=290166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=290166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}