dancing_dead
Level 1
|
 |
« Reply #1580 on: May 08, 2014, 12:34:10 AM » |
|
hats off to you, Joar, for coming up with original and interesting solutions! lookin' very good 
|
|
|
|
|
Logged
|
|
|
|
|
JLJac
|
 |
« Reply #1581 on: May 08, 2014, 12:50:01 AM » |
|
Thanks  Ugh, can someone clue me in on the quirks of the CG compiler? Is there a list somewhere? It certainly does not execute the the code linearly in the way that I'd expect, that's for sure! Example: if (light){ setColor = half4(0, 1, 0, 1); }else{ setColor = half4(1, 0, 1, 1); } This code makes the lit areas green and the other areas purple, as expected. This though: if (light){ setColor = tex2D(_PalTex, float2(red/30.0, 1.0-((paletteColor + 3)/7.0))); }else{ setColor = tex2D(_PalTex, float2(red/30.0, 1.0-(paletteColor/7.0))); } doesn't work, it executes the "else" always, never the "if"  No other changes! This: if (light) paletteColor += 3;
setColor = tex2D(_PalTex, float2(red/30.0, 1.0-(paletteColor/7.0)));
works, and according to my logic that is the exact same thing as the one above it. Confused  I've been told that shaders work more in parallel an less linearly, and I guess this is that, but I just can't wrap my head around how it works. To me it seems to just be random. What's going on?
|
|
|
|
|
Logged
|
|
|
|
|
eigenbom
|
 |
« Reply #1582 on: May 08, 2014, 01:46:42 AM » |
|
Looking good dude, you're making great progress!
|
|
|
|
|
Logged
|
|
|
|
|
migrafael
|
 |
« Reply #1583 on: May 08, 2014, 01:50:34 AM » |
|
Need to track this. Amazing looking stuff.
|
|
|
|
|
Logged
|
|
|
|
|
Ben H
|
 |
« Reply #1584 on: May 08, 2014, 02:29:57 AM » |
|
if (light){ setColor = tex2D(_PalTex, float2(red/30.0, 1.0-((paletteColor + 3)/7.0))); }else{ setColor = tex2D(_PalTex, float2(red/30.0, 1.0-(paletteColor/7.0))); } I'm not sure but calling tex2D on the same tex, with different UV coords, in the same shader, fugged me up once.
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Vovosunt
|
 |
« Reply #1586 on: May 08, 2014, 05:07:32 AM » |
|
No, I'm actually not raymarching, as I don't do any step-by-step checking of different depths. Instead the procedure has only two steps:
1. Check the pixel and get its info, which is color info but also depth (already encoded by the level editor).
2. Use the depth to check for where in the grab texture to look for objects that shadow this pixel. The greater the depth, the more up/left we check.
Effect: If you are in front of a wall, there will be a shadow on the wall. The further back the wall is, the further down/right the shadow will appear. Oh, I misunderstood then. (But that could still be considered raymarching with one step  ) Your pseudo code is super helpful, by reading it I see a lot of things I can optimize in my shader! It's impressive that you manage to keep away from if-statements like that! My texture looks like this:  So that's the same basic idea, right? That is pretty much exactly what I tried to illustrate  if (light){ setColor = tex2D(_PalTex, float2(red/30.0, 1.0-((paletteColor + 3)/7.0))); }else{ setColor = tex2D(_PalTex, float2(red/30.0, 1.0-(paletteColor/7.0))); } That should work... weird Try mixing uvs instead (should be faster): //considering light a float that has been clamped to 0 or 1
float uvY = mix(paletteColor + 3, paletteColor, light); setColor = tex2D(_PalTex, float2(red/30, 1 - (uvY / 7)));
EDIT: just remembered that mix is a glsl function. I believe it's called lerp in CG. BTW guys, why doesn't tigsource have a rainworld emoticon? 
|
|
|
|
|
Logged
|
|
|
|
|
Gimym JIMBERT
|
 |
« Reply #1587 on: May 08, 2014, 08:42:09 AM » |
|
Yep don't do if, use things like lerp, max, min etc ... For exemple: (pseudocode) setdata = lerp (A,B, 0) is effectively picking A when 0 but pick B if 1. Also be sure to set up your texture as not wrapping and filter none (bi/tri linear off)
If don't save a branch in shader because parallelism, it execute both code, you basically overwrite the data that's why it does not work for the texture picker.
Do something like c1 = texpicked1 c2 = texpicked2 color = lerp (c1,c2,light)
or color = lerp (texpicked1,texpicked2,light) ?
|
|
|
|
« Last Edit: May 08, 2014, 08:49:25 AM by Gimym JIMBERT »
|
Logged
|
 ILLOGICAL, random guy on internet, do not trust (lelebĉcülo dum borobürükiss) ! GЮЯЦ TФ ДЯSTӨTZҚД! sonic the heidegger (Überall Geschwindigkeit)
|
|
|
|
Zaphos
|
 |
