shader

THREE.js read pixels from GPUComputationRenderer texture

那年仲夏 提交于 2020-02-02 12:38:28
问题 I have been playing with GPUComputationRenderer on a modified version of this three.js example which modifies the velocity of interacting boids using GPU shaders to hold, read and manipulate boid position and velocity data. I have got to a stage where I can put GPU computed data (predicted collision times) into the texture buffer using the shader. But now I want to read some of that texture data inside the main javascript animation script (to find the earliest collision). Here is the relevant

Unity - 2D shader / lighting like Terraria or Starbound

我的梦境 提交于 2020-02-01 02:50:47
问题 I have a map with a lot of sprites. I could add a material to the sprite with diffuse shading and than add lots of lights. But that won't give me the result I want. And is performance heavy. Examples In the first image you can see that light is generated by torches. It's expanding its light at its best through 'open spaces' and it is stopped by blocks fairly quickly. Here is a great example of the top layer. We can see some kind of 2D directional light? Please note that the lighting inside

Unity - 2D shader / lighting like Terraria or Starbound

一世执手 提交于 2020-02-01 02:50:33
问题 I have a map with a lot of sprites. I could add a material to the sprite with diffuse shading and than add lots of lights. But that won't give me the result I want. And is performance heavy. Examples In the first image you can see that light is generated by torches. It's expanding its light at its best through 'open spaces' and it is stopped by blocks fairly quickly. Here is a great example of the top layer. We can see some kind of 2D directional light? Please note that the lighting inside

翻译5 Unity Advanced Lighting

自古美人都是妖i 提交于 2020-01-31 17:54:39
使用多个光源渲染 支持多光源类型 使用光照信息 计算顶点光照 了解球谐函数 上部分介绍了Unity的基本单个光源,现在学习多个光源参与渲染物体,使用Unity5.6.6f2 1 Include Files 为了给Shader增加支持多个光源,我们需要增加更多Pass通道。但是这些Pass最终包含了几乎完全相似的代码,为了避免代码的重复性,我们可以通过把着色器代码移动到一个CG文件,然后在Shader代码中引用该文件 在文件目录中手动创建一个 MyLighting.cginc 文件,再把FirstLighting.shader内从#pragma以下到ENDCG以上区间内代码拷贝进.cginc文件。这样我们不直接在shader中写这些重复的代码,通过include引用使用它。 注意, .cginc 文件也提供了类似的避免重复定义,#define XXX_INCLUDED,再把整个文件内容放置在预处理文件块中。 #if !defined(MY_LIGHTING_INCLUDED) #define MY_LIGHTING_INCLUDED //… #endif 2 第二光源-Drection 新建两个方向光对象,参数设置如下图: 2-1. 两个光源参数 现在场景中有两个光,但是每个物体看起来没有什么区别。现在我们一次只激活一个光源,看看有什么变化。 2-2. 左main光源

Unity3D 开发之shader教程(浅谈GPU渲染入门)

前提是你 提交于 2020-01-31 01:15:23
  尊重他人智慧成果,欢迎转载,请注明作者 心若透明,原文地址 http://www.cnblogs.com/ubanck/p/4109411.html   这篇随笔,就不按照各种专业的解释来描述了,完全看自己发挥吧,写到哪儿算哪儿。若是哪里有说的不对的地方,请各位看官直说无妨!   说到游戏研发,就不可避免会提到图形学,图形学里面细去研究,就会牵涉到各种各样的数学知识,向量,矩阵之类的!而到这儿,咱们先开始从shader谈起,什么是shader?咱们通常说写个shader,其实也就是写了一个执行某种功能的程序,跟你写个普通的程序原理上说一样的,而不同之处在于,shader是写个GPU执行的,说到GPU执行,那么就得谈到3D游戏里面的那些人物啊,花鸟啊,是怎么看到的,或者说的专业一点,叫做渲染出来的!   如果在2D上面,很简单,完全可以看作是一张图贴在屏幕上就OK。在3D上面,就复杂了一点,首先,我们的屏幕上2D的,不像现实世界,是三维空间!那么怎么在屏幕上画东西才能看上去有3D效果呢,你可以试试在纸上画一个立方体,学过数学都会画,你第一眼看上去就会觉得这是3D的,而不是一个简单的矩形!     模型坐标系:在计算机的3D世界里,也是通过这样一种东西来实现了3D效果。如果在计算机屏幕上面绘制3D模型,那么我们首先在3D软件上制作出这个模型,这个模型会有一个原点,来建一个坐标系

unity之LOD以及渲染队列

