Tag Info

Hot answers tagged

7

You already know what you have to do, I'll just summarize it. There are three ways to solve your problem: Go ahead and make a conditional like you're saying, either by sampling the texture or by creating a separate uniform for this purpose. As you probably know, adding branching on a shader is almost never a good idea, and much less so in the fragment ...


3

You need two different models, because flat-shaded and smooth-shaded models normals are different. One of the ways is to generate 2 separate models and replace them with one another on demand. Another way is to make a single model prepared for flat shaded render (all vertices unique) and replace only normals when switching to flat/smooth shading. For ...


2

One way of doing this is to when you are loading the model and creating the vertex layout. you could calculate a second set of normals. which would be the flat normals. Do so by taking the connecting triangles. and then put it into all the vertices. if there is more than one connecting pollygon, you could insert some indexing to make it easier to handle ...


2

if you are trying to make a screensaver for example, they most usually go with screen capturing one time, then create a fullscreen borderless window and draw over the picture they took. Some games where you "destroy your desktop" with a hammer and it breaks in glass fashion, or other effects, also works like that. Some virus/jokes, also do that. If you want ...


2

Yes. There an article about this by Chris­t­ian Schüler: http://www.thetenthplanet.de/archives/1180 It's a followup to a book article (ShaderX 5) which did exactly what you need. I've used it myself. Here is the part that you need: (p : world-space position, N : world-space normal) mat3 cotangent_frame( vec3 N, vec3 p, vec2 uv ) { // get edge vectors ...


1

You can't rewrite that loop so that it can't be unrolled. GPUs do not in general support a varying number of attributes to be passed between stages. You can, however, eliminate the loop entirely. Just pass vPosWS to the fragment shader, and do the loop there. Then the unrolling will actually be helpful. Bonus: You don't waste an absurd amount of bandwidth ...


1

Here's how I've approached this situation in Unity in the past: I create a custom shield shader that accepts some number of vector parameters (typically 3 or 4), each representing a recent hit. The xyz components are the position of the hit in local coordinates, and the w component is the intensity. Within the fragment shader, I compute the object-space ...


1

I'm a newb to DirectX myself, but from what I've read, in HLSL, this: Texture textures[3]; Will actually be compiled like this: Texture textures0; Texture textures1; Texture textures2; So indexing into the array won't work.


1

It's a simple interpolation. Let's assume that your heights span -1 to 1, 0 is water surface and you have 3 colours: dark green, light green and white. A way to do what you want is to have the following color_from_height function in the pixel or fragment shader (depending on how efficient you want to be). In my shader below I visualize the gradient, but the ...


1

Typically, the MVP matrix (along with any other matrices you might be using) are specified using uniforms, for example: #version 330 in vec3 iPosition; // input from vertex attribute out vec3 vPosition; // output to fragment shader // other inputs/outputs for colors, texture coordinates, etc. as needed uniform mat4 uMVP; void main() { vPosition = ...


1

You don't specify what rendering method you want to use. Standard rasterisation of a 3D mesh? Or do you have a volume representation of the model and your renderer uses that directly? If you render a volume, check this: http://http.developer.nvidia.com/GPUGems/gpugems_ch39.html especially 39.2. The effect in the picture you provide is mainly subsurface ...



Only top voted, non community-wiki answers of a minimum length are eligible