Whitespace语言教程【译】Whitespace Tutorial [原]

这篇教程介绍了Whitespace编程语言,一种基于空格、制表符和换行符的编程语言。内容涵盖栈操作、算术运算、堆访问、流程控制以及输入输出,并通过一个从1数到10并输出的示例进行说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文,Whitespace Tutorial:http://compsoc.dur.ac.uk/whitespace/tutorial.php

Whitespace 教程

这不是一个语言的指南,只是一个对whitespace语言的简单简单介绍。最接近的正式的介绍是自己去执行它!请看在操作语义学中整理的VM。hs(这句话不大清楚)

whitespace中的唯一的表示字符时Space(ASCII032),Tab(ASCII009)和LIne Feed(ASCII010)。仅允许line feed作为唯一的标识,对于Dos/Unix的文件转化时CR/LF问题就被避免了。

这个语言它自己本身是一个栈控制的语言,每一个命令包含一系列的标识,以Instruction Modification Parameter (IMP)开始. 在下表被列出了.

IMP Meaning
[Space] Stack Manipulation(栈控制)
[Tab][Space] Arithmetic(算术)
[Tab][Tab] Heap access(堆访问)
[LF] Flow Control(循环/流控制)
[Tab][LF] I/O

程序运行的虚拟机有一个栈或者堆程序员能轻松的把任意宽度的整数压入栈中(只能是整数,当前没有浮点数和实数操作)。堆也可以被用户作为永久存储的变量或数据结构而访问使用.

很多命令需要数字或者标签作为参数。数字可以是任意字节数的。可以用一系列的[space]和[Tab]来表示,以[LF]结束。[Space] 表示二进制中的0, [Tab] 表示 1.第一个字符给出了数的符号,[Space]表示正数,[Tab]表示负数,注意这里不是数字的一部分,只是来表示符号性的。

标签是简单的[LF]来结束spaces和tabs。因为只有一个全局的命名空间,所以所有的标签应该不同。

Stack Manipulation (IMP: [Space])

栈控制是众多普遍操作中的一个,因此IMP[Space]很简小。有4个栈指令(译者注:实际上现在有6个,后面有说)。

Command
### Unity URP Second UV Shader Implementation Tutorial #### Understanding the Concept of Secondary UVs in Shaders Secondary UV coordinates are often used to apply additional textures or effects on top of primary ones without affecting the main texture mapping. In Unity's Universal Render Pipeline (URP), implementing a shader that utilizes secondary UVs requires modifications within both the material properties and the shader code itself. #### Setting Up Material Properties with Additional UV Sets To enable support for multiple sets of UV coordinates, one must define these as input parameters inside the `Properties` block at the beginning of the HLSL file: ```hlsl Properties { _MainTex ("Texture", 2D) = "white" {} _SecondUVScale ("Second UV Scale", Vector) = (1,1,0,0) } ``` This snippet defines `_SecondUVScale`, which will be utilized later when transforming vertex positions into custom UV space[^1]. #### Modifying Vertex Function to Include Secondary UV Processing Within the vertex function, transform vertices using the provided scale factor from `_SecondUVScale`. This allows manipulation over how each point is mapped onto the new set of UVs before passing them down through the pipeline: ```csharp struct Attributes { float4 positionOS : POSITION; float2 uv : TEXCOORD0; }; struct Varyings { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float2 secondUv : TEXCOORD1; // Add this line here. }; Varyings Vert(Attributes IN){ Varyings OUT; OUT.pos = TransformObjectToHClip(IN.positionOS); OUT.uv = IN.uv * _SecondUVScale.xy + _SecondUVScale.zw; // Calculate secondary UV based on original UV plus scaling factors applied via property defined earlier. OUT.secondUv = TRANSFORM_TEX(IN.uv, _MainTex).xy *_SecondUVScale.xy+_SecondUVScale.zw; return OUT; } ``` The above Cg/HLSL script demonstrates adding an extra varying variable named `secondUv` alongside existing attributes passed between stages during rendering process[^3]. The transformation uses `TRANSFORM_TEX()` macro along with user-defined scales stored under `_SecondUVScale`. #### Fragment Shader Utilization of Both Main & Secondary UV Channels Finally, utilize both channels simultaneously by sampling two different textures assigned either directly within materials inspector panel or programmatically depending upon application requirements: ```glsl half4 Frag(Varyings IN):SV_Target{ half4 col = tex2D(_MainTex,IN.uv); half4 secCol=tex2D(_SecTex ,IN.secondUv); return lerp(col,secCol,col.a); } ``` Here, blending occurs according to alpha channel value present in first sampled color (`col`). Adjustments can easily accommodate more complex operations involving lighting calculations etc., but such extensions fall outside scope covered presently[^2]. --related questions-- 1. How does changing values associated with `_SecondUVScale` influence final rendered output? 2. What other types of transformations could potentially benefit from utilizing dual UV setups besides simple tiling patterns shown previously? 3. Can you provide examples where combining results derived from separate UV mappings leads to visually appealing outcomes compared against single-channel approaches alone? 4. Is there any performance impact while working extensively across multi-textured surfaces leveraging several distinct coordinate systems concurrently like demonstrated hereinabove ? 5. Are there alternative methods available within Unity’s ecosystem capable achieving similar visual effects achieved through manipulating secondary UV streams discussed herewithin ?
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值