℡╲_俬逩灬. 提交于 2020-01-31 00:46:55
LOD设置 LOD全称Level of Detail 作用:unity引擎会根据不同的LOD值在不同的平台上使用不同的SubShader 注意:在上几篇博客中已经说过在一个着色器中会有一到多个SubShader,但是系统每次只会执行一个子着色器,选择子着色器的标准就是根据子着色器所设置的LOD的值来进行选择,每一次使用着色器,都会选择第一个小于等于LOD值的子着色器。 如何设置Shader的LOD的值 :通过Shader maximumlOOD来设置最大的LOD值即Shader.globalMaximumLOD; unity内置着色器分LOD等级 注意在设置最大LOD值的时候不能小于 Ver texLit kind of shaders 的值(100),否则unity将不会显示使用此着色器的物体 Demo: 场景 shader代码 Shader "Custom/LODShader" { Properties { _Color ( "Color" , Color ) = ( 1 , 1 , 1 , 1 ) _MainTex ( "Albedo (RGB)" , 2 D ) = "white" { } _Glossiness ( "Smoothness" , Range ( 0 , 1 ) ) = 0.5 _Metallic ( "Metallic" , Range ( 0 , 1 )

shader入门精要读书笔记06 数学基础

倖福魔咒の 提交于 2020-01-30 14:50:39
第四章 数学基础 一、坐标系 笛卡尔坐标系,分为二维三维。 二维坐标系 OpenGL是左下角为0,DirectX是左上角。 三维坐标系,3个坐标轴也被称为基矢量,长度为1的基矢量叫做标准正交基,长度不唯1的叫正交基。 三维笛卡尔坐标系又分为左手坐标系与右手坐标系。 Unity使用的是左手坐标系,摄像头的观察空间是右手坐标系(摄像头前方为z轴的负方向)。 二、点和矢量 矢量:有方向有模,没有位置。 点:只是一个位置。 矢量的加减乘除运算,模运算。 单位矢量:被归一化的矢量。通过在矢量上方加个^来表示是矢量的模。 单位矢量的运算:通过矢量除以矢量的模来进行计算。 单位矢量计算通常使用在法线方向、光源方向等。 矢量的点积(内积/点乘): 点积就是可以确定两个矢量的方向关系。投影长度=标量。 点乘结果>0 :两个矢量方向关系为<90°。(=0 : 垂直,<0 : >90°) 求适量的模可以将矢量对其自身进行点乘,运算后开方。 a·b=|a||b|cos夹角 矢量的叉积(外积/叉乘): 叉积结果是矢量,不满足交换律,叉积的结果是得到一个同时垂直于这两个矢量的新矢量。 使用左手定则,右手定则来判断在不同坐标系中,新得到的矢量方向。 |a×b|=|a||b|sin夹角 我们可以通过点乘(cos值)来确定某两个矢量的夹角关系。 还可以通过叉乘判断一个面的正面反面(通过确定面上的三个点的顺时针

(How) can a shader view the current render-buffer?

拈花ヽ惹草 提交于 2020-01-30 09:12:06
问题 Is it possible for a pixel shader to see the current state of the depth/color/stencil buffer? 回答1: A fragment shader is not given the current buffer values for the fragment it is working on. Attempts to read these values, by using those buffers as textures, will not in the general case produce reasonable results. It's "undefined behavior." There are certain specific cases where it can work. First, you can use texture barriers. That is technically an NVIDIA extension, but ATI supports it

Unity Shader——Writing Surface Shaders(1)——Surface Shader Examples

我怕爱的太早我们不能终老 提交于 2020-01-30 04:09:00
  这里有 Surface Shader 的一些例子。下面的这些例子关注使用内建的光照模型;关于如何使用自定义光照模型的例子参见 Surface Shader Lighting Examples 。 简单   我们将会以一个非常简单的shader作为开始,并在此基础上逐渐完善。下面这个shader会把表面颜色置成“白色”。它使用内建的Lambert(漫反射)光照模型。 Shader "Example/Diffuse Simple" { SubShader { Tags { "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf Lambert struct Input { float4 color : COLOR; }; void surf (Input IN, inout SurfaceOutput o) { o.Albedo = 1; } ENDCG } Fallback "Diffuse" }   以下是使用两个 lights 作用在某个模型上的样子: 纹理   一个全白的对象太无聊了,所以让我们添加一个纹理。我们将会在shader中添加一个 Properties block ,这样我门就能在材质中获得一个纹理选择器。以下粗体为其他改变: Shader "Example/Diffuse Texture" {

Shader之小白入门学习三

风流意气都作罢 提交于 2020-01-28 17:13:38
Shader之小白入门学习三 前言 已经是第三章了,也该开始Shader中的代码干货了,那这一篇就来扒一扒Shader中的代码框架吧。 IDE 集成开发环境(IDE,Integrated Development Environment)是用于提供程序开发环境的应用程序,一般包括代码编辑器,编译器,调试器和图形用户界面等工具。简单点来说就是需要安装一个这样的脚本编辑器来书写Shader代码。 终于到了代码了,双击新建的Unlit shader让我们来一睹其真容。如果双击没有反应,说明你没有为Unity安装配置IDE,大家可以选择Visual Studio或者Visual Studio Code(简称 VSCode),个人比较喜欢Code,安装的细节可以在网上找到。 框架 打开后,我们大概能看到59行代码,刚开始也是看得我一脸懵逼,没关系,现在我们做一件事将这50多行的代码精简一下 只留下整体的框架部分,如下所示: Shader "Unlit/NewUnlitShader" { Properties { } SubShader { Pass { } } FallBack "Diffuse" CustomEditor "EditorName" } 为了说明框架问题,最后12 ,13行添加了两条语句后面会讲解。 从整体来看的话,大致是这样的一个框架结构: Shader “name” {