Page 47 of 91

Re: "Questions that don't deserve their own thread" thread

Posted: Wed Feb 10, 2016 3:57 pm
by bobbyjones
Ranguna259 wrote:
bobbyjones wrote:You don't need to. Just ship the binaries and load them up. You don't have to recompile love for them.
The problem is I can't find the binaries anywhere, I can't compile the code on windows and I wasn't talking about recompiling love, I wanted to compile the code through luaJIT's FFI, which would load the c code inside Lua.
That seems complicated. I mean you probably could try that but I think it would probably take awhile for it to compile. Rather than doing that it would be much better and faster if you just used ffi to wrap libcrypto. That way you can just wrap what you need.

Re: "Questions that don't deserve their own thread" thread

Posted: Thu Feb 11, 2016 8:44 am
by Ranguna259
That's what I said, compile luacrypto though FFI, but I don't know how to do that either.

Re: "Questions that don't deserve their own thread" thread

Posted: Thu Feb 11, 2016 8:56 am
by bobbyjones
No meant use ffi to wrap libcrypto which should be available everywhere.

Re: "Questions that don't deserve their own thread" thread

Posted: Thu Feb 11, 2016 12:47 pm
by Ranguna259
And how would I do that ?

Re: "Questions that don't deserve their own thread" thread

Posted: Thu Feb 11, 2016 4:49 pm
by bobbyjones
Here is an example of an ffi binding. It will result in a faster binding and should be easier because libcrypto is part of openssl so it should be available everywhere. And if it's not it will have binaries for everywhere.
https://github.com/LPGhatguy/luajit-request

Edit: just in case it was unclear (I usually do make unclear posts) the example was not an example of libcrypto but just of ffi bindings in general.

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Feb 13, 2016 6:42 am
by binaryeye
I'm new to writing shaders and having some trouble. I'm using six specific colors in my game, each with a bright and dark version like the CGA palette (e.g. light red is 255/85/85, dark red is 170/0/0, etc.). I'm attempting to implement a "water" shader that returns light cyan (85/255/255) for all light colors and dark cyan (0/170/170) for all dark colors. The code below is returning light cyan even for dark colors and I don't understand why. What am I doing wrong? Any help would be appreciated!

Code: Select all

    vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
      vec4 pixel = Texel(texture, texture_coords);
      if (pixel.a > 0.0) {              
        if (pixel.r == 1.0 || pixel.g == 1.0 || pixel.b == 1.0) return vec4(85.0/255.0, 1.0, 1.0, 1.0);
        else return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0);        
      }            
    }
I'd also like the shader to catch light gray (170/170/170) as a light color, but at this point I'd simply like to learn why the above doesn't work.

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Feb 13, 2016 11:59 am
by Ranguna259
I belive you forgot to open brackets on the second if, try this:

Code: Select all

    vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
      vec4 pixel = Texel(texture, texture_coords);
      if (pixel.a > 0.0) {              
        if (pixel.r == 1.0 || pixel.g == 1.0 || pixel.b == 1.0) {
          return vec4(85.0/255.0, 1.0, 1.0, 1.0);
       } 
       return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0);        
      }            
    }
But your code will return vec4(85.0/255.0, 1.0, 1.0, 1.0) for all pixel that have at least one of their rgb values set to 255 and it will return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0) for all other pixels.

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Feb 13, 2016 2:47 pm
by Evine
Something like this might work:

Code: Select all

    vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
      vec4 pixel = Texel(texture, texture_coords);
      if (pixel.a > 0.0) {              
        if (pixel.r > (254.5/255.0) || pixel.g > (254.5/255.0) || pixel.b > (254.5/255.0))
        	return vec4(85.0/255.0, 1.0, 1.0, 1.0);
        else
        	return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0);        
      }            
    }
Doing "==" comparison on floating point numbers is always a bit finicky. So I changed it so it checks if the input value is greater than 254.5 instead.

Also code readability is nice. So i'd recommend at least putting if statements and code on separate lines.

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Feb 13, 2016 3:56 pm
by binaryeye
Thanks for the suggestions. Unfortunately, neither work. I tried both in my actual game code as well as a separate test file, and both return light cyan when given dark red.
Evine wrote:Doing "==" comparison on floating point numbers is always a bit finicky. So I changed it so it checks if the input value is greater than 254.5 instead.
I figured as much. My original approach was to check if the sum of the RGB channels is greater than 1.5. The highest value dark color (e.g. 170/170/0) sums to 1.333; the lowest value bright color (e.g. 255/85/85) sums to 1.666. But this doesn't work, either. I've attached an example file. The draw color is set to 170/0/0 and the shader code is this:

Code: Select all

    vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
      vec4 pixel = Texel(texture, texture_coords);
      if (pixel.a > 0.0) {              
        if ((pixel.r + pixel.g + pixel.b) > 1.5)
          return vec4(85.0/255.0, 1.0, 1.0, 1.0);
        else
          return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0);        
      }            
    }
I'm beginning to wonder if it's my machine, but I'm using another shader that works fine.

Re: "Questions that don't deserve their own thread" thread

Posted: Sat Feb 13, 2016 6:02 pm
by Evine
Ah now I see the mistake you made. When you're using shaders the color that is set with love.graphics.setColor() and the pixel color of an image is two different arguments passed into the shader. "vec4 color" being the love.graphics.setColor() color and "Image texture" being the image pixels.

Because a primitive shape pixel color can only be vec4(0,0,0,0) or vec4(1,1,1,1) you only need to an if on the color value.

Code: Select all

    vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
      vec4 pixel = Texel(texture, texture_coords);
      if (pixel.a > 0.0) {              
        if ((color.r + color.g + color.b) > 1.5)
          return vec4(85.0/255.0, 1.0, 1.0, 1.0);
        else
          return vec4(0.0, 170.0/255.0, 170.0/255.0, 1.0);        
      }            
    }