shader

Multiple subroutine types defined in the same fragment shader does not work correctly using GLSL Shaders

喜夏-厌秋 提交于 2019-12-06 09:20:14
I'm working on a program using GLSL shaders. I coded 2 different ways to compute ADS (Ambient + Diffuse + Specular) shading in 2 different methods. To do the job properly I used subroutines to use one or the other method to compute ADS shading. Here's a piece of the fragment shader code : subroutine vec3 LightShadingEffectType(int idx, vec3 normal, vec3 lightDir); subroutine uniform LightShadingEffectType LightShadingEffect; subroutine (LightShadingEffectType) vec3 Basic_ADS_Shading(int idx, vec3 normal, vec3 lightDir) { vec3 reflectDir = reflect(-lightDir, normal); vec3 viewDir = normalize(

Unity 3d Sprite Shader (How do I limit Max Brightness to 1 with Multiple Lights Hitting)

杀马特。学长 韩版系。学妹 提交于 2019-12-06 08:43:30
I am creating a videogame in Unity. Every sprite is rendered with a Sprite Renderer with a Material that has the CornucopiaShader.shader. The problem I have is I want to limit the max brightness (or color) of the sprite to just be a normal image of the sprite regardless of the power of how many point lights are hitting it, the intensity of the lights, and also the ambient light in the unity scene. When the intensity of the lights hitting the sprite is below that max brightness level I want it to act like a normal lit sprite and be black if no lights are hitting it, and be half lit up if an

LibGDX assigning a specific shader to a ModelInstance

不问归期 提交于 2019-12-06 08:11:49
I have recently been learning an implementing my own shaders in libgdx. So far I did this with a custom shader provider, which chooses between a few shaders based on the userdata value of the object; public class MyShaderProvider extends DefaultShaderProvider { public final DefaultShader.Config config; final static String logstag = "ME.MyShaderProvider"; //known shaders static public enum shadertypes { prettynoise, invert, standardlibgdx, noise, distancefield, conceptbeam } public MyShaderProvider (final DefaultShader.Config config) { this.config = (config == null) ? new DefaultShader.Config()

Unity 3D double sided shader with alpha and depth masking

↘锁芯ラ 提交于 2019-12-06 07:52:41
I want to create a shader in Unity 3D that you can add a material to that has both depth and transparency. I have so far created a shader that appears in 'scene' mode with transparency, but when I try to preview this in my VR setup, I cannot see the backface of the image. This is a set up for Google Cardboard, so I need to have the camera inside the mesh. This is my code so far: Shader "Custom/transparentDepth" { Properties { _Color ("Main Color", Color) = (1,1,1,1) _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} } SubShader { Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType

Unity3D: Drawing particles after AA resolve for performance

↘锁芯ラ 提交于 2019-12-06 07:49:12
问题 I'm trying to gauge the effect of MSAA on scenes with lots of particles in Unity. To do that, I'd need to: Draw all non-particle objects in the scene with 8x MSAA Use the resolved depth buffer from the previous pass to render all the non-occluded particle systems onto a smaller render target. Alpha Blend the color buffer of (2) with (1) I'm looking at the post-processing effects to get a sense of what i might need to do, but none of them use the depth buffer from a previous pass to affect the

sphere texture mapping error

為{幸葍}努か 提交于 2019-12-06 07:47:39
i use D3DXCreateSphere method to create sphere mesh. and i want to apply an earth texture on it. i calculate the texture coordinate in pixel shader with following code: sampler ShadeSampler = sampler_state { Texture = (ShadeTex); AddressU = Mirror; AddressV = Mirror; MinFilter = LINEAR; MagFilter = LINEAR; MipFilter = LINEAR; }; PS_OUTPUT PSMain(VS_OUTPUT input){ PS_OUTPUT output = (PS_OUTPUT)0; vector uv; uv.x = 0.5 + atan2(input.normal.z, input.normal.x) / piMul2; uv.y = 0.5f - asin(input.normal.y) / pi; vector b = tex2D(ShadeSampler, uv.xy); output.diffuse = b * input.diffuse; return output

How should you efficiently batch complex meshes?

爱⌒轻易说出口 提交于 2019-12-06 06:42:13
问题 What is the best way to render complex meshes? I wrote different solutions below and wonder what is your opinion about them. Let's take an example: how to render the 'Crytek-Sponza' mesh? PS: I do not use Ubershader but only separate shaders If you download the mesh on the following link: http://graphics.cs.williams.edu/data/meshes.xml and load it in Blender you'll see that the whole mesh is composed by about 400 sub-meshes with their own materials/textures respectively. A dummy renderer

Loading SPIRV binary shader fails

你。 提交于 2019-12-06 06:39:59
In my program I tried to load precompiled binary shaders with the example code from Sasha Willems ( https://github.com/SaschaWillems/openglcpp/blob/master/SPIRVShader/main.cpp ): bool loadBinaryShader(const char *fileName, GLuint stage, GLuint binaryFormat, GLuint &shader) { std::ifstream shaderFile; shaderFile.open(fileName, std::ios::binary | std::ios::ate); if (shaderFile.is_open()) { size_t size = shaderFile.tellg(); shaderFile.seekg(0, std::ios::beg); char* bin = new char[size]; shaderFile.read(bin, size); GLint status; shader = glCreateShader(stage); // Create a new shader glShaderBinary

Shader - Simple SSS lighting issue

故事扮演 提交于 2019-12-06 06:29:31
I am trying to create a simple subsurface scattering effect using a shader but I am facing a small issue. Look at those screenshots. The three images represents three lighting states (above surface, really close to surface, subsurface) with various lighting colors (red and blue) and always the same subsurface color (red). As you might notice when the light is above the surface and really close to this surface its influence appears to minimize which is the expected behavior. But the problem is that is behaves the same for the subsurface part, this is normal according to my shader code but in my

(四)Shader中基本光照模型

时光总嘲笑我的痴心妄想 提交于 2019-12-06 06:29:11
1.前言 所谓的光照效果,反映到屏幕上就是一个个像素问题,所以光照的计算公式就是计算的一个一个颜色值。这些公式基本属于经验公式范畴,只是让人看起来像真正的光效。 光分为环境光、自发光、漫反射以及高光反射,由于反映到像素上就是颜色的叠加。即最终在片元着色器中返回的 颜色值=环境光颜色+自发光颜色+漫反射颜色+高光反射颜色 。下面依次对这些光进行说明。 2.环境光Ambient 环境光在Unity中可以设置,即windows-lighting中即可看到,在2018中则是window-rendering-lightingsettings中设置。在shader中通过如下变量可以获取到:UNITY_LIGHTMODEL_AMBIENT。但是一般计算中我们只需要颜色的rgb值。 3.自发光Emissive 自发光是最简单的,直接简单粗暴的暴露一个颜色值,包此值当作自发光颜色。 4.漫反射diffuse 漫反射计算参考一下光照模型进行计算。 4.1 兰伯特定律LambertLaw 兰伯特定律认为反射光线跟光源方向与法线夹角有关系(夹角余弦值),所以漫反射计算公式如下: 漫反射颜色 = 光源颜色 x 材质的漫反射颜色 x Max(0,Dot(法线,指向光源的方向) 其中: 光源颜色:变量_LightColor0代表光源颜色。 材质漫反射颜色:自定义的颜色值。 法线:可以获取到每个顶点的法线