Tag Info

New answers tagged

0

I do recommend this link for examples: http://www.codesampler.com/dx9src/dx9src_8.htm#dx9_hlsl_fx_simple For those wondering why their code won't work, or if you're confused on how to incorporate the shader into your pipeline, this is a good place to go.


4

Absolutely, But not as simple as taking a return value of a normal function. First I assume your question isn't about sharing variables between two shader stages (vertex, fragment..etc) but actually between two shader (programs). Shaders are part of the rendering pipeline, every input/output should pass through the rendering pipeline and its memory is ...


2

What you essentially want is the depth in camera coordinates, but relative to model, not camera. the easiest way to achieve that is to calculate the position of the origin of a model coordinate system in camera coordinates. ... vec4 cs_position = glModelViewMatrix * gl_Vertex; vec4 origin_position = glModelViewMatrix * vec4(0,0,0,1); distToOrigin = ...


1

calculate a bounding volume of the object (sphere, convex hull, box - depends on your speed/accuracy needs), this needs to be done only once - at initalization while rendering, for each object: transform camera (origin, direction) to object space project bounding volume on camera direction axis and subtract camera origin projection to retrieve min/max ...


0

I managed to find out what my problem was. The "smooth" keyword. Vertex shader: ... in float in_fl; flat out int FL; void main(void) { FL = int(in_fl); ... Fragment shader: ... flat in int FL; ... So now I have a red, a blue and a green square, as I wanted. Anyway thanks for any help.


1

It took quite a while but I've found the solution and am posting it here for anyone else who has the same issue. The draw code remains the same. Pixel Shader: // Texture sprite sheet. uniform extern texture ScreenTexture; sampler screen : register(s0) = sampler_state { Texture = <ScreenTexture>; MinFilter = POINT; // Stops pixels bleeding ...


1

Setting a uniform per sprite is probably not a good idea, as Sean Middleditch already pointed out. Tinting a sprite in OpenGL can easily be done by defining the vertex colors. Since the vertices in this case are defined by SpriteBatch.draw(), you should set the tint with SpriteBatch.setColor(). From the SpriteBatch source code: 200 public void setColor ...


1

Since I am working with SpriteKit on iOS the shader support in SpriteKit is still missing a few things to implement an animated color gradient shader in SpriteKit. However for those who come up to the same situation I have found a more performant way to make animated gradients with sprite kit. Instead of working with shaders I have created a simple image ...


4

Here's how I would do this. First, make sure you have the object's UVs or world coords (which you can pass through from your vertex shader) available to you. If it's just a background, you could also just use fragment coords (gl_FragCoord). For instance, let's say we're using UV coords. A fragment shader with only: gl_FragColor = vec4(vec3(uv.x),1.0); will ...



Top 50 recent answers are included