shader

Direct3D Line thickness

情到浓时终转凉″ 提交于 2019-12-03 19:11:23
问题 How do I change the thickness of lines when drawing line lists using Direct3D? This post says that line width is not supported and goes on to provide a workaround. Other options? While we are on this topic, do shaders allow one to draw lines with dash patterns? 回答1: You can use a geometry shader that will take as an input a segment of your line and output a quad (a triangle strip made of two triangles) so that the width of the quad is constant in screen space and matches the desire line

GLSL: gl_FragCoord issues

穿精又带淫゛_ 提交于 2019-12-03 17:46:02
问题 I am experimenting with GLSL for OpenGL ES 2.0. I have a quad and a texture I am rendering. I can successfully do it this way: //VERTEX SHADER attribute highp vec4 vertex; attribute mediump vec2 coord0; uniform mediump mat4 worldViewProjection; varying mediump vec2 tc0; void main() { // Transforming The Vertex gl_Position = worldViewProjection * vertex; // Passing The Texture Coordinate Of Texture Unit 0 To The Fragment Shader tc0 = vec2(coord0); } //FRAGMENT SHADER varying mediump vec2 tc0;

Render TMX Map on Threejs Plane

六月ゝ 毕业季﹏ 提交于 2019-12-03 17:12:38
Question updated with new code I am trying to write a WebGL shader that will draw a TMX Layer (exported from the Tiled editor). I am using THREE.js to create a Plane mesh and have the material be a ShaderMaterial that will draw the map on it. For those who don't know a tilemap exported by the Tiled editor as json will give a data attribute for each layer; it contains an array of numerical values, each of which is the tile index in the tileset like: "data": [5438, 5436, 5437, 5438, 5436, 5437, 5438, 5436, 5437, 5438, 845, ...] Since my tilemap is 256 by 256 tiles, the array is 65536 elements in

What is the actual number of vertex uniform components for GLSL shader on ATI graphics card?

ぃ、小莉子 提交于 2019-12-03 16:58:01
问题 I'm writing a GLSL vertex shader for an iMac with a AMD Radeon HD 6970M 2048 MB graphics card: GL_MAX_VERTEX_ATTRIBS: 16 GL_MAX_VERTEX_UNIFORM_COMPONENTS: 4096 GL_VERSION: 2.1 ATI-7.12.9 GL_SHADING_LANGUAGE_VERSION: 1.20 In my shader I would like to have a large array of uniform mat4s: uniform mat4 T[65] but if I try to have 65 of these my shader (secretly) switches to Apple Software Renderer mode. If I instead use 64: uniform mat4 T[64] everything is fine. Seems to be a problem with

THREE.js repeat wrapping texture in shader

