Thursday, 30 May 2013

Unity world's coolest tutorial about water, girls and sky with FREE assets



DOWNLOAD ASSETS LINK:
https://dl.dropboxusercontent.com/u/106482752/Water-Underwater/Water-Underwater.unitypackage

MIRROR ASSETS LINK:
https://drive.google.com/file/d/0BxgYUKP-c4dJUTZDYU5VSV8wMk0/edit?usp=sharing

WEB PLAYER LINK:
https://dl.dropboxusercontent.com/u/106482752/Water-Underwater/Water.html



Take some pizza and cola and let's start.

Water, water, water everyone is crazy about it. Lets remember Bioshock. Jesus Christ whole team just for one water...Crysis...same shit. What's about Unity ? Even now with super pro custom advanced shader eat performance of whole game. Okey we have created awesome water, but if player want to go just deeper, deeper, deeper baby. Here is nothing except culling. Culling make feel people so lonely. But as always I have an idea and of course a realization.

Let's split our task into two:
1. Water
2. Underwater
Sounds simple at now.

        Water

Split into smaller parts:
1. Reflections
2. Refraction
3. Waves
4. Smooth bitch beach blending.
5. Mix everything

1. Reflection. Everything is really simple. Render environment opposite to water plane and store it in a texture.  I have used some old script that can do it.

2. Refraction. Render everything without plane. Store in a texture. For deferred render its really easy. Just got render without water plane.

3. Waves. Here we can choose two opportunities: mathematically calculate waves like combinations of sin functions in different directions and phases. Lots of opportunities like no tiles, custom waves that depends on wind speed or anything else. But we don't wanna fuck our brain up. Option 2: use texture of waves. Maybe normal map for proper specular calculation and sweet lighting. Hmmmm....guess second. Guys from Crysis definitely have choosed first one. Nice texture of a wave you can find on a cgtextures.com.

4. Smooth shore blending. Algorithm is quite easy. Get zbuffer in shader. Use that value for alpha blending. Closer objects like shore will receive less value for alpha and we will see smooth transition from water to shore.

5. If you ever study physics or stuff like that you may know that water have coefficient of self reflection. Sounds boring. But it's easy to understand if you look at water standing in it turn your head down you will see the bottom. If you see under some angle you will not see the bottom but will see the sky. So we need to calculate that that angle and make smooth transition between reflection and refraction. We can do like multiplication of of normal of some point in water and one length vector of plane where it's water situated. Then find angle from scalar multiplication and plane where it's plane is situated. This value is used for blending. Use some color coefficients for designers and little girls.

That's all as for top of the water.

     Underwater

1. Underwater reflections
2. Blue fog
3. Bubbles
4. Fish
5. Caustic cool effects
6. Camera color tint.

1. Underwater reflection. Unity have built in shader LOD system for shaders. So in one shader we can store both water and underwater. Use LOD fallback tag to provide that functionality. Write just plane reflection with wave without hardcore transitions and stuff like that

2. Blue fog. Simple as hell. Decrease fog distance and turn it color into some nice deep blue.

3. Bubbles. Just a simple particle emitter  Shrunken if you want or legacy.  Just tweak nice and leave as is. You can use my texture I have made it from series of bubbles.


4. Fish. I have modeled it by the texture. And animate in 3ds max. Two bones for swimming. But one fish that moving in a tank it's fucking boring. 5 better. 42 even better. But real pro will use cohesion separation algorithm for populations movement. Fuck yeah....use steer library for that shit. Just for extremely cool fishes.
5. Caustics is probably the most butt fucking moment of water creation. I have created it via projectors with caustic animation texture putted on it. I have used special program that can produce caustic animation like series of sprites and after that special scrip that can animate or simply change projector texture in update cycle. Out of topic: guess much faster is to store in one texture and use UV animation like in animated particles.

6. And underwater everything is looking more blue then above it. So we need to post process resulting screen for achieving water effect. That script is already available in effects. So our custom script will put it on camera.

That's it. Put some  rocks and water vegetation as you want.

      PUT ALL STUFF TOGETHER

Here we need to write custom script that handle player entering water or underwater mode. Of course that script should know about material of water. Player position, and something else that we know about much later like bubbles particles, underwater fog color.

Okay if player position by Y-axe is less then water position by this axe turn on underwater mode: fog density and color, shader LOD, turn on bubbles, you can leave fish moving in tank,  caustic is also switch according. When bigger just go back turn everything off. Also don't forget to turn camera rendering reflection direction into opposite one.

Some HACKs that was used:
1. you can't just turn off bubble particles when you leave water, cuz they have lifetime. So next time you entering water bubbles start emitting like they have waited you. Of course you can pre-warm. But this method have some strange behavior  like you should call them in for statement several times( you can find discussion about it on Unity answers). And by the way turn lot of objects on/off causing lags that we don't need. So use particle material and set it alpha to zero. Not so fast, but if you have better one you are welcome to write in comments.
2. Caustic. I have created couple of projectors and use script that takes player position and move caustic according to player movements. So it's small hack, small Hollywood trick.

Future:

1. Water came down effect when you go from underwater.
2.  Waves when come in water and stuff like small rain drops.
3. More accurate refraction and reflection model for water
4. Godrays



Smells like you have done. See you.

Thanks!Have joy and fun!
konstantin dvornik


Tuesday, 28 May 2013

Windows 8 tablet prototype design

Main idea of that table:  you dont care about it.

- its FREE. You take it and pay only for software and services.
- non-breakeable
- sun light and magnite charging
- water resist
- rubber body
- have no holes. Just wireless and magnite based connections.
- have no buttons. Voice commands and touch screen


Sunday, 5 May 2013

How Universe works

We all know that Statistic is common tool in forecasting in real world: marketing, commerce, sales. And most events in real world describes as Gaussian:
Let's take human life time. Avarage life time of a man is 70 years. So the most succesfull period comes to 30-40 years old what ideally describes Gaussian law. You may say it's quite long period and this information is useless...Not so fast. Lets take a day. If you wake up at 8am and go to sleep at 0am then  the most productive time is 12pm-4pm. But its quite boring info just to proof that simple theory.  Much  more interesting is forecasting something that people call LUCK.

LUCK is described as part of my theory. If you fail, fail, fail, fail, fail, fail...then just to keep Gaussian law you definatly should win and result of your life is 50/50 of fails/wins. Yes, shift of this curve is different: you can do your everyday office work or rule whole nation, but law of your win/fail will always be Gaussian. Of course win/fail of our life depend on our choises. We can work or not on something, we can choose between something, that shift Gaussian curve in needed directions.

Wednesday, 1 May 2013

IDE coding idea

Constants...Everyone know that using some static Constant class is common practice in any product. So we can integrate such functionality directly in IDE. For example:

1. enter for( int i=0;i<42;i++){....}
2. when you put cursor on number 42 IDE automaticaly propose you to setup this constant in Constant file. You enter name for constant and hit enter. Gotcha
3. for( int i=0;i<cSenseOfLife;i++){...}

But thats not all

IDE have special mode where all constants from Constant file are showing directly in code. So you can edit them here without a need to open Constant file.