Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Member Since 28 Feb 2011
Offline Last Active Today, 09:25 AM

#5187978 Extracting surface reflectance or lightning intensity from a single image.

Posted by Bacterius on 19 October 2014 - 07:29 AM

The surface normal can be retrieved from either a depth texture (if available) or approximated by gradient methods. The light direction will have to be inferred from surrounding context (specular lobes, shadows, are all good indicators of the direction of the light source - if you are outside, know your position, view direction, and the time of day/year, latitude and longitude, you can determine the Sun's position relative to you and work out the sunlight's direction). Once you have all that, you just calculate the dot product and solve for the reflectance. But getting the normal and light direction mechanically will probably require some serious computer vision algorithms if you want to automate it somehow.


Not to mention that you are completely ignoring the light's intensity (dependent on the light itself, and on its distance from the surface if it's not too far away). And, of course, this is valid only for a single light source. If you have multiple light sources, things get tricky.


Do you have examples of images you need to work on?

#5187757 point & Octahedron relationship

Posted by Bacterius on 17 October 2014 - 07:25 PM

In 2d, shoot a ray out in any direction. If it crosses the lines of the shape an even number of times (0 is even here), you are outside. If it crosses odd number of times you are inside.


Note this also works in 3D if the polygon is closed. It's a pretty elegant (if intuitively obvious) theorem.

#5186588 Why do unused game assets get stored in the game?

Posted by Bacterius on 12 October 2014 - 07:14 PM

Plus, if there are unused assets then modders can always use them to easily create new content.

#5185967 Portability: am I guaranteed for union size/base address to be the same on va...

Posted by Bacterius on 09 October 2014 - 06:30 AM

It is guaranteed that the address of the union is equal to the address of all members of the union, and to be "at offset 0" in the sense that the difference between two equal pointers is tautologically zero. The union is not guaranteed to be 64 bytes long because of implementation-defined size of int, unsigned int, float, and implementation-defined structure padding and alignment requirements (though none of the structures in the union are particularly problematic here as they all contain arrays or single members) but it usually will be on a typical system.

It is legal to cast a pointer to the union to a void pointer, a pointer of type of any member of this union, or any compatible type(though reinterpreting one type into another may lead to a trap representation). Otherwise, you are breaking aliasing rules and it becomes implementation-defined behaviour. It is legal to memcpy to and from the union and the bytes copied in will be reinterpreted depending on the type of the union member they are read through (again possibly resulting in a trap representation) while any padding bits will be left implementation-defined. And attempting to read those padding bytes is of course implementation-defined, so technically if you memcpy 64 bytes into the union and then inspect the 3x3 matrix member, the standard only guarantees the behaviour of reading the first 9 floats in the 4x4 matrix member, as the simple act of accessing the 3x3 matrix member has caused the last 7 bytes (which are now padding bytes for this type) to turn implementation-defined - here the "common initial sequence" rule kicks in because both structs are float arrays - writing to e.g. _int and then reading _float is clearly implementation-defined. But in practice compilers will just dump the bytes into the union and leave them alone and you can read them as you would expect)

Relevant quote from the standard (picked from a C89 draft, but I am certain it has not really changed in any later C or C++ standard as this is basic set-in-stone C stuff) emphasis mine: Structure and union specifiers

The size of a union is sufficient to contain the largest of its members. The value of at most one of the members can be stored in a union object at any time. A pointer to a union object, suitably cast, points to each of its members (or if a member is a bit-field, then to the unit in which it resides), and vice versa.

There may also be unnamed padding at the end of a structure or union, as necessary to achieve the appropriate alignment were the structure or union to be a member of an array. Structure and union members

With one exception, if a member of a union object is accessed after a value has been stored in a different member of the object, the behavior is implementation-defined.33 One special guarantee is made in order to simplify the use of unions: If a union contains several structures that share a common initial sequence, and if the union object currently contains one of these structures, it is permitted to inspect the common initial part of any of them. Two structures share a common initial sequence if corresponding members have compatible types for a sequence of one or more initial members.

All in all, it looks reasonably portable as presented here, it is certainly implementation-defined, but the sane kind that tends to work the same on typical systems. Beyond that, it depends on what you are going to do with the union, if you just want it to be a "variant" kind of type as I suspect, this will likely be fine. In any case, I agree with using uint32_t and so on because using plain ints anywhere but to hold small local temporary variables of little importance is asking for trouble, and if you really want to be sure you can always shoehorn portability into it with compiler pragmas, though I would not recommend doing that unless you really have to as it gets unmaintainable and dangerous very quickly.

