Search Results

Search found 2086 results on 84 pages for 'pixel shader'.

Page 4/84 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Counting texels using a fragment shader

    - by Brett
    Hi, I have two textures generated using a fragment shader. I want to be able to count the number of texels in each texture that are above some colour intensity. My question is how can this be done? My initial thought is to count these texels using the fragment shader before generating the texture. However, this would require some sort of global counter. I can't use occlusion queries because the textures are created from other textures. I'm using OpenGL 2.1. Any ideas appreciated. Thanks

    Read the article

  • How to Create an Easy Pixel Art Avatar in Photoshop or GIMP

    - by Eric Z Goodnight
    Boingboing.net has a cool set of meticulously drawn pixel art portraits for their key writers. If you’re a lover of pixel art, why not try and recreate a similar avatars for yourself with a few simple filters in either Photoshop or GIMP? How-To Geek has covered a few different ways to create pixel art from ordinary graphics, and this simple method is more simple pixel art, but using a different technique. Watch as we transform two ordinary photographs into blocky masterpieces, as well as compare the techniques used between Photoshop and the GIMP. Read on!  How to Create an Easy Pixel Art Avatar in Photoshop or GIMPInternet Explorer 9 Released: Here’s What You Need To KnowHTG Explains: How Does Email Work?

    Read the article

  • Comparing bitmap data in AS3 pixel for pixel

    - by Jono
    Hi, I am looking for a fairly simple image comparison method in AS3. I have taken an image from a web cam (with no subject) passed it in to bitmap data, then a second image is taken (this time with a subject) to compare this data, from these two images I would like to create a mask from the pixels that match on both bitmaps. I have been scratching my head for a while, and I am not really making any progress. Could any one point me in the right direction for pixel comparison method, something like getPixel32() Cheers Jono

    Read the article

  • AS3: How to access pixel data efficiently?

    - by JonoRR
    I'm working a game. The game requires entities to analyse an image and head towards pixels with specific properties (high red channel, etc.) I've looked into Pixel Bender, but this only seems useful for writing new colors to the image. At the moment, even at a low resolution (200x200) just one entity scanning the image slows to 1-2 Frames/second. I'm embedding the image and instance it as a Bitmap as a child of the stage. The 1-2 FPS situation is using BitmapData.getPixel() (on each pixel) with a distance calculation beforehand. I'm wondering if there's any way I can do this more efficiently... My first thought was some sort of spatial partioning coupled with splitting the image up into many smaller pieces. I also feel like Pixel Bender should be able to help somehow, however I've had little experience with it. Cheers for any help. Jonathan

    Read the article

  • How to create an ARGB_8888 pixel value?

    - by vidstige
    Say I want to create an array of pixel values to pass into the createBitmap method described here. I have three int values r, g, b in the range 0 - 0xff. How do I transform those into a opaque pixel p? Does the alpha channel go in the high byte or the low byte? I googled up the documentation but it only states that: Each pixel is stored on 4 bytes. Each channel (RGB and alpha for translucency) is stored with 8 bits of precision (256 possible values.) This configuration is very flexible and offers the best quality. It should be used whenever possible. So, how to write this method? int createPixel(int r, int g, int b) { retrurn ? }

    Read the article

  • Monogame/SharpDX - Shader parameters missing

    - by Layoric
    I am currently working on a simple game that I am building in Windows 8 using MonoGame (develop3d). I am using some shader code from a tutorial (made by Charles Humphrey) and having an issue populating a 'texture' parameter as it appears to be missing. Edit I have also tried 'Texture2D' and using it with a register(t0), still no luck I'm not well versed writing shaders, so this might be caused by a more obvious problem. I have debugged through MonoGame's Content processor to see how this shader is being parsed, all the non 'texture' parameters are there and look to be loading correctly. Edit This seems to go back to D3D compiler. Shader code below: #include "PPVertexShader.fxh" float2 lightScreenPosition; float4x4 matVP; float2 halfPixel; float SunSize; texture flare; sampler2D Scene: register(s0){ AddressU = Clamp; AddressV = Clamp; }; sampler Flare = sampler_state { Texture = (flare); AddressU = CLAMP; AddressV = CLAMP; }; float4 LightSourceMaskPS(float2 texCoord : TEXCOORD0 ) : COLOR0 { texCoord -= halfPixel; // Get the scene float4 col = 0; // Find the suns position in the world and map it to the screen space. float2 coord; float size = SunSize / 1; float2 center = lightScreenPosition; coord = .5 - (texCoord - center) / size * .5; col += (pow(tex2D(Flare,coord),2) * 1) * 2; return col * tex2D(Scene,texCoord); } technique LightSourceMask { pass p0 { VertexShader = compile vs_4_0 VertexShaderFunction(); PixelShader = compile ps_4_0 LightSourceMaskPS(); } } I've removed default values as they are currently not support in MonoGame and also changed ps and vs to v4 instead of 2. Could this be causing the issue? As I debug through 'DXConstantBufferData' constructor (from within the MonoGameContentProcessing project) I find that the 'flare' parameter does not exist. All others seem to be getting created fine. Any help would be appreciated. Update 1 I have discovered that SharpDX D3D compiler is what seems to be ignoring this parameter (perhaps by design?). The ConstantBufferDescription.VariableCount seems to be not counting the texture variable. Update 2 SharpDX function 'GetConstantBuffer(int index)' returns the parameters (minus textures) which is making is impossible to set values to these variables within the shader. Any one know if this is normal for DX11 / Shader Model 4.0? Or am I missing something else?

    Read the article

  • Setting uniform value of a vertex shader for different sprites in a SpriteBatch

    - by midasmax
    I'm using libGDX and currently have a simple shader that does a passthrough, except for randomly shifting the vertex positions. This shift is a vec2 uniform that I set within my code's render() loop. It's declared in my vertex shader as uniform vec2 u_random. I have two different kind of Sprites -- let's called them SpriteA and SpriteB. Both are drawn within the same SpriteBatch's begin()/end() calls. Prior to drawing each sprite in my scene, I check the type of the sprite. If sprite instance of SpriteA: I set the uniform u_random value to Vector2.Zero, meaning that I don't want any vertex changes for it. If sprite instance of SpriteB, I set the uniform u_random to Vector2(MathUtils.random(), MathUtils.random(). The expected behavior was that all the SpriteA objects in my scene won't experience any jittering, while all SpriteB objects would be jittering about their positions. However, what I'm experiencing is that both SpriteA and SpriteB are jittering, leading me to believe that the u_random uniform is not actually being set per Sprite, and being applied to all sprites. What is the reason for this? And how can I fix this such that the vertex shader correctly accepts the uniform value set to affect each sprite individually? passthrough.vsh attribute vec4 a_color; attribute vec3 a_position; attribute vec2 a_texCoord0; uniform mat4 u_projTrans; uniform vec2 u_random; varying vec4 v_color; varying vec2 v_texCoord; void main() { v_color = a_color; v_texCoord = a_texCoord0; vec3 temp_position = vec3( a_position.x + u_random.x, a_position.y + u_random.y, a_position.z); gl_Position = u_projTrans * vec4(temp_position, 1.0); } Java Code this.batch.begin(); this.batch.setShader(shader); for (Sprite sprite : sprites) { Vector2 v = Vector2.Zero; if (sprite instanceof SpriteB) { v.x = MathUtils.random(-1, 1); v.y = MathUtils.random(-1, 1); } shader.setUniformf("u_random", v); sprite.draw(this.batch); } this.batch.end();

    Read the article

  • How to get skin tone color pixel in iPhone?

    - by aman-gupta
    Hi In my application I m using following way to get red pixel in a image // // PixelsAccessAppDelegate.h // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright MyCompanyName 2010. All rights reserved. // import @class clsPixelAccess; NSUInteger numberOfRedPixels; NSUInteger numberOfRedPixels1; NSUInteger numberOfRedPixels2; NSUInteger numberOfRedPixels3; NSUInteger numberOfRedPixels4; NSUInteger numberOfRedPixels5; NSUInteger numberOfRedPixels6; NSUInteger numberOfRedPixels7; NSUInteger numberOfRedPixels8; NSUInteger numberOfRedPixels9; NSUInteger numberOfRedPixels10; NSUInteger numberOfRedPixels11; NSUInteger numberOfRedPixels12; NSUInteger numberOfRedPixels13; NSUInteger numberOfRedPixels14; NSUInteger numberOfRedPixels15; NSUInteger numberOfRedPixels16; NSUInteger numberOfRedPixels17; NSUInteger numberOfRedPixels18; NSUInteger numberOfRedPixels19; NSUInteger numberOfRedPixels20; NSUInteger numberOfRedPixels21; NSUInteger numberOfRedPixels22; NSUInteger numberOfRedPixels23; NSUInteger numberOfRedPixels24; NSUInteger numberOfRedPixels25; NSUInteger numberOfRedPixels26; NSUInteger numberOfRedPixels27; NSUInteger numberOfRedPixels28; NSUInteger numberOfRedPixels29; NSUInteger numberOfRedPixels30; NSUInteger numberOfRedPixels31; @interface PixelsAccessAppDelegate : NSObject { UIWindow *window; clsPixelAccess *obj; } @property (nonatomic, retain) IBOutlet UIWindow *window; -(IBAction)processImage:(id)sender; @end //////////////////// // // PixelsAccessAppDelegate.m // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright MyCompanyName 2010. All rights reserved. // import "PixelsAccessAppDelegate.h" import "clsPixelAccess.h" @implementation PixelsAccessAppDelegate @synthesize window; (IBAction)processImage:(id)sender { NSUInteger retVal; obj = [[clsPixelAccess alloc] init]; NSInteger imageSend =[obj processImage1:[UIImage imageNamed:@"s.jpg"]]; NSInteger iamgeCall =[obj getPixelData:retVal]; NSUInteger *numberOfRedPixels = retVal; //lblPixelCount.text = [NSString stringWithFormat: @"There are %d red pixels in the image", numberOfRedPixels]; } (void)applicationDidFinishLaunching:(UIApplication *)application { // Override point for customization after application launch [window makeKeyAndVisible]; } (void)dealloc { [window release]; [super dealloc]; } @end /////////////// // // clsPixelsAccess.h // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright 2010 MyCompanyName. All rights reserved. // import @interface clsPixelAccess : NSObject { } -(NSInteger) processImage1: (UIImage*) image; -(NSInteger)getPixelData:(NSUInteger *)pixelCount; @end ///////// // // clsPixelsAccess.m // PixelsAccess // // Created by Fortune1 on 14/04/10. // Copyright 2010 MyCompanyName. All rights reserved. // import "clsPixelAccess.h" import "PixelsAccessAppDelegate.h" @implementation clsPixelAccess struct pixel { //unsigned char r, g, b,a; Byte r, g, b, a; int count; }; -(NSInteger)getPixelData:(NSUInteger *)pixelCount { *pixelCount =numberOfRedPixels; return 1; } // Process the image and return the number of pure red pixels in it. (NSInteger) processImage1: (UIImage*) image { // Allocate a buffer big enough to hold all the pixels struct pixel* pixels = (struct pixel*) calloc(1, image.size.width * image.size.height * sizeof(struct pixel)); if (pixels != nil) { // Create a new bitmap CGContextRef context = CGBitmapContextCreate( (void*) pixels, image.size.width, image.size.height, 8, image.size.width * 4, CGImageGetColorSpace(image.CGImage), kCGImageAlphaPremultipliedLast ); //NSLog(@"1=%d, 2=%d, 3=%d", CGImageGetBitsPerComponent(image), CGImageGetBitsPerPixel(image),CGImageGetBytesPerRow(image)); if (context != NULL) { // Draw the image in the bitmap CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, image.size.width, image.size.height), image.CGImage); NSUInteger numberOfPixels = image.size.width * image.size.height; NSMutableArray *numberOfPixelsArray = [[[NSMutableArray alloc] initWithCapacity:numberOfPixelsArray] autorelease]; NSLog( @"Pixel data %d", numberOfPixelsArray); /* NSMatrix *newMatrix = [[NSMatrix alloc] initWithFrame:NSMakeRect(138.0f, 85.0f, 0.0f, 0.0f) mode:NSRadioModeMatrix prototype:prototypeButtonCell numberOfRows: numberOfColumns:]; */ while (numberOfPixels &gt; 0) { if (pixels-&gt;r &gt; 0 &amp;&amp; pixels-&gt;r &lt;= 7) { numberOfRedPixels++; } NSLog( @"Red pixel data %d",numberOfRedPixels); if (pixels-&gt;r &gt;= 8 &amp;&amp; pixels-&gt;r &lt;= 15) { numberOfRedPixels1++; } NSLog( @"Red pixel data1 %d",numberOfRedPixels1); if (pixels-&gt;r &gt;= 16 &amp;&amp; pixels-&gt;r &lt;=23 ) { numberOfRedPixels2++; } NSLog( @"Red pixel data2 %d",numberOfRedPixels2); if (pixels-&gt;r &gt;= 24 &amp;&amp; pixels-&gt;r &lt;=31 ) { numberOfRedPixels3++; } NSLog( @"Red pixel data3 %d",numberOfRedPixels3); if (pixels-&gt;r &gt;= 32 &amp;&amp; pixels-&gt;r &lt;= 39) { numberOfRedPixels4++; } NSLog( @"Red pixel data4 %d",numberOfRedPixels4); if (pixels-&gt;r &gt;= 40 &amp;&amp; pixels-&gt;r &lt;= 47) { numberOfRedPixels5++; } NSLog( @"Red pixel data5 %d",numberOfRedPixels5); if (pixels-&gt;r &gt;= 48 &amp;&amp; pixels-&gt;r &lt;= 55) { numberOfRedPixels6++; } NSLog( @"Red pixel data6 %d",numberOfRedPixels6); if(pixels-&gt;r &gt;= 56 &amp;&amp; pixels-&gt;r &lt;= 63) { numberOfRedPixels7++; } NSLog( @"Red pixel data7 %d",numberOfRedPixels7); if (pixels-&gt;r &gt;= 64 &amp;&amp; pixels-&gt;r &lt;= 71) { numberOfRedPixels8++; } NSLog( @"Red pixel data8 %d",numberOfRedPixels8); if (pixels-&gt;r &gt;= 72 &amp;&amp; pixels-&gt;r &lt;= 79) { numberOfRedPixels9++; } NSLog( @"Red pixel data9 %d",numberOfRedPixels9); if (pixels-&gt;r &gt;= 80 &amp;&amp; pixels-&gt;r &lt;= 87) { numberOfRedPixels10++; } NSLog( @"Red pixel data10 %d",numberOfRedPixels10); if (pixels-&gt;r &gt;= 88 &amp;&amp; pixels-&gt;r &lt;= 95) { numberOfRedPixels11++; } NSLog( @"Red pixel data11 %d",numberOfRedPixels11); if (pixels-&gt;r &gt;= 96 &amp;&amp; pixels-&gt;r &lt;= 103) { numberOfRedPixels12++; } NSLog( @"Red pixel data12 %d",numberOfRedPixels12); if (pixels-&gt;r &gt;= 104 &amp;&amp; pixels-&gt;r &lt;= 111) { numberOfRedPixels13++; } NSLog( @"Red pixel data13 %d",numberOfRedPixels13); if (pixels-&gt;r &gt;= 112 &amp;&amp; pixels-&gt;r &lt;= 119) { numberOfRedPixels14++; } NSLog( @"Red pixel data14 %d",numberOfRedPixels14); if (pixels-&gt;r &gt;= 120 &amp;&amp; pixels-&gt;r &lt;= 127) { numberOfRedPixels15++; } NSLog( @"Red pixel data15 %d",numberOfRedPixels15); if (pixels-&gt;r &gt; 128 &amp;&amp; pixels-&gt;r &lt;= 135) { numberOfRedPixels16++; } NSLog( @"Red pixel data16 %d",numberOfRedPixels16); if (pixels-&gt;r &gt;= 136 &amp;&amp; pixels-&gt;r &lt;= 143) { numberOfRedPixels17++; } NSLog( @"Red pixel data17 %d",numberOfRedPixels17); if (pixels-&gt;r &gt;= 144 &amp;&amp; pixels-&gt;r &lt;=151) { numberOfRedPixels18++; } NSLog( @"Red pixel data18 %d",numberOfRedPixels18); if (pixels-&gt;r &gt;= 152 &amp;&amp; pixels-&gt;r &lt;=159 ) { numberOfRedPixels19++; } NSLog( @"Red pixel data19 %d",numberOfRedPixels19); if (pixels-&gt;r &gt;= 160 &amp;&amp; pixels-&gt;r &lt;= 167) { numberOfRedPixels20++; } NSLog( @"Red pixel data20 %d",numberOfRedPixels20); if (pixels-&gt;r &gt;= 168 &amp;&amp; pixels-&gt;r &lt;= 175) { numberOfRedPixels21++; } NSLog( @"Red pixel data21 %d",numberOfRedPixels21); if (pixels-&gt;r &gt;= 176 &amp;&amp; pixels-&gt;r &lt;= 199) { numberOfRedPixels22++; } NSLog( @"Red pixel data22 %d",numberOfRedPixels22); if(pixels-&gt;r &gt;= 184 &amp;&amp; pixels-&gt;r &lt;= 191) { numberOfRedPixels23++; } NSLog( @"Red pixel data23 %d",numberOfRedPixels23); if (pixels-&gt;r &gt;= 192 &amp;&amp; pixels-&gt;r &lt;= 199) { numberOfRedPixels24++; } NSLog( @"Red pixel data24 %d",numberOfRedPixels24); if (pixels-&gt;r &gt;= 200 &amp;&amp; pixels-&gt;r &lt;= 207) { numberOfRedPixels25++; } NSLog( @"Red pixel data25 %d",numberOfRedPixels25); if (pixels-&gt;r &gt;= 208 &amp;&amp; pixels-&gt;r &lt;= 215) { numberOfRedPixels26++; } NSLog( @"Red pixel data26 %d",numberOfRedPixels26); if (pixels-&gt;r &gt;= 216 &amp;&amp; pixels-&gt;r &lt;= 223) { numberOfRedPixels27++; } NSLog( @"Red pixel data27 %d",numberOfRedPixels27); if (pixels-&gt;r &gt;= 224 &amp;&amp; pixels-&gt;r &lt;= 231) { numberOfRedPixels28++; } NSLog( @"Red pixel data28 %d",numberOfRedPixels28); if (pixels-&gt;r &gt;= 232 &amp;&amp; pixels-&gt;r &lt;= 239) { numberOfRedPixels29++; } NSLog( @"Red pixel data29 %d",numberOfRedPixels29); if (pixels-&gt;r &gt;= 240 &amp;&amp; pixels-&gt;r &lt;= 247) { numberOfRedPixels30++; } NSLog( @"Red pixel data30 %d",numberOfRedPixels30); if (pixels-&gt;r &gt;= 248) { numberOfRedPixels31++; } NSLog( @"Red pixel data31 %d",numberOfRedPixels31); pixels++; numberOfPixels--; } CGContextRelease(context); } free(pixels); } return 1; } @end My problem is I want skin Tone Pixel how it could be possible Please help me out. Thanks in Advance

    Read the article

  • Passing Boost uBLAS matrices to OpenGL shader

    - by AJM
    I'm writing an OpenGL program where I compute my own matrices and pass them to shaders. I want to use Boost's uBLAS library for the matrices, but I have little idea how to get a uBLAS matrix into OpenGL's shader uniform functions. matrix<GLfloat, column_major> projection(4, 4); // Fill matrix ... GLuint projectionU = glGetUniformLocation(shaderProgram, "projection"); glUniformMatrix4fv(projectionU, 1, 0, (GLfloat *)... Um ...); Trying to cast the matrix to a GLfloat pointer causes an invalid cast error on compile.

    Read the article

  • How to set Alpha value from pixel shader in SlimDX Direct3d9

    - by Yashwinder
    I am trying to set alpha value of color as color.a = 0.5f in my pixel shader but all the time it is giving an exception. I can set color.r, color.g, color.b but it is not allowing me to set color.a and throwing an exception D3DERR_INVALIDCALL: Invalid call (-2005530516). I have just created a direct3d9 device and assigned my pixel shader to it. My pixel shader code is as below sampler2D ourImage : register(s0); float4 main(float2 locationInSource : TEXCOORD) : COLOR { float4 color = tex2D( ourImage , locationInSource.xy); color.a = 0.2; return color; } I am creating my pixel shader as byte[] byteCode = GiveFxFile(transitionEffect.PixelShaderFileName); var shaderBytecode = ShaderBytecode.Compile(byteCode, "main", "ps_2_0", ShaderFlags.None); var pixelShader = new PixelShader(device, ShaderBytecode); _device.PixelShader=pixelShader; I have initialized my device as var _presentParams = new PresentParameters { Windowed = _isWindowedMode, BackBufferWidth = (int)SystemParameters.PrimaryScreenWidth, BackBufferHeight = (int)SystemParameters.PrimaryScreenHeight, // Enable Z-Buffer // This is not really needed in this sample but real applications generaly use it EnableAutoDepthStencil = true, AutoDepthStencilFormat = Format.D16, // How to swap backbuffer in front and how many per screen refresh BackBufferCount = 1, SwapEffect = SwapEffect.Copy, BackBufferFormat = _direct3D.Adapters[0].CurrentDisplayMode.Format, PresentationInterval = PresentInterval.Immediate, DeviceWindowHandle = _windowHandle }; _device = new Device(_direct3D, 0, DeviceType.Hardware, _windowHandle, deviceFlags | CreateFlags.Multithreaded, _presentParams);

    Read the article

  • What is the minimum of shader I need to use to run basic calculation on GPU?

    - by Jinxi
    I read, that the Hull Shader, Domain Shader, Geometry Shader and Pixel Shader can be used optional. So, is the Vertex Shader optional too? If no: What does a basic Vertex Shader look like? Just like a simple pass through? Is the Vertex Shader necessary to tell what kind of datastructure (Van Stripes or Meshes) are used? What can I do, with just the vertex shader? Are the fixed functions working without any help of programming a programmable stage?

    Read the article

  • Image/"most resembling pixel" search optimization?

    - by SigTerm
    The situation: Let's say I have an image A, say, 512x512 pixels, and image B, 5x5 or 7x7 pixels. Both images are 24bit rgb, and B have 1bit alpha mask (so each pixel is either completely transparent or completely solid). I need to find within image A a pixel which (with its' neighbors) most closely resembles image B, OR the pixel that probably most closely resembles image B. Resemblance is calculated as "distance" which is sum of "distances" between non-transparent B's pixels and A's pixels divided by number of non-transparent B's pixels. Here is a sample SDL code for explanation: struct Pixel{ unsigned char b, g, r, a; }; void fillPixel(int x, int y, SDL_Surface* dst, SDL_Surface* src, int dstMaskX, int dstMaskY){ Pixel& dstPix = *((Pixel*)((char*)(dst->pixels) + sizeof(Pixel)*x + dst->pitch*y)); int xMin = x + texWidth - searchWidth; int xMax = xMin + searchWidth*2; int yMin = y + texHeight - searchHeight; int yMax = yMin + searchHeight*2; int numFilled = 0; for (int curY = yMin; curY < yMax; curY++) for (int curX = xMin; curX < xMax; curX++){ Pixel& cur = *((Pixel*)((char*)(dst->pixels) + sizeof(Pixel)*(curX & texMaskX) + dst->pitch*(curY & texMaskY))); if (cur.a != 0) numFilled++; } if (numFilled == 0){ int srcX = rand() % src->w; int srcY = rand() % src->h; dstPix = *((Pixel*)((char*)(src->pixels) + sizeof(Pixel)*srcX + src->pitch*srcY)); dstPix.a = 0xFF; return; } int storedSrcX = rand() % src->w; int storedSrcY = rand() % src->h; float lastDifference = 3.40282347e+37F; //unsigned char mask = for (int srcY = searchHeight; srcY < (src->h - searchHeight); srcY++) for (int srcX = searchWidth; srcX < (src->w - searchWidth); srcX++){ float curDifference = 0; int numPixels = 0; for (int tmpY = -searchHeight; tmpY < searchHeight; tmpY++) for(int tmpX = -searchWidth; tmpX < searchWidth; tmpX++){ Pixel& tmpSrc = *((Pixel*)((char*)(src->pixels) + sizeof(Pixel)*(srcX+tmpX) + src->pitch*(srcY+tmpY))); Pixel& tmpDst = *((Pixel*)((char*)(dst->pixels) + sizeof(Pixel)*((x + dst->w + tmpX) & dstMaskX) + dst->pitch*((y + dst->h + tmpY) & dstMaskY))); if (tmpDst.a){ numPixels++; int dr = tmpSrc.r - tmpDst.r; int dg = tmpSrc.g - tmpDst.g; int db = tmpSrc.g - tmpDst.g; curDifference += dr*dr + dg*dg + db*db; } } if (numPixels) curDifference /= (float)numPixels; if (curDifference < lastDifference){ lastDifference = curDifference; storedSrcX = srcX; storedSrcY = srcY; } } dstPix = *((Pixel*)((char*)(src->pixels) + sizeof(Pixel)*storedSrcX + src->pitch*storedSrcY)); dstPix.a = 0xFF; } This thing is supposed to be used for texture generation. Now, the question: The easiest way to do this is brute force search (which is used in example routine). But it is slow - even using GPU acceleration and dual core cpu won't make it much faster. It looks like I can't use modified binary search because of B's mask. So, how can I find desired pixel faster? Additional Info: It is allowed to use 2 cores, GPU acceleration, CUDA, and 1.5..2 gigabytes of RAM for the task. I would prefer to avoid some kind of lengthy preprocessing phase that will take 30 minutes to finish. Ideas?

    Read the article

  • Encode two integers into colour values and compare them in a HLSL shader

    - by Ben Slinger
    I am writing a 2D point and click adventure game in Monogame, and I'd like to be able to create an image mask for every room which defines which parts of the background a character can walk behind, and at which Y value a character needs to be at for the background to be drawn above the character. I haven't done any shader work before but after doing some reading I thought the following solution should work: Create a mask for the room with different walk behind areas painted in a colour that defines the baseline Y value (Walk Behind Mask) Render all objects to a RenderTarget2D (Base Texture) Render all objects to a different RenderTarget2D, but changing every pixel of each object to a colour that defines its Y value (Position Mask) Pass these two textures plus the image mask into the shader, and for each pixel compare the colour of the image mask to the colour of the Position Mask to the Walk Behind Mask - if the Position Mask pixel is larger (thus lower on the screen and closer to the camera) than the Walk Behind Mask, draw the pixel from the Base Texture, otherwise draw a transparent pixel (allowing the background to show through). I've got it mostly working, but I'm having trouble packing and unpacking the Y values into colours and retrieving them correctly in the shader. Here are some code examples of how I'm doing it so far: (When drawing to the Position Mask RenderTarget2D) Color posColor = new Color(((int)Position.Y >> 16) & 255, ((int)Position.Y >> 8) & 255, (int)Position.Y & 255); So as far as I can tell, this should be taking the first 3 bytes of the position integer and encoding them into a 4 byte colour (ignoring the alpha as the 4th byte). This seems to work fine, as when my character is at Y = 600, the resulting Color from this is: {[Color: R=0, G=2, B=88, A=255, PackedValue=4283957760]}. I then have an area in my Walk Behind Mask that I only want the character to be displayed behind if his Y value is lower than 655, so I've painted it with R=0, G=2, B=143, A=255. Now, I think I have the shader OK as well, here's what I have: sampler BaseTexture : register(s0); sampler MaskTexture : register(s1); sampler PositionTexture : register(s2); float4 mask( float2 coords : TEXCOORD0 ) : COLOR0 { float4 color = tex2D(BaseTexture, coords); float4 maskColor = tex2D(MaskTexture, coords); float4 positionColor = tex2D(PositionTexture, coords); float maskCompare = (maskColor.r * pow(2,24)) + (maskColor.g * pow(2,16)) + (maskColor.b * pow(2,8)); float positionCompare = (positionColor.r * pow(2,24)) + (positionColor.g * pow(2,16)) + (positionColor.b * pow(2,8)); return positionCompare < maskCompare ? float4(0,0,0,0) : color; } technique Technique1 { pass NoEffect { PixelShader = compile ps_3_0 mask(); } } This isn't working, however - currently all characters are displayed behind the walk behind area, regardless of their Y value. I tried printing out some debug info by grabbing the pixel from both the Position Mask and the Walk Under Mask under the current mouse position, and it seems like maybe the colours aren't being rendered to the Position Mask correctly? When calculating the colour in that code above I'm getting R=0, G=2, B=88, A=255, but when I mouseover my character I get R=0, G=0, B=30, A=255. Any ideas what I'm doing wrong? It seems like maybe I'm losing some information when rendering to the RenderTarget2D, but I'm now knowledgeable enough to figure out what's happening. Also, I should probably ask, is this an efficient way to do this? Will there be a performance impact? Edit: Whoops, turns out there was a bug that I'd introduced myself, I was drawing out the Position Mask with the position Color, left over from some early testing I was doing. So this solution is working perfectly, though I'm still interested in whether this is an efficient solution performance wise.

    Read the article

  • HLSL, Program pixel shader with different Texture2D downscaling algorithms

    - by Kaminari
    I'm trying to port some image interpolation algorithms into HLSL code, for now i got: float2 texSize; float scale; int method; sampler TextureSampler : register(s0); float4 PixelShader(float4 color : COLOR0, float2 texCoord : TEXCOORD0) : COLOR0 { float2 newTexSize = texSize * scale; float4 tex2; if(texCoord[0] * texSize[0] > newTexSize[0] || texCoord[1] * texSize[1] > newTexSize[1]) { tex2 = float4( 0, 0, 0, 0 ); } else { if (method == 0) { tex2 = tex2D(TextureSampler, float2(texCoord[0]/scale, texCoord[1]/scale)); } else { float2 step = float2(1/texSize[0], 1/texSize[1]); float4 px1 = tex2D(TextureSampler, float2(texCoord[0]/scale-step[0], texCoord[1]/scale-step[1])); float4 px2 = tex2D(TextureSampler, float2(texCoord[0]/scale , texCoord[1]/scale-step[1])); float4 px3 = tex2D(TextureSampler, float2(texCoord[0]/scale+step[0], texCoord[1]/scale-step[1])); float4 px4 = tex2D(TextureSampler, float2(texCoord[0]/scale-step[0], texCoord[1]/scale )); float4 px5 = tex2D(TextureSampler, float2(texCoord[0]/scale+step[0], texCoord[1]/scale )); float4 px6 = tex2D(TextureSampler, float2(texCoord[0]/scale-step[0], texCoord[1]/scale+step[1])); float4 px7 = tex2D(TextureSampler, float2(texCoord[0]/scale , texCoord[1]/scale+step[1])); float4 px8 = tex2D(TextureSampler, float2(texCoord[0]/scale+step[0], texCoord[1]/scale+step[1])); tex2 = (px1+px2+px3+px4+px5+px6+px7+px8)/8; tex2.a = 1; } } return tex2; } technique Resample { pass Pass1 { PixelShader = compile ps_2_0 PixelShader(); } } The problem is that programming pixel shader requires different approach because we don't have the control of current position, only the 'inner' part of actual loop through pixels. I've been googling for about whole day and found none open source library with scaling algoriths used in loop. Is there such library from wich i could port some methods? I found http://www.codeproject.com/KB/GDI-plus/imgresizoutperfgdiplus.aspx but I really don't understand His approach to the problem, and porting it will be a pain in the ... Wikipedia tells a matematic approach. So my question is: Where can I find easy-to-port graphic open source library wich includes simple scaling algorithms? Of course if such library even exists :)

    Read the article

  • Shader effect similar to Metro 2033 gasmask

    - by Tim
    I was thinking about effects in games the other day and I was reminded of the Gasmask effect from Metro 2033. Once you put the gasmask on it blurred a bit in the corners and could ice up and even get cracked. I assume that something like that is done using a shader. I have been experimenting a bit with game development, so far mostly playing with existing rendering engines and adding physics support etc. I would like to learn more about this sort of effect. Can someone give me a simple example of a shader that would alter the entire scene like this. Or if not a shader then an idea on how it would be done. Thanks. Edit : Include screenshot of the metro 2033 gasmask effect.

    Read the article

  • OpenGL ES 2.0: Vertex and Fragment Shader for 2D with Transparency

    - by Bunkai.Satori
    Could I knindly ask for correct examples of OpenGL ES 2.0 Vertex and Fragment shader for displaying 2D textured sprites with transparency? I have fairly simple shaders that display textured polygon pairs but transparency is not applied despite: texture map contains transparency information Blending is enabled: glEnable(GL_BLEND); glEnable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); My Vertex Shader: uniform mat4 uOrthoProjection; uniform vec3 Translation; attribute vec4 Position; attribute vec2 TextureCoord; varying vec2 TextureCoordOut; void main() { gl_Position = uOrthoProjection * (Position + vec4(Translation, 0)); TextureCoordOut = TextureCoord; } My Fragment Shader: varying mediump vec2 TextureCoordOut; uniform sampler2D Sampler; void main() { gl_FragColor = texture2D(Sampler, TextureCoordOut); }

    Read the article

  • Bitwise operators in DX9 ps_2_0 shader

    - by lapin
    I've got the following code in a shader: // v & y are both floats nPixel = v; nPixel << 8; nPixel |= y; and this gives me the following error in compilation: shader.fx(80,10): error X3535: Bitwise operations not supported on legacy targets. shader.fx(92,18): ID3DXEffectCompiler::CompileEffect: There was an error compiling expression ID3DXEffectCompiler: Compilation failed The error is on the following line: nPixel |= y; What am I doing wrong here?

    Read the article

  • Cool examples of procedural pixel shader effects?

    - by Robert Fraser
    What are some good examples of procedural/screen-space pixel shader effects? No code necessary; just looking for inspiration. In particular, I'm looking for effects that are not dependent on geometry or the rest of the scene (would look okay rendered alone on a quad) and are not image processing (don't require a "base image", though they can incorporate textures). Multi-pass or single-pass is fine. Screenshots or videos would be ideal, but ideas work too. Here are a few examples of what I'm looking for (all from the RenderMonkey samples): PS - I'm aware of this question; I'm not asking for a source of actual shader implementations but instead for some inspirational ideas -- and the ones at the NVIDIA Shader Library mostly require a scene or are image processing effects. EDIT: this is an open-ended question and I wish there was a good way to split the bounty. I'll award the rep to the best answer on the last day.

    Read the article

  • PCF shadow shader math causing artifacts

    - by user2971069
    For a while now I used PCSS for my shadow technique of choice until I discovered a type of percentage closer filtering. This method creates really smooth shadows and with hopes of improving performance, with only a fraction of texture samples, I tried to implement PCF into my shader. This is the relevant code: float c0, c1, c2, c3; float f = blurFactor; float2 coord = ProjectedTexCoords; if (receiverDistance - tex2D(lightSampler, coord + float2(0, 0)).x > 0.0007) c0 = 1; if (receiverDistance - tex2D(lightSampler, coord + float2(f, 0)).x > 0.0007) c1 = 1; if (receiverDistance - tex2D(lightSampler, coord + float2(0, f)).x > 0.0007) c2 = 1; if (receiverDistance - tex2D(lightSampler, coord + float2(f, f)).x > 0.0007) c3 = 1; coord = (coord % f) / f; return 1 - (c0 * (1 - coord.x) * (1 - coord.y) + c1 * coord.x * (1 - coord.y) + c2 * (1 - coord.x) * coord.y + c3 * coord.x * coord.y); This is a very basic implementation. blurFactor is initialized with 1 / LightTextureSize. So the if statements fetch the occlusion values for the four adjacent texels. I now want to weight each value based on the actual position of the texture coordinate. If it's near the bottom-right pixel, that occlusion value should be preferred. The weighting itself is done with a simple bilinear interpolation function, however this function takes a 2d vector in the range [0..1] so I have to convert my texture coordinate to get the distance from my first pixel to the second one in range [0..1]. For that I used the mod operator to get it into [0..f] range and then divided by f. This code makes sense to me, and for specific blurFactors it works, producing really smooth one pixel wide shadows, but not for all blurFactors. Initially blurFactor is (1 / LightTextureSize) to sample the 4 adjacent texels. I now want to increase the blurFactor by factor x to get a smooth interpolation across maybe 4 or so pixels. But that is when weird artifacts show up. Here is an image: Using a 1x on blurFactor produces a good result, 0.5 is as expected not so smooth. 2x however doesn't work at all. I found that only a factor of 1/2^n produces an good result, every other factor produces artifacts. I'm pretty sure the error lies here: coord = (coord % f) / f; Maybe the modulo is not calculated correctly? I have no idea how to fix that. Is it even possible for pixel that are further than 1 pixel away?

    Read the article

  • New to CG shader programming, what program should I use to write and test them?

    - by Notbad
    I have started witting some shaders. First ones were fairly easy to write in notepad but now I need something with a bit more meat. I have checked rendermonnkey that seems to support CG but it is really old and don't know if it is a good option. On the other hand there exist this FX Composer 2.0 but it seems somthing that could really distract me from learning shaders because it seems a pretty deep program. Are there any other possibilities? There's a really nice alternative to write shaders named ShaderToy but just supports GLSL. Any information will be really welcomed. Thanks in advance.

    Read the article

  • C# GDI - How to check if a Pixel is opaque or not?

    - by rkawano
    I am using a method to get a pixel of the image to check if this point is transparent or not. I am using GetPixel that returns a System.Drawing.Color with a 32bit color info. This struct have the "A" property where I can get the alpha value of pixel, according to this MSDN topic. Code: using (Bitmap bmp = new Bitmap(path)) { Color pixel = bmp.GetPixel(0, 0); if (pixel.A == 0) // This is a fully transparent pixel else // This is not a fully transparent pixel } When I use this method with a fully transparent PNG images it returns 0. When I run with a white semi-transparent images, it will give me other values starting on 1 and up to 86, where 86 are given for images with a 100% alfa (full opaque). But with opaque JPEG images, the "A" property are giving me all sort of values like 56, 71, 86, 129, and others, depending on image. But these pixels are fully opaques! How are the correct way to check if a pixel is opaque or not?

    Read the article

  • Access to a single pixel in C#

    - by Malki
    Hello, I'm working on a school project right now. It's meant to be a 3D editing software, (like a very minimized version of Maya). I have to write it in C#, using the 'Windows Application Project'. I intend to implement all the 3D stuff myself, from projections to shading. My question is, how can I get direct access to a single pixel in the C# windows application? I know I'm going to have a main view port in the window. But I haven't decided yet how it will be made. Is there a built in object that I can use, that will let me define the boundaries of the view port, and then paint each pixel individually? (I'm just shooting in the dark here, I don't know much about C#. I mostly program in C) Thanks, Malki.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >