在 Unity 写 Shader 的时候,在一个循环里面使用了 tex2D 函数,类似与下面这样:

fixed2 center = fixed2(0.5,0.5);
fixed2 uv = i.uv - center;
for (fixed j = 0; j < _Strength; j++) {
c1 += tex2D(_MainTex,uv*(1 - 0.01*j) + center).rgb;
}

打apk没什么问题,但是打win版本的时候有个报错

unable to unroll loop, loop does not appear to terminate in a timely manner (994 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number
can't use gradient instructions in loops with break

解决方案1.

错误提示上说了,没有办法对循环进行展开,因为展开的迭代次数太多了,快到一千次了,请使用 [unroll(n)] 特性来指定一个可能的最大值。

[unroll(88)]
fixed2 center = fixed2(0.5,0.5);
fixed2 uv = i.uv - center;
for (fixed j = 0; j < _Strength; j++) {
c1 += tex2D(_MainTex,uv*(1 - 0.01*j) + center).rgb;
}

解决方案2.

由于 tex2D 函数需要确定 LOD ,即所使用的纹理层,这才必须 unroll,如果直接使用能够指定 LOD 的 tex2Dlod,那么就可以避免了。

函数签名:

  • tex2D( Sampler, IN.Texture );
  • tex2Dlod( Sampler, float4( IN.Texture, 0.0f, 0.0f ) );
fixed4 center = fixed4(.5,.5,0,0);
fixed4 uv = fixed4(i.uv,0,0) - center; for (fixed j = 0; j < _Strength; j++) {
c1 += tex2Dlod(_MainTex,uv*(1 - 0.01*j) + center).rgb;
}

解决方案3.

既然提示说不支持迭代,那么直接避免迭代就好了嘛。


参考链接

Issues with shaderProperty and for-loop[via Unity Forum]:见4楼 Dolkar 的回答,很详细了。

报错解决 unable to unroll loop, loop does not appear to terminate in a timely manner (994 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number的更多相关文章

  1. Android 工程报错解决 Unable to resolve target 'android-17'

    转自:http://www.cnblogs.com/csulennon/p/3705177.html 换了系统后,重新安装了Android SDK和ADT插件,导入之前的工作空间.居然发现所有的And ...

  2. 修改ubuntu DNS的步骤/wget url报错: unable to resolve host address的解决方法

    wget url 报错:unable to resolve host address ‘url’,显然是无法解析主机地址,这就能看出是DNS解析的问题.解决办法就是配置可用的dns 一般是修改成为谷歌 ...

  3. 解决报错:Unable to process Jar entry [org/springframework/jmx/export/annotation/*****]

    情况说明:从gitub上clone的maven项目,pox.xml配置中的依赖,自己的repository都有,所以正常update project ,正常clean,install,整个过程无报错 ...

  4. npm总是报错:unable to verify the first certificate

    今天npm install总是报错:unable to verify the first certificate(无法验证第一证书),查了一下发现 As of February 27, 2014, n ...

  5. 【Devops】【docker】【CI/CD】Jenkins自动安装JDK需要提供Oracle的账号密码,否则报错:Unable ro auto-install JDK until the license is accepted

    Jenkins自动安装JDK需要提供Oracle的账号密码,否则报错:Unable ro auto-install JDK  until the  license is accepted 解决方法: ...

  6. git同步遇到报错“fatal: unable to access 'https://github.com/lizhong24/mysite2.git/': Peer reports incompatible or unsupported protocol version.”

    git同步遇到报错“fatal: unable to access 'https://github.com/lizhong24/mysite2.git/': Peer reports incompat ...

  7. k8s集群node节点一直NotReady, 且node节点(并非master)的kubelet报错:Unable to update cni config: No networks found in /etc/cni/net.d

    若要转载本文,请务必声明出处:https://www.cnblogs.com/zhongyuanzhao000/p/11401031.html 问题: 集群搭建的过程中,master节点初始化成功,但 ...

  8. 报错:Unable to read additional data from client sessionid 0x36ab52d38c20b20, likely client has closed socket

    报错背景: CDH集群中,将kafka和Flume整合,将kafka的数据发送给Flume消费. 启动kafka的时候正常,但是启动Flume的时候出现了报错现象. 但是我检查了Flume,Flume ...

  9. 安装visual stdio 2017后依然报错:Unable to find vcvarsall.bat

    安装visual stdio 2017后依然报错:Unable to find vcvarsall.bat 解决办法:更新setuptools 原文章:https://blog.csdn.net/wl ...

随机推荐

  1. 简单实现TodoList

    Todolist实例 储备知识js的splice的用法 实例逻辑 1 在data里面做一个存一条条留言的列表,往里面添加或者删除留言内容. 2 做一个变量和input双向绑定,然后做一个点击事件把这个 ...

  2. C语言I作业10

    问题 回答 这个作业属于哪个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/SE2019-2/homework/10100 我在 ...

  3. 关于jsp中jstl报错Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core

    有的时候在开发jsp时,需要使用jstl时,在jsp上面引用jstl却出现错误:Can not find the tag library descriptor for "http://jav ...

  4. TensorFlow2.0(11):tf.keras建模三部曲

    .caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...

  5. 转:FileSync plugin for Eclipse 安装注意事项 Eclipse文件同步插件

    习惯了使用MyEclipse,各种插件不用自己安装,觉得开发起来很方便,现在大家都用Eclipse了,还有不用Eclipse用更高级的,IT当然开发大型项目没人用UltraEdit吧,虽然是一个不错的 ...

  6. SpringBoot入门简介(一)

    1.SpringBoot简介 1.1 什么是Spring 随着动态语言的流行 (Ruby.Groovy.Scala.Node.js),Java 的开发显得格外的笨重:繁多的配置.低下的开发效率.复杂的 ...

  7. 大数据之Linux网卡配置

    当你安装好一台Linux之后,第一步自然是配置网卡,让你的Linux上网. 配置网卡大多数有两种模式,一种是桥接,一种是NAT 首先讲一下桥接网卡的上网原理,他是等同于在你现有的网络环境上直接现加一台 ...

  8. Unity3D for iOS初级教程:Part 1/3(下)

    转自:http://www.cnblogs.com/alongu3d/archive/2013/06/01/3111735.html 一个手指来统治他们 但是等等,你还没有完全完成! 如果你玩游戏有一 ...

  9. 字典dict的深入学习(item() / items() 一致的)

    字典Dict的跟进学习: 一. items()方法的遍历:items()方法把字典中每对key和value组成一个元组,并把这些元组放在列表中返回. dict = {"name" ...

  10. [TimLinux] selinux sesearch命令详解

    1. 描述 sesearch用于搜索SELinux安全策略规则集,命令来自包:yum install setools-console. 2. 命令 命令使用方法: sesearch [OPTIONS] ...