« Reply #1588 on: May 08, 2014, 08:57:07 AM » |
|
if (light){ setColor = tex2D(_PalTex, float2(red/30.0, 1.0-((paletteColor + 3)/7.0))); }else{ setColor = tex2D(_PalTex, float2(red/30.0, 1.0-(paletteColor/7.0))); } lerp/mix are good to know but for this you could also have just done: setColor = tex2D(_PalTex, float2(red/30.0, 1.0-((paletteColor + 3*light)/7.0))); //light is 0 or 1
|
|
|
|
|
Logged
|
|
|
|
|
JLJac
|
 |
« Reply #1589 on: May 08, 2014, 09:30:36 AM » |
|
Thanks guys! Yeap, those solutions are actually how I solved it! But the reason why I wanted to do it with proper if statements was that I didn't want to check for shadowing objects if I already knew the pixel was in shadow. I didn't want it to run that code unless necessary.
Speaking of which, how expensive is tex2D? I do it quite a lot, heh -
|
|
|
|
|
Logged
|
|
|
|
|
Gimym JIMBERT
|
 |
« Reply #1590 on: May 08, 2014, 09:31:58 AM » |
|
If don't work like that in shader
|
|
|
|
|
Logged
|
 ILLOGICAL, random guy on internet, do not trust (lelebĉcülo dum borobürükiss) ! GЮЯЦ TФ ДЯSTӨTZҚД! sonic the heidegger (Überall Geschwindigkeit)
|
|
|
|
|
|
Zaphos
|
 |
« Reply #1592 on: May 08, 2014, 10:37:07 AM » |
|
Even on a CPU, "3*light" would be cheaper than an if statement. Conditional statements can have an extra cost beyond normal instructions, depending on how predictable they are. CPUs basically have a pipeline where they pre-load instructions and data, and when they see if statements they have to guess which way the if statement will go, and pre-load based on the guess. If they guess wrong, they throw out that pre-loading work and go back to do the other branch, and this is relatively expensive. See: http://en.wikipedia.org/wiki/Branch_predictor (And GPUs are worse at branching than CPUs -- really old ones can't even branch, they just do all the paths and suppress the results of the wrong branches... See Chromanoid's link!)
|
|
|
|
|
Logged
|
|
|
|
|
RealityShifter
|
 |
« Reply #1593 on: May 08, 2014, 10:41:05 AM » |
|
Even on a CPU, "3*light" would be cheaper than an if statement. Conditional statements can have an extra cost beyond normal instructions, depending on how predictable they are. CPUs basically have a pipeline where they pre-load instructions and data, and when they see if statements they have to guess which way the if statement will go, and pre-load based on the guess. If they guess wrong, they throw out that pre-loading work and go back to do the other branch, and this is relatively expensive. See: http://en.wikipedia.org/wiki/Branch_predictor (And GPUs are worse at branching than CPUs -- really old ones can't even branch, they just do all the paths and suppress the results of the wrong branches... See Chromanoid's link!) This is good to know. O.O
|
|
|
|
|
Logged
|
Creativegametheory.com @theorygeorgiou
|
|
|
|
JLJac
|
 |
« Reply #1594 on: May 08, 2014, 11:09:09 AM » |
|
Super relevant info, guys! What would I even do without you!?
|
|
|
|
|
Logged
|
|
|
|
|
Gimym JIMBERT
|
 |
« Reply #1595 on: May 08, 2014, 11:09:41 AM » |
|
rain world?
|
|
|
|
|
Logged
|
 ILLOGICAL, random guy on internet, do not trust (lelebĉcülo dum borobürükiss) ! GЮЯЦ TФ ДЯSTӨTZҚД! sonic the heidegger (Überall Geschwindigkeit)
|
|
|
|
JLJac
|
 |
« Reply #1596 on: May 08, 2014, 11:31:39 AM » |
|
 probably not, no! I'd still be beating my head against Macromedia Director!
|
|
|
|
|
Logged
|
|
|
|
|
Slader16
|
 |
« Reply #1597 on: May 08, 2014, 01:33:00 PM » |
|
Just wanted to let you know, in Unity lerp is Mathf.Lerp 
|
|
|
|
|
Logged
|
|
|
|
|
Gimym JIMBERT
|
 |
« Reply #1598 on: May 08, 2014, 03:00:38 PM » |
|
Just wanted to let you know, in Unity lerp is Mathf.Lerp  not in shader?
|
|
|
|
|
Logged
|
 ILLOGICAL, random guy on internet, do not trust (lelebĉcülo dum borobürükiss) ! GЮЯЦ TФ ДЯSTӨTZҚД! sonic the heidegger (Überall Geschwindigkeit)
|
|
|
|
Slader16
|
 |
« Reply #1599 on: May 08, 2014, 04:30:10 PM » |
|
Just wanted to let you know, in Unity lerp is Mathf.Lerp  not in shader? I don't know anything about shaders or if Joar is using Unity's built in methods, but if I was going to use a lerp it would be Mathf.Lerp. An example is moving an objects position: Mathf.Lerp(currentPosition, newPosition, Time.deltatime);. I could be thinking of something different though since what Joar uses relates to shaders. 
|
|
|
|
|
Logged
|
|
|
|
|