Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075758 Posts in 44140 Topics- by 36112 Members - Latest Member: Nbohlsen

December 29, 2014, 12:34:16 AM
TIGSource ForumsFeedbackDevLogsProject Rain World
Pages: 1 ... 78 79 [80] 81 82 ... 131
Print
Author Topic: Project Rain World  (Read 248234 times)
dancing_dead
Level 1
*


View Profile
« 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 Smiley
Logged
JLJac
Level 10
*****



View Profile
« Reply #1581 on: May 08, 2014, 12:50:01 AM »

Thanks  Smiley

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:

Code:

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:

Code:

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" Crazy No other changes!

This:

Code:

 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  Crazy

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
Level 10
*****



View Profile WWW
« Reply #1582 on: May 08, 2014, 01:46:42 AM »

Looking good dude, you're making great progress!
Logged

migrafael
Level 2
**


Making games, two at a time


View Profile WWW
« Reply #1583 on: May 08, 2014, 01:50:34 AM »

Need to track this. Amazing looking stuff.
Logged

Ben H
Level 0
**


View Profile WWW
« Reply #1584 on: May 08, 2014, 02:29:57 AM »

Code:

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

Nilanjan
Level 0
***



View Profile Email
« Reply #1585 on: May 08, 2014, 04:45:58 AM »

@Joar The way you come up with original solutions is f*****ng brilliant!!! You Sir are not a mere mortal  Shocked Tears of Joy
Logged

Souls of Titans
Vovosunt
Level 0
**


Vovo the Lolcat


View Profile
« 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 Tongue)

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  Smiley

Code:

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):

Code:
//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? Wink
Logged

Gimym JIMBERT
Level 10
*****


NOTGAMER ludophile


View Profile Email
« 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
Level 5
*****



View Profile WWW Email
« Reply #1588 on: May 08, 2014, 08:57:07 AM »

Code:

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:
Code:
setColor = tex2D(_PalTex, float2(red/30.0, 1.0-((paletteColor + 3*light)/7.0))); //light is 0 or 1
Logged

JLJac
Level 10
*****



View Profile
« 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
Level 10
*****


NOTGAMER ludophile


View Profile Email
« 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)
Chromanoid
Level 10
*****



View Profile
« Reply #1591 on: May 08, 2014, 10:30:33 AM »

http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter34.html might be interesting for you. It's probably outdated, but it gives you a basic understanding of flow control in GPUs.
Logged
Zaphos
Level 5
*****



View Profile WWW Email
« 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
Level 0
***



View Profile WWW Email
« 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
Level 10
*****



View Profile
« Reply #1594 on: May 08, 2014, 11:09:09 AM »

Super relevant info, guys! What would I even do without you!?
Logged
Gimym JIMBERT
Level 10
*****


NOTGAMER ludophile


View Profile Email
« 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
Level 10
*****



View Profile
« Reply #1596 on: May 08, 2014, 11:31:39 AM »

 Cheesy probably not, no! I'd still be beating my head against Macromedia Director!
Logged
Slader16
Level 6
*



View Profile Email
« Reply #1597 on: May 08, 2014, 01:33:00 PM »

Just wanted to let you know, in Unity lerp is Mathf.Lerp  Coffee
Logged

Gimym JIMBERT
Level 10
*****


NOTGAMER ludophile


View Profile Email
« Reply #1598 on: May 08, 2014, 03:00:38 PM »

Just wanted to let you know, in Unity lerp is Mathf.Lerp  Coffee
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
Level 6
*



View Profile Email
« Reply #1599 on: May 08, 2014, 04:30:10 PM »

Just wanted to let you know, in Unity lerp is Mathf.Lerp  Coffee
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.  Grin
Logged

Pages: 1 ... 78 79 [80] 81 82 ... 131
Print
Jump to:  

Theme orange-lt created by panic