Jump to content

What Programming Language?


49 replies to this topic

#21 Gromokryak

    Rookie

  • The Bold
  • 2 posts

Posted 03 April 2014 - 12:03 AM

View PostHelmstif, on 02 April 2014 - 06:56 PM, said:

Yup. In fact I would be glad if one day I could make a 16-bit colored 2D game....


My story:

After I completed java book (Horstmann, Core Java), I wrote 2D Tower Defence game just for practice, without any frameworks. It's not too hard, main requirements - be excited to create something (but all novices are!) and sometimes strong will to carry on.
Most complex tasks for me in process (my first app!) was not the language knowledge or something, but graphics basics (double buffer, rendering steps, object rendering queue sorting), alghoritms (pathfinding, sorting, detections) and math(formulas to creature's trajectories, shooting trajectories, creatures orientation and so on).

You can check this out - https://github.com/m...2k/TowerDefence
Code as it was few years ago, never refactored (I can do it now, but don't want to)

So... just start and here you go.

Edited by Gromokryak, 03 April 2014 - 12:10 AM.


#22 S3dition

    Member

  • PipPipPipPipPipPipPipPip
  • Elite Founder
  • Elite Founder
  • 1,633 posts
  • LocationLost in the Warp

Posted 03 April 2014 - 05:59 AM

View PostHelmstif, on 02 April 2014 - 06:56 PM, said:

Some interesting arguments. Thanks everyone, I'll do a bit more research, but I'm kinda sorta leaning toward:


Also,

That's the point. Lottery = minimal investment. Even if I don't end up making any money, I still get to learn some programming skill. And at this day and age, programming sounds like the kind of skill one would be glad to have.


Yup. In fact I would be glad if one day I could make a 16-bit colored 2D game....


If you think it will be minimal investment... you already failed. Super Meat Boy had 2 developers and took almost a year to develop. That's a 2d sprite game with an experienced artist and coder. I've been working on a mobile game for android on and off for about a year now (getting close... SOO Clooose).

You might be able to get into it for minimal financial investment. But game development will consume your soul and the forum trolls will eat your remains.

True story.

Even a basic game is going to require a lot of time when you first start out. I actually got started back in NWN using their C based scripting language. It's how I learned data types, loops ,conditionals, etc. But they didn't support object oriented programming (well, they kind of did through structs) so I couldn't learn about classes, instantiating, inheritance, etc until later on.

I do recommend you try Unity, as it's a very visual way of learning. They have some tutorials on scripting and other development activities: https://unity3d.com/...torials/modules

As well as free live training and class archives: https://unity3d.com/...raining/archive

Live class list: https://unity3d.com/...n/live-training - the class on Monday is actually very important for mobile games. You may want to sit in just to get your feet wet.

It's not currently the most fabulous looking engine (physically based shaders coming this summer!), but it's forgiving and it's really easy to get help with it. Again, a lot of it is very visual, which helps.

The thing is - whatever you choose, make you sure you stick with it until you're proficient before branching off. All programming follows the same core concepts of OOP coding. Once you're comfortable with that, learning other languages will be much easier.

Edited by S3dition, 03 April 2014 - 06:01 AM.


#23 S3dition

    Member

  • PipPipPipPipPipPipPipPip
  • Elite Founder
  • Elite Founder
  • 1,633 posts
  • LocationLost in the Warp

Posted 03 April 2014 - 06:30 AM

View PostMarack Drock, on 03 April 2014 - 06:24 AM, said:

Who thinks it would be cool if the community joined together to create a video game franchise (I have always wanted to do that and I am a good artist, and story developer -that is if you like really dark and disturbing stories-)?


It takes more than having an ability. It has to mesh with the needs of the project. You have to be willing to work a lot of hours every week in addition to your regular job, you have to get along with the team members, everyone has to agree on an engine to use, there has to be an agreement on the project direction, there needs to be enough people to fill complex roles like animation.

It's hard enough trying to get people to make a game for money. Doing it for free is even harder.

#24 Hex Pallett

    Member

  • PipPipPipPipPipPipPipPipPip
  • Urban Commando
  • Urban Commando
  • 2,009 posts
  • Twitter: Link
  • LocationHomeless, in the streets of Solaris 7

Posted 03 April 2014 - 07:26 AM

View PostS3dition, on 03 April 2014 - 05:59 AM, said:


If you think it will be minimal investment... you already failed. Super Meat Boy had 2 developers and took almost a year to develop. That's a 2d sprite game with an experienced artist and coder. I've been working on a mobile game for android on and off for about a year now (getting close... SOO Clooose).

You might be able to get into it for minimal financial investment. But game development will consume your soul and the forum trolls will eat your remains.

True story.

Even a basic game is going to require a lot of time when you first start out. I actually got started back in NWN using their C based scripting language. It's how I learned data types, loops ,conditionals, etc. But they didn't support object oriented programming (well, they kind of did through structs) so I couldn't learn about classes, instantiating, inheritance, etc until later on.

I do recommend you try Unity, as it's a very visual way of learning. They have some tutorials on scripting and other development activities: https://unity3d.com/...torials/modules

As well as free live training and class archives: https://unity3d.com/...raining/archive

Live class list: https://unity3d.com/...n/live-training - the class on Monday is actually very important for mobile games. You may want to sit in just to get your feet wet.

It's not currently the most fabulous looking engine (physically based shaders coming this summer!), but it's forgiving and it's really easy to get help with it. Again, a lot of it is very visual, which helps.

The thing is - whatever you choose, make you sure you stick with it until you're proficient before branching off. All programming follows the same core concepts of OOP coding. Once you're comfortable with that, learning other languages will be much easier.


Don't worry. I have no plan on going Phil Fish, forging my own soul into a single game. Also Super Meatboy is not a simple game - in fact any game that I couldn't tell the movement mechanisms immediately is not a simple game. What I'm aiming for is something along this line...

...but even simpler.

In that case I'm not sure if Unity would help me out, cuz...isn't Unity a 3D engine? I for one don't wanna go beyond 2D. That's what I meant by "minimal investment", like an hour and a half every night.

But regardless, thanks for the advice.

#25 S3dition

    Member

  • PipPipPipPipPipPipPipPip
  • Elite Founder
  • Elite Founder
  • 1,633 posts
  • LocationLost in the Warp

Posted 03 April 2014 - 08:39 AM

View PostHelmstif, on 03 April 2014 - 07:26 AM, said:


In that case I'm not sure if Unity would help me out, cuz...isn't Unity a 3D engine? I for one don't wanna go beyond 2D. That's what I meant by "minimal investment", like an hour and a half every night.

But regardless, thanks for the advice.


Did you check any of those links I posted for you?

Edited by S3dition, 03 April 2014 - 08:39 AM.


#26 Hex Pallett

    Member

  • PipPipPipPipPipPipPipPipPip
  • Urban Commando
  • Urban Commando
  • 2,009 posts
  • Twitter: Link
  • LocationHomeless, in the streets of Solaris 7

Posted 03 April 2014 - 08:58 AM

View PostS3dition, on 03 April 2014 - 08:39 AM, said:

Did you check any of those links I posted for you?

Admittedly I didn't really. Was in class, professor giving back midterm.

Now since I got a bit time...hmmm, interesting....

#27 Alaskan Nobody

    Member

  • PipPipPipPipPipPipPipPipPipPipPip
  • The Determined
  • The Determined
  • 10,358 posts
  • LocationAlaska!

Posted 03 April 2014 - 09:35 AM

View PostMarack Drock, on 02 April 2014 - 11:30 AM, said:

Edit -note- Java is practically the same as C++ (very similar languages) so if you can program C you can program Java (or vice versa).

View PostS3dition, on 02 April 2014 - 12:58 PM, said:

Failing that, download Eclipse and start learning java. That route is free too. Expect to be miserable though. It takes a lot of failure before everything clicks and works.

Codacademy has lessons on Java - and I have started on those. :huh:

Note though for S3dition?
If MWT is any indication for Unity - I am going to have problems using it. :lol:

#28 Adridos

    Member

  • PipPipPipPipPipPipPipPipPipPipPip
  • Bridesmaid
  • 10,635 posts
  • LocationHiding in a cake, left in green city called New A... something.

Posted 03 April 2014 - 09:36 AM

View PostHelmstif, on 03 April 2014 - 07:26 AM, said:

In that case I'm not sure if Unity would help me out, cuz...isn't Unity a 3D engine? I for one don't wanna go beyond 2D. That's what I meant by "minimal investment", like an hour and a half every night.


Most 2D stuff is simply 3D stuff with singular Z axis values, nowadays, anyway...

Ok, maybe not, but you really need not worry when doing a 2D game in a 3D engine, in some cases it even helps with the implementation of some things and in the general terms is in the same league as far as time or diffculty goes.

Take unity, put your camera facing at a 90° angle to the XY axis, put all your sprites on that plane and whenever you need to use the third axis, simply write "z" behind it, while defining z as 0 ("#define z 0" in C++). It may have had an impact on performance back in the 90s, but today's hardware will be dragged down by anything but that part of your game.

Also, as far as language goes, it's either Java or C# for you... depends mostly in what you'd like to use (Unity = C#).
Both are pretty much entry-level languages that may not be the best for learning proper coding (they will probably teach you some bad habits especially when it comes to memory management, but that would only concern you if you were planning to do anything so advanced it actually requires proper memory management in the future... which you don't), but they are the main tool when it comes to whipping up cheap game clones with F2P model... sorry, I meant: "smartphone games."

View PostMarack Drock, on 02 April 2014 - 11:30 AM, said:

Edit -note- Java is practically the same as C++ (very similar languages) so if you can program C you can program Java (or vice versa).


Java's equivalent is C#, not C++, nor C. :lol:

Although the general "If you know one, you know them all," applies to most gen 4 languages.
It's like LEGO... the basics are absolutely the same, but there are different sets with slightly different parts that may look/function a little bit differently.

Things like Scratch are the Duplo blocks, C is the Creator, Java is the City, Fortran/Basic is Technic and Assembly is the Meccano.

Edited by Adridos, 03 April 2014 - 09:47 AM.


#29 Hawkeye 72

    Member

  • PipPipPipPipPipPipPipPip
  • 1,890 posts
  • Google+: Link
  • Facebook: Link
  • LocationArcadia

Posted 03 April 2014 - 10:26 AM

When I started my engineering degree, I had zero programming experience.

First courses got me started with MATLAB (originally written in C) and some basic level C stuff. However I wasn't developing games with these. More just technical/math based work.

Since then I started moving into Java to get the basics of OOP down and so I can work with more ease in the Android operating system. I'll probably move into C++ later this year. I personally was never a big fan of Python, as I actually disliked how simple it was, so if you don't have a big math/computer background it is a good place to start. If you want to get a little more depth, I recommend either C or Java. With Java you don't have to worry about memory AS much as C or C++, so it can be a little friendlier to the beginner.

If all you want to do is build a basic 2D game, I suggest just pick a language and learn as much as you can about it. The beauty of programming is all you need is a computer and the internet, and you can learn everything you want. There are hundreds of PDF files of textbooks online to learn from, and websites and tutorials galore. The key to programming is just to code as much as you can. For every example execution you read, you should type it out yourself. As you learn, you slowly figure out how putting together a basic 2D game is rather simple.

As for myself, with my engineering background I am a glutton for punishment, so I like to do EVERYTHING myself in programming. Havok physics engine? Screw that I make my own physics haha.

#30 Cyberiad

    Member

  • PipPipPipPipPipPip
  • 342 posts

Posted 03 April 2014 - 02:09 PM

View PostHelmstif, on 02 April 2014 - 11:44 PM, said:


So does it mean that, with some refined algorithms in C, I could generate stuff like Minecraft/Terraria worlds? :lol:


Yeah, you can use any language to generate procedural worlds. Minecraft uses what is called simplex/Perlin noise. Ken Perlin invented it in 1985 for the movie Tron and was awarded an Academy Award for it. The basic idea is that you generate random numbers on a grid and use these values as derivatives to generate a smooth random field. It's actually a lot easier than it sounds.

Here's a highly simplified shader implementation:
#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.14159265359
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
float f0(vec3 p){
float a=sin(dot(p,vec3(123.456,234.567,345.678)))*456.789;
return fract(a);
}
float f1(vec3 p){
vec3 p0=vec3(floor(p.x),floor(p.y),floor(p.z));
vec3 p1=vec3(floor(p.x)+1.0,floor(p.y),floor(p.z));
vec3 p2=vec3(floor(p.x),floor(p.y)+1.0,floor(p.z));
vec3 p3=vec3(floor(p.x)+1.0,floor(p.y)+1.0,floor(p.z));
vec3 p4=vec3(floor(p.x),floor(p.y),floor(p.z)+1.0);
vec3 p5=vec3(floor(p.x)+1.0,floor(p.y),floor(p.z)+1.0);
vec3 p6=vec3(floor(p.x),floor(p.y)+1.0,floor(p.z)+1.0);
vec3 p7=vec3(floor(p.x)+1.0,floor(p.y)+1.0,floor(p.z)+1.0);
float r0=f0(p0);
float r1=f0(p1);
float r2=f0(p2);
float r3=f0(p3);
float r4=f0(p4);
float r5=f0(p5);
float r6=f0(p6);
float r7=f0(p7);
float s0=fract(p.x);
float s1=fract(p.y);
float s2=fract(p.z);
s0=(sin(s0*PI-PI/2.0)+1.0)/2.0;
s1=(sin(s1*PI-PI/2.0)+1.0)/2.0;
s2=(sin(s2*PI-PI/2.0)+1.0)/2.0;
float a0=r0*(1.0-s0)+r1*s0;
float a1=r2*(1.0-s0)+r3*s0;
float a2=a0*(1.0-s1)+a1*s1;
float a3=r4*(1.0-s0)+r5*s0;
float a4=r6*(1.0-s0)+r7*s0;
float a5=a3*(1.0-s1)+a4*s1;
float a6=a2*(1.0-s2)+a5*s2;
return a6;
}
#define ITER 1
#define POWER 3
float f2(vec3 p){
float a=0.0;
for(int i=0;i<ITER;i++){
  a+=f1(vec3(p.xy*pow(2.0,float(i+POWER)),p.z+float(i)*0.5));
}
a/=float(ITER);
return a;
}
void main(void){
vec2 p=(gl_FragCoord.xy/resolution.xy);
vec2 b=vec2(1.0)/resolution.xy*5.0;
gl_FragColor=vec4(f2(vec3(p*2.0+vec2(-b.x,0.0),time*0.5)));
}


Posted Image

This is actually 3 dimensional except one of the dimensions is mapped to time. You could use this to generate a Minecraft-like 3d terrain.

Here an example of it in use from the shader version of the famous 4-kilobyte real-time program Elevated:
Posted Image
It's 271 lines of code:
// Created by inigo quilez - iq/2013
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
//stereo thanks to Croqueteer
//#define STEREO
float hash( float n )
{
	return fract(sin(n)*43758.5453123);
}
vec3 noised( in vec2 x )
{
	vec2 p = floor(x);
	vec2 f = fract(x);
	vec2 u = f*f*(3.0-2.0*f);
	float n = p.x + p.y*57.0;
	float a = hash(n+  0.0);
	float b = hash(n+  1.0);
	float c = hash(n+ 57.0);
	float d = hash(n+ 58.0);
return vec3(a+(b-a)*u.x+(c-a)*u.y+(a-b-c+d)*u.x*u.y,
	30.0*f*f*(f*(f-2.0)+1.0)*(vec2(b-a,c-a)+(a-b-c+d)*u.yx));
}
float noise( in vec2 x )
{
	vec2 p = floor(x);
	vec2 f = fract(x);
	f = f*f*(3.0-2.0*f);
	float n = p.x + p.y*57.0;
	float res = mix(mix( hash(n+  0.0), hash(n+  1.0),f.x),
					mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);
	return res;
}
const mat2 m2 = mat2(1.6,-1.2,1.2,1.6);
 
float fbm( vec2 p )
{
	float f = 0.0;
	f += 0.5000*noise( p ); p = m2*p*2.02;
	f += 0.2500*noise( p ); p = m2*p*2.03;
	f += 0.1250*noise( p ); p = m2*p*2.01;
	f += 0.0625*noise( p );
	return f/0.9375;
}
float terrain( in vec2 x )
{
vec2  p = x*0.003;
	float a = 0.0;
	float b = 1.0;
vec2  d = vec2(0.0);
	for( int i=0; i<6; i++ )
	{
		vec3 n = noised(p);
		d += n.yz;
		a += b*n.x/(1.0+dot(d,d));
  b *= 0.5;
		p = m2*p;
	}
return 140.0*a;
}
float terrain2( in vec2 x )
{
vec2  p = x*0.003;
	float a = 0.0;
	float b = 1.0;
vec2  d = vec2(0.0);
	for( int i=0; i<14; i++ )
	{
		vec3 n = noised(p);
		d += n.yz;
		a += b*n.x/(1.0+dot(d,d));
  b *= 0.5;
		p=m2*p;
	}
return 140.0*a;
}
float terrain3( in vec2 x )
{
vec2  p = x*0.003;
	float a = 0.0;
	float b = 1.0;
vec2  d = vec2(0.0);
	for( int i=0; i<4; i++ )
	{
		vec3 n = noised(p);
		d += n.yz;
		a += b*n.x/(1.0+dot(d,d));
  b *= 0.5;
		p = m2*p;
	}
return 140.0*a;
}
float map( in vec3 p )
{
float h = terrain(p.xz);
	return p.y - h;
}
float map2( in vec3 p )
{
float h = terrain2(p.xz);
	return p.y - h;
}
float interesct( in vec3 ro, in vec3 rd )
{
	float h = 1.0;
	float t = 1.0;
for( int i=0; i<128; i++ )
{
  if( h<0.1 || t>2000.0 ) break;
  t += 0.5*h*(1.0+0.0002*t);
  h = map( ro + t*rd );
}
if( h>10.0 ) t = -1.0;
return t;
}
float sinteresct(in vec3 rO, in vec3 rD )
{
	float res = 1.0;
	float t = 0.0;
for( int j=0; j<50; j++ )
{
		//if( t>1000.0 ) break;
	 vec3 p = rO + t*rD;
		float h = map( p );
  res = min( res, 16.0*h/t );
  t += h;
}
return clamp( res, 0.0, 1.0 );
}
vec3 calcNormal( in vec3 pos, float t )
{
float e = 0.001;
e = 0.001*t;
	vec3  eps = vec3(e,0.0,0.0);
	vec3 nor;
	nor.x = map2(pos+eps.xyy) - map2(pos-eps.xyy);
	nor.y = map2(pos+eps.yxy) - map2(pos-eps.yxy);
	nor.z = map2(pos+eps.yyx) - map2(pos-eps.yyx);
	return normalize(nor);
}
vec3 camPath( float time )
{
	vec2 p = 600.0*vec2( cos(1.4+0.37*time),
						 cos(3.2+0.31*time) );
return vec3( p.x, 0.0, p.y );
}
void main(void)
{
	vec2 xy = -1.0 + 2.0*gl_FragCoord.xy / iResolution.xy;
vec2 s = xy*vec2(1.75,1.0);
#ifdef STEREO
float isCyan = mod(gl_FragCoord.x + mod(gl_FragCoord.y,2.0),2.0);
	#endif
 
	float time = iGlobalTime*.15 + 4.0*iMouse.x/iResolution.x;
vec3 light1 = normalize( vec3(  0.4, 0.22,  0.6 ) );
 
vec3 ro = camPath( time );
vec3 ta = camPath( time + 3.0 );
ro.y = terrain3( ro.xz ) + 11.0;
ta.y = ro.y - 100.0;
float cr = 0.2*cos(0.1*time);
vec3  cw = normalize(ta-ro);
vec3  cp = vec3(sin(cr), cos(cr),0.0);
vec3  cu = normalize( cross(cw,cp) );
vec3  cv = normalize( cross(cu,cw) );
vec3  rd = normalize( s.x*cu + s.y*cv + 1.5*cw );
#ifdef STEREO
ro += 2.0*cu*isCyan; // move camera to the right - the rd vector is still good
	#endif
float sundot = clamp(dot(rd,light1),0.0,1.0);
vec3 col;
	float t = interesct( ro, rd );
	if( t<0.0 )
	{
  col = vec3(0.85,.95,1.0)*(1.0-0.5*rd.y);
  col += 0.25*vec3(1.0,0.8,0.4)*pow( sundot,12.0 );
 
}
else
{
  vec3 pos = ro + t*rd;
		vec3 nor = calcNormal( pos, t );
  float r = noise( 7.0*pos.xz );
		col = (r*0.25+0.75)*0.9*mix( vec3(0.08,0.05,0.03), vec3(0.13,0.10,0.08), clamp(terrain2( vec2(pos.x,pos.y*48.0))/200.0,0.0,1.0) );
  col = mix( col, 0.15*vec3(0.45,.23,0.04)*(0.50+0.50*r),smoothstep(0.70,0.9,nor.y) );
		col = mix( col, 0.10*vec3(0.30,.30,0.00)*(0.25+0.75*r),smoothstep(0.95,1.0,nor.y) );
	   col *= 0.9;
		 // snow
  float h = smoothstep(55.0,80.0,pos.y + 25.0*fbm(0.01*pos.xz) );
		float e = smoothstep(1.0-0.5*h,1.0-0.1*h,nor.y);
		float o = 0.3 + 0.7*smoothstep(0.0,0.1,nor.x+h*h);
		float s = h*e*o;
		col = mix( col, 0.35*vec3(0.62,0.65,0.7), smoothstep( 0.1, 0.9, s ) );
		 // lighting
		float amb = clamp(0.5+0.5*nor.y,0.0,1.0);
  float dif = clamp( dot( light1, nor ), 0.0, 1.0 );
  float bac = clamp( 0.2 + 0.8*dot( normalize( vec3(-light1.x, 0.0, light1.z ) ), nor ), 0.0, 1.0 );
  float sh = 1.0; if( dif>=0.0001 ) sh = sinteresct(pos+light1*20.0,light1);
 
  vec3 lin  = vec3(0.0);
		lin += dif*vec3(8.00,5.50,3.00)*vec3( sh, sh*sh*0.5+0.5*sh, sh*sh*0.8+0.2*sh );
  lin += amb*vec3(0.30,0.50,0.60);
		lin += bac*vec3(0.60,0.60,0.60);
  col *= lin;
 
  float fo = 1.0-exp(-0.0007*t);
  vec3 fco = vec3(0.55,0.65,0.75) + 0.6*vec3(1.0,0.8,0.5)*pow( sundot, 4.0 );
  col = mix( col, fco, fo );
  col += 0.4*vec3(1.0,0.8,0.4)*pow( sundot, 8.0 )*(1.0-exp(-0.005*t));
}
 
col = pow(col,vec3(0.45));
col = col*0.6 + 0.4*col*col*(3.0-2.0*col);
 
vec2 uv = xy*0.5+0.5;
col *= 0.7 + 0.3*pow(16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y),0.1);
 
	#ifdef STEREO
	col *= vec3( isCyan, 1.0-isCyan, 1.0-isCyan );
#endif
 
gl_FragColor=vec4(col,1.0);
}


#31 Cyberiad

    Member

  • PipPipPipPipPipPip
  • 342 posts

Posted 03 April 2014 - 02:15 PM

Here's a picture of some landscape's I wrote this morning, only took about 10 minutes to write:
Posted Image
full code:
#define PI 3.1415926
#define MAX_ITER 64
#define MIN_STEP 0.001
#define FOV PI/4.0
#define SAMPLE_RADIUS 0.001
#define SPECULAR 5.0
#define MAX_ITER_SHADOW 32
#define MAX_DIST_SHADOW 10.0
#define MIN_DIST_SHADOW 0.1
#define PENUMBRA 16.0
struct light{
vec4 c;
vec4 a;
vec3 p;
};
struct ray{
vec4 c;
vec3 p;
vec3 d;
vec3 n;
int i;
light l;
};
struct view{
vec3 e;
vec3 l;
vec3 u;
};
void srand(vec2 p,inout float s);
float rand(inout float s);
float hash2d(vec2 p);
float grad(float t);
mat2 rot2d(float a);
mat3 rotx(float a);
mat3 roty(float a);
mat3 rotz(float a);
mat3 rot(vec3 z,float a);
vec4 trace(vec2 p,view v,light l);
float dist(inout ray r);
float sphere(inout ray r,vec3 o);
vec3  normal(ray r);
vec4 ambient(ray r);
vec4 diffuse(ray r,vec3 n);
vec4 specular(ray r,vec3 n);
vec4 shadow(ray r);
float dome(inout ray r);
float smin(float a,float b,float k);
float ifs(inout ray r,vec3 o,float d,int i);
float octahedron(vec3 p,float r);
float texture(vec2 p);
float hash2d(vec2 p);
vec2 simplex(vec2 p);
vec2 unsimplex(vec2 p);
void main(void){
vec2 p=(gl_FragCoord.xy-iResolution.xy/2.0)/iResolution.y;
vec2 m=(iMouse.xy-iResolution.xy/2.0)/iResolution.y;
view v;
v.l=vec3(0.0,0.0,0.0);
vec3 vv=vec3(2.0,0.0,0.0);
vv*=roty((PI*m.y)/4.0-PI/8.0);
vv*=rotz(2.0*PI*m.x);
v.e=v.l+vv;
v.u=vec3(0.0,0.0,1.0);
light l=light( 
  vec4(0.5),
  vec4(0.5),
  vec3(5.0)
);
gl_FragColor=trace(p,v,l);
}
vec4 trace(vec2 p,view v,light l){
ray r;
r.d=normalize(v.l-v.e);
vec3 hv=normalize(cross(r.d,v.u));
vec3 vv=normalize(cross(hv,r.d));
r.d*=rot(vv,p.x*FOV);
r.d*=rot(hv,p.y*FOV);
r.p=v.e;
r.i=0;
r.c=vec4(1.0);
r.l=l;
for(int i=0;i<MAX_ITER;i++){
  float d=dist(r);
  if(r.i==1)break;
  d=max(d,MIN_STEP);
  r.p+=r.d*d;
}
vec3 n=normal(r);
return ambient(r)+min(shadow(r),max(diffuse(r,n),specular(r,n)));
}
float dist(inout ray r){
float d=128.0;
d=min(d,dome(r));
//d=min(d,ifs(r,vec3(0.0),128.0,0));
return d;
}
vec4 ambient(ray r){
return r.c*r.l.a;
}
vec4 diffuse(ray r,vec3 n){
vec3 v=r.l.p-r.p;
return clamp(r.c*r.l.c*dot(n,normalize(v)),0.0,1.0);
}
vec4 specular(ray r,vec3 n){
float d=length(r.l.p-r.p);
vec3 v=normalize(r.l.p-r.p);
return r.l.c*max(pow(dot(v,reflect(r.d,n)),SPECULAR),0.0);
}
vec4 shadow(ray r){
r.p-=2.0*MIN_STEP*r.d;
r.d=normalize(r.l.p-r.p);
float s=1.0;
float t=MIN_DIST_SHADOW;
for(int i=0;i<MAX_ITER_SHADOW;i++){
  ray tmp=r;
  tmp.p+=r.d*t;
  float h=dist(tmp);
  if(h<MIN_STEP)return vec4(0.0);
  s=min(s,PENUMBRA*h/t);
  t+=h;
  if(t>MAX_DIST_SHADOW)break;
}
return vec4(s);
}
vec3 normal(ray r){
float d=dist(r);
vec3 n=vec3(SAMPLE_RADIUS,0.0,0.0);
ray r0=r;
ray r1=r;
ray r2=r;
r0.p+=n.xyy;
r1.p+=n.yxy;
r2.p+=n.yyx;
return normalize(vec3(dist(r0)-d,dist(r1)-d,dist(r2)-d));
}
float smin(float a,float b,float k){
float h=clamp(0.5+0.5*(b-a)/k,0.0,1.0);
    return mix(b,a,h)-k*h*(1.0-h);
}
float dome(inout ray r){
float d=dot(r.p+vec3(0.0,0.0,0.5*texture(r.p.xy)),vec3(0.0,0.0,1.0))+0.5;
d=smin(d,50.0-length(r.p),10.0);
if(d<0.0){
  float l=length(r.p);
  r.c=vec4(1.0);
  r.i=1;
}
return d;
}
float sphere(inout ray r,vec3 o){
vec3 p=r.p+o;
float d=length(p)-0.5;
if(d<0.0){
  r.i=1;
  r.c=vec4(1.0);
}
return d;
}
void srand(vec2 p,inout float s){
s=sin(dot(p,vec2(423.62431,321.54323)));
}
float rand(inout float s){
s=fract(s*32322.65432+0.12333);
return abs(fract(s));
}
float hash2d(vec2 p){
float s;
srand(p,s);
return rand(s);
}
float grad(float t){
return 6.0*pow(t,5.0)-15.0*pow(t,4.0)+10.0*pow(t,3.0);
}
mat2 rot2d(float a){
float c=cos(a);
float s=sin(a);
return mat2(
  c,-s,
  s, c);
}
mat3 rotx(float a){
float c=cos(a);
float s=sin(a);
return mat3(
  1.0,0.0,0.0,
  0.0,  c, -s,
  0.0,  s,  c);
}
mat3 roty(float a){
float c=cos(a);
float s=sin(a);
return mat3(
  c,  0.0,  s,
  0.0,1.0,0.0,
  -s, 0.0,  c);
}
mat3 rotz(float a){
float c=cos(a);
float s=sin(a);
return mat3(
    c, -s,0.0,
    s,  c,0.0,
	 0.0,0.0,1.0);
}
mat3 rot(vec3 z,float a){
float c=cos(a);
float s=sin(a);
float b=1.0-c;
return mat3(
  b*z.x*z.x+c,b*z.x*z.y-z.z*s,b*z.z*z.x+z.y*s,
  b*z.x*z.y+z.z*s,b*z.y*z.y+c,b*z.y*z.z-z.x*s,
  b*z.z*z.x-z.y*s,b*z.y*z.z+z.x*s,b*z.z*z.z+c);
}
float ifs(inout ray r,vec3 o,float d,int i){
vec3 p=r.p+o;
float l=0.5;
for(int i=0;i<16;i++){
  d=min(d,octahedron(p,l));
  p=vec3(p.x+2.5*l,p.y,p.z);
  l*=0.5;
}
if(d<0.0){
  r.i=1;
  r.c=vec4(1.0);
}
return d;
}
float octahedron(vec3 p,float r){
return dot(abs(p),normalize(vec3(1.0,1.0,1.0)))-r;
}
float texture(vec2 p){
p=simplex(p);
vec2 p0=floor(p);
vec2 p1=p0+vec2(1.0,0.0);
vec2 p2=p0+vec2(1.0,1.0);
vec2 p3=p0+vec2(0.0,1.0);
vec2 i=fract(p);
float r0,r1,r2;
float d0,d1,d2;
if(i.x>i.y){
  r0=hash2d(p0);
  r1=hash2d(p1);
  r2=hash2d(p2);
  d0=max(1.0-distance(unsimplex(p),unsimplex(p0)),0.0);
  d1=max(1.0-distance(unsimplex(p),unsimplex(p1)),0.0);
  d2=max(1.0-distance(unsimplex(p),unsimplex(p2)),0.0);
}else{
  r0=hash2d(p0);
  r1=hash2d(p2);
  r2=hash2d(p3);
  d0=max(1.0-distance(unsimplex(p),unsimplex(p0)),0.0);
  d1=max(1.0-distance(unsimplex(p),unsimplex(p2)),0.0);
  d2=max(1.0-distance(unsimplex(p),unsimplex(p3)),0.0);
}
return d0*r0+d1*r1+d2*r2;
}
vec2 simplex(vec2 p){
vec2 r;
r.x=1.1547*p.x;
r.y=p.y+0.5*r.x;
return r;
}
vec2 unsimplex(vec2 p){
vec2 r;
r.y=p.y-0.5*p.x;
r.x=p.x/1.1547;
return r;
}


#32 Hex Pallett

    Member

  • PipPipPipPipPipPipPipPipPip
  • Urban Commando
  • Urban Commando
  • 2,009 posts
  • Twitter: Link
  • LocationHomeless, in the streets of Solaris 7

Posted 04 April 2014 - 04:55 AM

Oh, and there's one more thing...I have rather strong logic thinking, which I assume is an advantage, but on the other hand I have *terrible* math skill....like, I went for Economics BA instead of BS because the former takes only Calculus I, that kind of bad.

Is that gonna be a problem?

(btw, against all stereotypes, I'm Asian :D )

#33 Adridos

    Member

  • PipPipPipPipPipPipPipPipPipPipPip
  • Bridesmaid
  • 10,635 posts
  • LocationHiding in a cake, left in green city called New A... something.

Posted 04 April 2014 - 05:54 AM

View PostHelmstif, on 04 April 2014 - 04:55 AM, said:

Is that gonna be a problem?


Well, depends on how complex you want your game to be.

Any game that's above a text adventure does require some maths, especially in the geometric deparment (and as with all maths, that's directly linked to solving equations, thus algebra) and scales through trigonometry, analytical geometry and such pretty fast. However, you should be able to piece a game together even with limited knowledge in those areas if you use third party libraries for things like hit-detection and such.

However, that writes off the "get rich" plan pretty fast, since people are fine if you're using their code for yourself, not so much when it's used for making money they see none of.

If you want to build serious games from scratch, you'll need to know some maths.

#34 Madw0lf

    Member

  • PipPipPipPipPipPip
  • The Raider
  • The Raider
  • 367 posts

Posted 04 April 2014 - 07:20 AM

View PostSiliconLife, on 03 April 2014 - 02:09 PM, said:




I am keeping this thread purely to reference this stuff your posting :D

#35 Cyberiad

    Member

  • PipPipPipPipPipPip
  • 342 posts

Posted 04 April 2014 - 12:31 PM

View PostHelmstif, on 04 April 2014 - 04:55 AM, said:

Oh, and there's one more thing...I have rather strong logic thinking, which I assume is an advantage, but on the other hand I have *terrible* math skill....like, I went for Economics BA instead of BS because the former takes only Calculus I, that kind of bad.

Is that gonna be a problem?

(btw, against all stereotypes, I'm Asian :) )


I too hated math during high school and university. Math get's a lot better and easier once you start programing with it. At academic levels most of the math is analytical, dealing with exact equations and symbolic integration. Once you start programming and have to use math, things can just be brute forced/calculated numerically, no more analytical symbol manipulation. Things that are really complicated such as exact navier-stokes solutions on paper become really simple fit-all solutions when implemented discretly in a program. Exact solutions that usually deal with high order polynomials and integrals turn into adds and multiplies when splitting up the problem into small computational domains. Some solutions can't even be solved analytically and actually require a computational/discrete model. Integrals in a computational simulation just turn into adding and subtracting.

Example:
position = last_position + velocity*delta_time
velocity = last_velocity + acceleration*delta_time
acceleration = gravitational_constant

Symbolic manupulation isn't used in programming so all of the stuff you learned in school now becomes pretty much useless.

#36 Karl Berg

    Technical Director

  • 497 posts
  • LocationVancouver

Posted 04 April 2014 - 07:02 PM

MWO's servers are written in Python and C++. MWO is written in C++.

Algorithms, data-structures, math; yes all hugely important. Far more important than what particular languages you know. Of course, you won't actually get too far without actually learning a language too.

#37 Alaskan Nobody

    Member

  • PipPipPipPipPipPipPipPipPipPipPip
  • The Determined
  • The Determined
  • 10,358 posts
  • LocationAlaska!

Posted 04 April 2014 - 09:35 PM

View PostKarl Berg, on 04 April 2014 - 07:02 PM, said:

Algorithms, data-structures, math; yes all hugely important.

Python! Cool!
Math.... mixed feelings.
I loved math until I hit Algebra (took geometry and the others first)
Algebra was my first failing grade - and boy was it a failing. :)

#38 S3dition

    Member

  • PipPipPipPipPipPipPipPip
  • Elite Founder
  • Elite Founder
  • 1,633 posts
  • LocationLost in the Warp

Posted 04 April 2014 - 10:42 PM

View PostShar Wolf, on 04 April 2014 - 09:35 PM, said:

Python! Cool!
Math.... mixed feelings.
I loved math until I hit Algebra (took geometry and the others first)
Algebra was my first failing grade - and boy was it a failing. :)


Programming actually made me better at math. It gave me a new way to look at linear algebra and got me over that hump and into calculus. I still hate math, but I have a far better understanding now. I guess it gives you some real world applications to grasp concepts that they love to teach with as abstract of methods as possible. Honestly, I think every math class should be taught using a programming language.

#39 Adridos

    Member

  • PipPipPipPipPipPipPipPipPipPipPip
  • Bridesmaid
  • 10,635 posts
  • LocationHiding in a cake, left in green city called New A... something.

Posted 04 April 2014 - 11:37 PM

View PostS3dition, on 04 April 2014 - 10:42 PM, said:

Honestly, I think every math class should be taught using a programming language.


Oh GOD, no...

Any additional layer of artificial abstraction and maths teachers everywhere may as well give up trying to teach those not into maths anything at all. Those good at maths already posses the logical thinking needed for programming, but as far as the actual problematic group goes, you're more likely to make it even harder for them to understand anything at all.
"Brute forcing" alone where teacher simply allows them to solve a problem using actual values behind variables and rounding up messy numbers that calculators throw up instead of solving the problem proper gives you the same result without the additional layer of abstraction (which, imo, is the most difficult part of mathematics for most people in my own experience).

Besides, it's been tried here during the 90s (at least that's what my programming teacher told me when I asked her why does the Book of Math Exercises have Basic code in the latter part next to normal solutions AND full algorithms to the problem) and apparently didn't catch on.

#40 Hex Pallett

    Member

  • PipPipPipPipPipPipPipPipPip
  • Urban Commando
  • Urban Commando
  • 2,009 posts
  • Twitter: Link
  • LocationHomeless, in the streets of Solaris 7

Posted 04 April 2014 - 11:42 PM

View PostKarl Berg, on 04 April 2014 - 07:02 PM, said:

MWO's servers are written in Python and C++. MWO is written in C++.

Algorithms, data-structures, math; yes all hugely important. Far more important than what particular languages you know. Of course, you won't actually get too far without actually learning a language too.


Well...I have no problem with algebra and trig, but as soon as it goes to logarithmic I'm totally hopeless.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users