shader

Explicit vs Automatic attribute location binding for OpenGL shaders

血红的双手。 提交于 2019-11-26 06:56:43
问题 When setting up attribute locations for an OpenGL shader program, you are faced with two options: glBindAttribLocation() before linking to explicitly define an attribute location. or glGetAttribLocation() after linking to obtain an automatically assigned attribute location. What is the utility for using one over the other? And which one, if any, is preferred in practice? 回答1: I know one good reason to prefer explicit location definition. Consider that you hold your geometry data in Vertex

Unity Shader - 车漆效果(基于MatCap)

☆樱花仙子☆ 提交于 2019-11-26 03:00:59
效果图: 这篇文章将基于MatCap的思想,在Unity中实现了具有高度真实感的MatCap车漆Shader。采用MatCap思想的Shader,用低廉的计算成本,就可以达到类似PBS非常真实的渲染效果,可谓是在移动平台实现次时代渲染效果的一种优秀解决方案。 本文以车漆Shader为例,但MatCap思想能实现的,并不局限于车漆Shader。 什么是matcap? Matcap全称MaterialCapture(材质捕获) 是一种把光照信息存储在纹理, 来源: https://blog.csdn.net/e295166319/article/details/90381627

ShaderLab学习小结(八)在标准表面shader中加入顶点着色器函数

…衆ロ難τιáo~ 提交于 2019-11-26 02:00:49
场景中新建cube,和一个plane,新建一个standard surface shader和用此shader的材质赋给cube。 在不改变这个标准表面shader原有元素的基础上加入顶点程序,实现” ShaderLab学习小结(七)用插值函数lerp渐变颜色 “中的颜色渐变,如下图: shader代码: Shader "Custom/TestCarPaintShader" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} _Glossiness("Smoothness", Range(0,1)) = 0.5 _Metallic("Metallic", Range(0,1)) = 0.0 //1.以下四个属性为新加入的实现渐变色属性(参见学习小结(七)) _Center("Center", range(-120,420)) = 0 _R("R",range(0,400)) = 0 _MainColor("Main Color", color) = (0,0,1,1) _SecColor("Second Color", color) = (1,0,0,1) } SubShader { Tags { "RenderType"="Opaque" }

How to render depth linearly in modern OpenGL with gl_FragCoord.z in fragment shader?

和自甴很熟 提交于 2019-11-26 01:02:01
问题 I read lots of information about getting depth with fragment shader. such as http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=234519 but I still don\'t know whether or not the gl_FragCoord.z is linear. GLSL specification said its range is [0,1] in screen sapce without mentioning it\'s linear or not. I think linearity it is vital since I will use the rendered model to match depth map from Kinect. Then if it is not linear, how to linearlize it in the world space? 回答1:

ray and ellipsoid intersection accuracy improvement

柔情痞子 提交于 2019-11-26 00:38:58
问题 I need to enhance precision for function in one of mine Atmospheric scattering GLSL fragment shader which computes the intersection between single ray and axis aligned ellipsoid. This is the core function for mine atmospheric scattering shader. The old original shader was on floats and for normal rendering was fine, but after addition of zoom I found that with relatively small distances the precision get lost. On floats the usable distances for Earth was only up to 0.005 AU (Astronomical Unit

OpenGL - vertex normals in OBJ

五迷三道 提交于 2019-11-25 21:55:55
问题 I want to know how can I use the vertex normals for lightning effect? Currently what I have is I can send both vertex and texture coords to the shader and use them but with normals, I don\'t know how to use them in the shader program. Below is what I have so far. // vertex shader layout(location = 0) in vec4 vert; layout(location = 1) in vec4 color; layout(location = 2) in vec2 texcoord; uniform mat4 m_model; uniform mat4 m_view; uniform mat4 m_proj; void main() { gl_Position = m_proj * m