#5185271 Memory Access Violation C++ freeglut

Posted by Bacterius on 06 October 2014 - 06:44 AM

Seems like you never initialize GLEW, which is the library which sets up all the post-1.1 opengl functions like glCreateShader (it does this dynamically, so at startup these just point to zero until you tell it to go fetch every opengl function it can get a hold of). Is this all your code or is there a glewInit() hiding somewhere where we can't see it?

#5184278 Bad code or usefull ...

Posted by Bacterius on 01 October 2014 - 04:31 AM

Ok, branching in this case is bad, but for a specific cases like this it is still possible to cast locally and avoid the branching. By adding the operator to the class it self you create a potential problem that can be hidden any where in the code base. (where a programmer feels like typing [i + 1] in staid of getY())


.. I'm not sure I understand what you mean. You are suggesting breaking into the internals of the vector by taking a pointer to x and incrementing it in this specific case, instead of using an operator[] specially designed for the task? How does that avoid safety issues at all, especially since like I said, proper implementation of this function is strongly coupled to how the vector struct is implemented with respect to its layout and so on? Seems to me it just muddles up the codebase with random casts. The operator[] offers a specific and well-defined functionality, there is nothing vague about it. Where should the line be drawn between "this operation is used twice in the entire codebase" and "the dot product is used everywhere so we made this dot function"?

#5184265 Bad code or usefull ...

Posted by Bacterius on 01 October 2014 - 03:32 AM

One example I can think of is when implementing kd-trees or a few other space-partitioning trees, you usually want to rotate through each coordinate for the split axis at each level of the tree (i.e. level 1 = split on x-axis, level 2 = split on y-axis, etc..). With the [] operator it amounts to working on vec[depth % 3], without it you are stuck with branching on the depth or unrolling three tree levels at a time (awful). In short, it gives you constant-time access to any coordinate based on an index, and is the kind of thing where you are essentially screwed if it's not provided.


That said another, simpler answer to your question is, why not? It does not cause any performance penalty compared to direct access, can potentially help awkward situations like the one I described above, and can be made strictly safe (wrt memory layout and stuff) and standards-conforming with little effort - in fact, zero effort for a properly implemented vector class. If it is never used, it won't even be included in the binary, and it will almost certainly be inlined in all use cases being a trivial function, so all it does is take up five lines of code maximum in your vector class for only potential gains. One could then argue that features need to be proven worthwhile before being added to a library, and I won't deny that (I would like to see more examples of the use of vec[] as well) but, honestly, how many other features can you think of providing with your vector class? I can think of more questionable ones than [].

#5184219 This chat, apparently, is a gigantic coding horror

Posted by Bacterius on 30 September 2014 - 09:34 PM

Okay, now that I've checked it's not "dirty" but "clean", close enough.. behold the cleanMessage() function:

