{"action":"created","issue":{"url":"https://api.github.com/repos/pmneila/jsexp/issues/6","labels_url":"https://api.github.com/repos/pmneila/jsexp/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/pmneila/jsexp/issues/6/comments","events_url":"https://api.github.com/repos/pmneila/jsexp/issues/6/events","html_url":"https://github.com/pmneila/jsexp/issues/6","id":118408179,"number":6,"title":"React to underlying background?","user":{"login":"fallenartist","id":661820,"avatar_url":"https://avatars.githubusercontent.com/u/661820?v=3","gravatar_id":"","url":"https://api.github.com/users/fallenartist","html_url":"https://github.com/fallenartist","followers_url":"https://api.github.com/users/fallenartist/followers","following_url":"https://api.github.com/users/fallenartist/following{/other_user}","gists_url":"https://api.github.com/users/fallenartist/gists{/gist_id}","starred_url":"https://api.github.com/users/fallenartist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fallenartist/subscriptions","organizations_url":"https://api.github.com/users/fallenartist/orgs","repos_url":"https://api.github.com/users/fallenartist/repos","events_url":"https://api.github.com/users/fallenartist/events{/privacy}","received_events_url":"https://api.github.com/users/fallenartist/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-11-23T15:42:55Z","updated_at":"2015-11-25T03:03:50Z","closed_at":null,"body":"Hi. Great Gray-Scott solver! I was wondering if it would be possible to modify the algorithm so it reacts to underlying colour or grayscale image like here:\r\n\r\n![Reactor](http://jasondorie.com/pictures/Reactor.jpg) \r\n\r\nI did't have much success [so far](http://codepen.io/znak/pen/JYVGJW?editors=001). Would you have any ideas how to achieve this? Cheers!"},"comment":{"url":"https://api.github.com/repos/pmneila/jsexp/issues/comments/159474104","html_url":"https://github.com/pmneila/jsexp/issues/6#issuecomment-159474104","issue_url":"https://api.github.com/repos/pmneila/jsexp/issues/6","id":159474104,"user":{"login":"pmneila","id":1254337,"avatar_url":"https://avatars.githubusercontent.com/u/1254337?v=3","gravatar_id":"","url":"https://api.github.com/users/pmneila","html_url":"https://github.com/pmneila","followers_url":"https://api.github.com/users/pmneila/followers","following_url":"https://api.github.com/users/pmneila/following{/other_user}","gists_url":"https://api.github.com/users/pmneila/gists{/gist_id}","starred_url":"https://api.github.com/users/pmneila/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pmneila/subscriptions","organizations_url":"https://api.github.com/users/pmneila/orgs","repos_url":"https://api.github.com/users/pmneila/repos","events_url":"https://api.github.com/users/pmneila/events{/privacy}","received_events_url":"https://api.github.com/users/pmneila/received_events","type":"User","site_admin":false},"created_at":"2015-11-25T03:03:50Z","updated_at":"2015-11-25T03:03:50Z","body":"Hi,\r\n\r\n> Am I right that the formula checks the red channel of the texture?\r\n\r\nYes, you are right. But [the image I'm loading in that specific example](https://github.com/pmneila/jsexp/blob/master/gsimage/lena512.jpg) is grayscale, so the red channel is already the luminosity value.\r\n\r\n> I guess it should be luminosity (like sqrt(0.299 * R^2 + 0.587 * G^2 + 0.114 * B^2) - ref)?\r\n\r\nYes. That's one option. You can use a simpler and faster approach without the squares (see in the reference you linked).\r\n\r\n> The most important issue for me, however, is to stabilise the shader in darker areas with lower feed value, like in the Reactor software (image above).\r\n\r\nI'm not sure what you mean with \"stabilise the shader\". Do you mean \"not to grow into those areas\" as in the white region in the upper right? You don't need to change the kill rate for that, just set the feed rate low enough. For example, for a fixed kill rate of 0.062, the \"valid\" feed rates are in the range [0.015, 0.06] or so. Just set the feed rate mapping the grayscale values from [0, 1] to that range. For example, with\r\n```\r\nfloat feed = (1.0 - texture2D(feed_texture, vUv).r) * 0.045 + 0.015;\r\nfloat kill = 0.062;\r\n```\r\n\r\n>  I guess the kill value would also need to be dependent on the texture? But what should be the formula?\r\n\r\nYou can tune the kill value depending on the texture, of course, but I'm not sure if that's necessary for your purposes. \r\n\r\n> Also, there are some fixed values in the code (1, 2, 3, 4). What are they and are they somehow linked?\r\n\r\n1, 2 and 3 are related to the mouse and initialization. Mixing both things in the same variable is dirty, but that way I don't need extra variables only for initialization.\r\n\r\n3 sets the initial coordinates of the mouse to (-10, -10), just an arbitrary negative value.\r\n\r\n1 checks if the coordinates are less than -5 (which is only true in the first iteration and when the \"clear\" button is pressed) to initialize the density texture.\r\n\r\n2 is for setting to 0.9, an arbitrary high value, the densities of the pixels that are close to the mouse cursor (for \"painting\" with the mouse). It could be 1, but that might lead to numerical instabilities. \r\n\r\n4 avoids stability problems when solving the PDE. If your computer is too slow, it might happen that the time step dt is too large, which might make the numerical solution become unstable. Therefore, if dt is too large, it is clipped to 0.8, which is a reasonable value obtained empirically. :)\r\n"}}