余生长醉 提交于 2019-12-03 16:45:12
I want to repeat wrapping texture in THREE.js shader. The original texture image is: I want it to repeat 4x4 times which will looks like: But with the following code, it turns out to be: Vertex shader: varying vec2 vUv; uniform float textRepeat; void main() { // passing texture to fragment shader vUv = uv * textRepeat; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); } Fragment shader: varying vec2 vUv; uniform sampler2D texture; void main() { // add origianl texture gl_FragColor = texture2D(texture, vUv); } uniforms in a JavaScript file, in which textureRepeat gives the

Unity3d shader裁剪圆形头像

跟風遠走 提交于 2019-12-03 16:16:21
Shader "Custom/D2" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _Mask ("Base (RGB)", 2D) = "white" {} } SubShader { Tags{"Queue"="Transparent"} Pass{ blend SrcAlpha OneMinusDstAlpha SetTexture [_MainTex]{ combine texture } SetTexture [_Mask]{ combine Previous , texture } } } } Shader "Custom/D3" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _banjin ("Rodius",Range(0.01,0.25)) = 0.25 } SubShader { Tags { "RenderType"="Opaque" "Queue"="Transparent"} LOD 200 CGPROGRAM #pragma surface surf Lambert alpha sampler2D _MainTex; float _banjin; struct Input { float2 uv_MainTex; };

Unity 自定义Inspector面板 样式

 ̄綄美尐妖づ 提交于 2019-12-03 16:16:04
有时候为了开发更加方便,会重写Inspector面板或者Editor窗口。一般情况下,Unity已经将public修饰符的字段自动序列化,使得该字段能够在Inspector面板中能够被修改。而且也添加了许多unity的特性,例如[Range(0, 100)],[HideInInspector]等等,需要了解的同学们可以百度一下。 这次我们说的是Inspector面板。 马上看看效果及代码。 using UnityEngine; using System.Collections; using UnityEditor; [CustomEditor(typeof(NewBehaviourScript))] public class InspectorTest : Editor { public override void OnInspectorGUI() { DrawDefaultInspector(); GUILayout.Label("Expansion", "GUIEditor.BreadcrumbLeft"); GUILayout.Label("Expansion", "WhiteBoldLabel"); GUI.color = Color.green; GUILayout.Label("Expansion", "NotificationText"); GUILayout

Unity Shader 入门 之一 语法基础

流过昼夜 提交于 2019-12-03 16:15:38
unity shaderlab 的语法基础 ,用来做个人备忘查询 ShaderLab Syntax Unity中的所有Shader都是用一种叫做"Shader Lab"的陈述性语言(declarative language)写的。在Shader中通过逐层嵌套的大括号来声明包括在材质面板看到的一系列变量、使用的渲染模式、硬件不支持时的fallback等。而真正的"shader代码"夹在CGPROGRAM...ENDCG之间的代码片段。本节就合租要介绍这些嵌套的语法。而真正CGPROGRAM代码段是通过常规的HLSL/Cg 着色器语言完成的。 ShaderLab Shader "shadername" { [Properties] Subshaders [Fallback] [CustomEditor] } shadername: "shadername "是你通过inspector面板为材质选择shader时看到的名字,可以用"/"生成类似二级三级菜单的形式,例如" custom/example" Properties: shader中用到的一些额外参数,可以在材质的inspcector面板中看到,例如颜色,贴图等 Subshaders: 每一个Shder都是由一个或者多个sub-shader组成的。当加载一个shader的时候,unity 会从头遍历这一系列的subshader

unity Shader 扭曲效果

╄→尐↘猪︶ㄣ 提交于 2019-12-03 16:15:21
原理 所谓扭曲就是扰动一个物体的uv坐标,表现出来就是一个扰动效果,如火焰扭曲空气,和水波对水底的影响。 1. 在shader 中我们需要一张当前渲染的纹理 2. 给一个物体渲染并使用当前纹理,用屏幕坐标作为uv坐标加上一个扰动值 unity 1. unity提供了抓取的pass: GrabPass unity官网介绍 //每次遇到这个pass就去抓取一次提供了了一个默认名称_GrabTexture 不推荐使用 GrabPass { } //第一次遇到去抓取一次每帧只会抓取一次,名称由你自己定义 GrabPass { "_BackgroundTexture" } 2. 获取物体的屏幕坐标,unity也给出了内置函数 //官网代码 v2f vert(appdata_base v) { v2f o; // use UnityObjectToClipPos from UnityCG.cginc to calculate // the clip-space of the vertex o.pos = UnityObjectToClipPos(v.vertex); // use ComputeGrabScreenPos function from UnityCG.cginc // to get the correct texture coordinate o.grabPos =

Unity-使用Shader裁剪图片

允我心安 提交于 2019-12-03 16:14:49
原文: http://www.tuicool.com/articles/FziyEv 在unity中,使用一张正方形的图片,但是要显示成圆形。这样怎么做呢? 1、首先,新建一个shader:Circular 2、再新建一个material,选择上面新建的shader。 3、最后将上面的material赋值给unity中要显示为圆形的图片 下面是shader代码 Shader "Self/Circular" { Properties { _MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {} _StencilComp ("Stencil Comparison", Float) = 8 _Stencil ("Stencil ID", Float) = 0 _StencilOp ("Stencil Operation", Float) = 0 _StencilWriteMask ("Stencil Write Mask", Float) = 255 _StencilReadMask ("Stencil Read Mask", Float) = 255 _ColorMask ("Color Mask", Float) = 15 // 以 1 - _Radius 长度为半径的圆形 _Radius ("Radius", Range(0,0.5))