function (message) {
  return message;

And the unCleanMessage() function:

function (message) {
  message=message.replace(/__N__/g,"<br />");
  return message;

Now take a look at what happens if you type in "=A=" for instance.. the two equal signs get replaced and so it gets encoded to "__E__A__E__". Which then promptly gets decoded to "__E&E__" as the middle part "__A__" happens to get replaced first. Oops laugh.png

#5184159 This chat, apparently, is a gigantic coding horror

Posted by Bacterius on 30 September 2014 - 04:05 PM

Yes, I actually found the code that caused that issue. It comes from some "dirtyMessage" and "undirtyMessage" functions (can't check the exact names now, try and grep the JS code for "dirty") in the javascript code that do exactly what you are saying: replacing special symbols by encoded values to send them over the network. But the encoding and decoding functions are not inverses of each other, and in some circumstances the encoding is ambiguous, which causes the decoding function to decode the wrong thing, resulting in the bug observed. Basically, whoever implemented it tried to be smart, and failed.


Should've just used base64.

#5183695 Casting a double to an IDirect3DDevice9*?

Posted by Bacterius on 29 September 2014 - 03:12 AM

Ah ok, It is probably a DWORD (been a long day). Actually a REAL is what it is defined as in the 3rd party API as it turns out. Does that sound right?


The problem is I keep getting an invalid pointer, so my DLL causes an immediate crash.


I don't know what the REAL type is. It's not a standard C or C++ type and does not appear in the Windows Data Types page. But a real is a numeric type representing a point on the real line (if you don't know what the real line is, "all the numbers" is a sufficiently accurate description) and is generally implemented as a floating-point type. So, no, I don't think that sounds right at all. What API is this? It must not be very sane if it returns pointers as floating-point values.

#5183118 code for doing something while the game is off

Posted by Bacterius on 26 September 2014 - 07:24 AM



i am trying to make a clicker game, but there is a problem faced me sad.png


how can i let the game does something while its off?


for example Cookie Clicker, when u close the game and then open it after 10 mins u will find ur cookies increased.


When the game closes, save the current time. When the game reopens, compute how long the game has been closed, and use that to work out any actions that might take place "as if" the game was still running during that time (without user input, obviously). You can't run code when the game isn't running, sorry.

#5182339 To Day I had to Resort To a FileBack Up

Posted by Bacterius on 23 September 2014 - 02:05 AM

Ok back. What about in the file revisions it said it was modified yesterday and for some reason the folder was set to shared as well yesterday at 7.51Am.

but When I checked to day its not shared ???? this is alarm bell to me not hard drive.

In fact I have a hard drive that is 20 years old working fine and Ive had like 25 years worth of computers and never had a hard drive fail.

I could go in the back room and start my very firts computer a IBM aptiva 166 heehehe(third Computer).


That's understandable. The first time a drive fails on someone they are confused and don't want to believe it could've happened to them, it's a distressing experience, especially since hard drive failures can often be more subtle and insidious than "cannot find boot sector". If you didn't have backups, having this happen to you is one way to get the point driven home (the hard way).




So can hard drive fail write a modified log.


Sure, why not. Where do you think the log is stored?




there was a unknow app in system configurations on startup some thing going by the name language_Application no install date its gone now.


This just means you are biased because you suspect a hacker has infliltrated your PC, so every little thing will look like a red flag to you. Be careful of cognitive bias when trying to draw logical conclusions from events you are emotionally connected to (and you obviously are in this case, given your reaction). You say you have backups, so use them:


1. Nuke your PC and reinstall the operating system (to alleviate your - irrational - fear of hackers)

2. Run hard drive tests and replace the drive if bad

3. Restore all files from backup

4. Resume normal life


This shouldn't take more than about a day, spent mostly reinstalling software.


Besides, let's assume for a second that your doubts are justified and this is the result of malice. If your computer really was targeted by someone, don't you think he'd have better things to do than randomly corrupt a file you haven't opened in years? Wouldn't he just go for your source code, erase his tracks as discreetly as possible, and then boast loudly about it on the internet? Very little malware is specifically targeted, and it always is targeted at high-profile entities like terrorists, nuclear facilities, or high-ranking officials (we call them APT's for advanced persistent threat). Most of the stuff you'll get on an average consumer PC is spyware and generic trojans that just scan for passwords, email addresses, credit card numbers, and use your residential line to send spam email as part of a botnet. They are nearly fully automated. They certainly don't search for game source code, and there is no-one at the other end trolling you by flipping bits on your hard drive smile.png


I'm not saying it's guaranteed to be a hard drive failure, just that given the choice between that and a hacker stealing your source code, I would certainly find the hard drive failure a more likely explanation. But like Promit said, there could be many other causes, none of which can be remotely diagnosed. So try to relax - you (probably) aren't under attack, investigate the problem, but keep your expectations real. The causes of your malfunctions probably are much more mundane than what you're picturing them to be.

#5182313 To Day I had to Resort To a FileBack Up

Posted by Bacterius on 22 September 2014 - 10:42 PM

Or maybe your hard drive is just dying. You know, just a thought.

#5181463 Graphics without drivers?

Posted by Bacterius on 19 September 2014 - 12:44 AM

Run your program through a DOS emulator, then you can use all those old-school techniques wink.png

Or even just write a bootloader and a basic C kernel and boot it in a VM, that works too. There's even code online that implements a simple VGA driver for an example (1-file) "operating system". I don't think you can directly access the VGA framebuffer under modern operating systems anyway, at least not easily. I would think even enabling the required VGA mode requires your process to be in kernel land to begin with, especially since your address space would be virtualized anyway in userland so your 0xB8000 address wouldn't be of any use.


Well, on Linux you could always try mapping the graphics card's memory into virtual memory through /proc/, but that will probably not produce the results you want laugh.png

#5180972 how to represent this number

Posted by Bacterius on 17 September 2014 - 05:22 AM

So how I select the odd number?...whut?....what is the problem with selecting a random odd number? the probability of selecting a random odd number is the same for all odd numbers in the set

Right, and there infinitely many of them, so they can't have the same probability of being selected. Please, read this: http://math.stackexchange.com/questions/500545/why-does-the-probability-of-a-random-natural-number-being-prime-make-no-sense (first paragraph of the first answer) and think again about what you just wrote.