8 Replies - 892 Views - Last Post: 13 November 2010 - 01:23 PM Rate Topic: -----

#1 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Plz help me ease into a 2d/3d language

Posted 24 October 2010 - 05:46 PM

Hey, I'm a C# programmer and I really need some advice before I once again begin laboriously researching graphics programming (I keep giving up/ running out of time). I'm a C# programmer. I'm interested in designing an application that renders something, and I'm not sure what my next step will be. In the past, I've tried doing C++ DirectX and OpenGL tuts, and the ones on the web were cool... but.. kinda.. not enough to teach me how to do anything productive (or completely beyond me). So here's an outline of what I think an ideal tutorial series would be for teaching someone how to program a 2D scene:

I want to render molecular structures (2D for now) and since that's fairly simple (physics notwithstanding) it seems like an ideal subject for the tutorial series (let's consider ourselves to want to render basically what the tutorialist is drawing in this video http://www.youtube.c...v=3XiHrsZNZko):


Step 1 "Hello World": For a scene of just the atom H (hydrogen of course) I would like to draw a circle on the screen. I'd like the letter H to be smack dab right on top of the circle.

Step 2: I'd like to be able to render the proton + neutron (as just 1 circle labeled 'H') AND an electron.

Step 2.1: How to animate the electron to float along a path (circling the nucleolus)

Step 2.2: How to animate the electron so it looks like it's glowing and all "electric-like" for style points

Step 3: How to draw one of these such scenes in 3D

Step 4: Animate chemical reactions (where molecules are breaking apart/ coming together)

Step 4.5: Encapsulate molecules with.. nebulous, transparent bubbles to help delineate them as specific molecules (e.g. H2O would be encapsulated in a 'watery' looking sack that floats like a bubble-ish looking thing).

Step 5,000 MILLION: Program the electron quantum mechanics in so it can do enzyme simulations that we can watch! (real-live 'physics' engine stuff)


Can anyone suggest the 'simplest' API language-thing to do this in (which can handle step 5,000 MILLION)? And can anyone suggest some books/ tutorials that will get me through steps 1 and 2 fast? Can anyone do the whole tutorial for me (include step 5,000 million plz =P)?
Thanks for your thoughts!

Is This A Good Question/Topic? 0
  • +

Replies To: Plz help me ease into a 2d/3d language

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Plz help me ease into a 2d/3d language

Posted 25 October 2010 - 07:19 AM

Grab XNA. That will take care of the API issues for you. The rest is just general programming, and you said you were already a programmer.
Was This Post Helpful? 1
  • +
  • -

#3 Fib  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 161
  • View blog
  • Posts: 554
  • Joined: 12-March 09

Re: Plz help me ease into a 2d/3d language

Posted 08 November 2010 - 03:58 PM

As Oler1s said, get XNA.

Here are some tutorials on beginning a 2D game.

http://www.riemers.n...rp/series2d.php

You can select each tutorial from the right side.
Was This Post Helpful? 1
  • +
  • -

#4 WolfCoder  Icon User is offline

  • Isn't a volcano just an angry hill?
  • member icon


Reputation: 781
  • View blog
  • Posts: 7,604
  • Joined: 05-May 05

Re: Plz help me ease into a 2d/3d language

Posted 10 November 2010 - 11:40 AM

Isn't there a direct method of DirectX in C#? Well you could do fragment and vertex programs in XNA still. Of course you're going to have to learn a much more powerful, faster, language designed for scientific cluster systems for step 5000.

And there's no such thing as a "2D Language" or a "3D Language", just a language. 2D games these days are actually 3D games drawn with quads in orthographic perspective anyway so it gets loaded into your video card.

Isn't there a direct method of DirectX in C#? Well you could do fragment and vertex programs in XNA still. Of course you're going to have to learn a much more powerful, faster, language designed for scientific cluster systems for step 5000.

And there's no such thing as a "2D Language" or a "3D Language", just a language. 2D games these days are actually 3D games drawn with quads in orthographic perspective anyway so it gets loaded into your video card.
Was This Post Helpful? 1
  • +
  • -

#5 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Plz help me ease into a 2d/3d language

Posted 10 November 2010 - 09:25 PM

Quote

Isn't there a direct method of DirectX in C#?
There isn't (officially). Microsoft discontinued the bindings it supported (Managed DirectX). Thankfully, there's a really good community project (SlimDX) that provides bindings.

Of course, you then have to be able to use the APIs. I suggested XNA because it provides a simpler way to get graphics on screen. The rest of what is being asked for isn't API specific. It's algorithms and general programming. Regardless of language, you still have to deal with the same work.

This post has been edited by Oler1s: 10 November 2010 - 09:27 PM

Was This Post Helpful? 0
  • +
  • -

#6 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Plz help me ease into a 2d/3d language

Posted 12 November 2010 - 02:10 PM

Thanks for the posts. I tried to make a post yesterday but it didn't go through =/

So I'm out of my element, but I think what you guys are suggesting is that I use a high efficiency language to get everything going (I can probably port to ASM at some point), and I should also use DirectX to do some of my work through a shader program? I don't know anything about shader programs yet, but it looks like the best way to draw electrons is to code them with a geometry shader?

Does that sound right? Pass the atom object to the geometry shader (including energy levels, electron quantity, position, etc.) and have the shader make all the electron objects? I think I would need to get information back out of the pipeline if Event_NewBondAccurs or something of that nature, where the electron becomes part of a second atom. At the most distant zoom, I won't care so much about having it look pretty, just having the logic functioning in accordance with the physics equations I give it.

The loose algo for calculating the electron position might be something like this:
AtomObject myAtom = aCarbonAtom;  // this atom would be 1 of as many as ~3,000 at minimum zoom (could be 300,000 electrons out there, not all drawn, but all accounted for)
                                  // I wouldn't mind drawing simple sphere's, at this point, as symbols of electrons.  or even pyramids if that's easiest, they have no shape anyway.
myAtom.ElectronQty = 14;
myAtom.ElectronArray[] = new array[14];  // my brain isn't thinking, I'm just demonstrating an array here of those 14 electrons
myAtom.Energy = VagueEnergyQty; // not researched on this enough yet

EnergySpreadAcrossAllElectrons = myAtom.Energy // I'm pulling this off the top of my head, I think the electrons on the outer shell have a probability of being in random/ odd shells beyond their nearest shell, but I could be wrong on this, AND there's a better way to handle this I'm sure, i'm jumping a head though.  
for (int i = 0; i < 14; i++)
{
    myAtom.ElectronArray[i].EnergyHome = FindElectronsBasePoint(myAtom.Energy);  // Do Calculation To Find What Probability Routine To Use in order to draw the electron there
    // NOTE:  Ignore myAtom.Energy, It would be used to ensure that all electrons were positions in 'electron shells' that the atom's energy could support
}
    // RenderAllElectrons();
    {
        ForEach (Electron e in myAtom...)
        {
            // a line of code would need to locate the EXACT position of the electron with in it's shell (with in it's home which was determined previously) 
            e.ElectronArray[i].ExactPosition = CalculateEXACTPositionOfElectron[e.ElectronArray[i].EnergyHome, e.ElectronArray[i], EnergySpreadAcrossAllElectrons];

            EnergySpreadAcrossAllElectrons = EnergySpreadAcrossAllElectrons - myAtom.ElectronArray[i].EnergyPosition; // just making sure all the energy of the atom is exhibited in the aggrogate distance of all the electrons FROM the nucleus.  (this is from memory, there's prolly TONS more to it than that, lol.. and this approach is terribly wrong I think)
            }
RenderAllTheElectrons(HostAtomXYZ, ExactPosition);  // a line would draw all the electrons
Return AllValenceElectronPositionsXYZ;              // but more importantly, a line would track all the electrons so they can be checked for "collision" so to speak.  
                                                    // And even electrons not drawn on screen would need their calculated positions tested
                                                    // if no collisions, then the CPU wouldn't need to manipulate the data objects
                                                    // if there are collisions (the electrons being drawn in a place where the host atom is electromagnetically pulling the electron less powerfully than is another atom, [i]"yoink"[/i]) then the host atom would have ElectronQty--  and the other electron would be ElectronQty++, or covalent relationships would be established, depending on... electromagnetic conditions and also I think maybe the "motion/velocity" of the two atoms



Ok, I'm not sure if I have written a good explanation there, but I think you can see what needs to be done. So that leaves me with the following questions.

Can the above code be handled by geometry shaders?
Should it be handled by a geometry shader?
Also, how exactly do you tell when the graphics card will be better than the CPU at processing (e.g. when GPUs are better at password cracking)? That question might belong in it's own thread actually, it's straying from the thread's title a smidgen, and getting a little specific.
Was This Post Helpful? 0
  • +
  • -

#7 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Plz help me ease into a 2d/3d language

Posted 12 November 2010 - 04:25 PM

Quote

So I'm out of my element, but I think what you guys are suggesting is that I use a high efficiency language to get everything going
No. In fact, you need to worry about algorithmic issues. Writing a high efficiency but naive O(n^2) algorithm impresses no one. It's just silly.

Quote

I can probably port to ASM at some point
You also need to ditch this mentality. This whole "ASM is fastest" mentality runs around in the beginner circles. They haven't actually done any real high performance work, so they talk about ASM like a folk legend.

Quote

I should also use DirectX to do some of my work through a shader program
If you aren't aware of this already, GPUs these days have programmable pipelines. That means you need to write programs to do stuff on the GPU. These programs are called shaders.

Quote

I don't know anything about shader programs yet, but it looks like the best way to draw electrons is to code them with a geometry shader
No. Besides, it's unlikely you even have hardware that supports geometry shaders.

Quote

Also, how exactly do you tell when the graphics card will be better than the CPU at processing
You've got lots of parallel work to be done, that doesn't require things like double precision, etc. It's a bit like rendering graphics. You push bulk data to GPU, operate on that with parallel algorithms, and fetch results.

You're basically running ahead of yourself, to the point that you sound silly.

Broach each issue at a time, and study the topic properly. Are you wondering about how to render things on screen? Use a platform like XNA, or use Direct3D or OpenGL. If you don't use an abstraction, you'll be interested in books like Real Time Rendering and Fundamentals of Computer Graphics.
Was This Post Helpful? 0
  • +
  • -

#8 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Plz help me ease into a 2d/3d language

Posted 13 November 2010 - 09:16 AM

"general purpose code" for the GPU != shaders
Google for CUDA Toolkit to find out about it and OpenCL
.NET != compiled languages, clever algorithms and wit won't efface this aspect
But looking silly is nothing to worry about on the world wide web
Was This Post Helpful? 0
  • +
  • -

#9 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Plz help me ease into a 2d/3d language

Posted 13 November 2010 - 01:23 PM

What did you want to be told? Write code in assembly and you'll get the fastest performance possible? Use CUDA to do some of the computations and you'll get order of magnitude speedups?

I mean, I don't see what you have to ask us, given the constraints you set for yourself.

- You don't want abstractions. So that means C++, C and Assembly.
- You want to render in chosen languages. That means OpenGL and Direct3D.
- You want to write compute kernels for the GPU. That means CUDA if you have Nvidia hardware and OpenCL if you want to support AMD.

But you also tell us you want quick and easy, which requires high level languages, and not mucking with low level details, which invalidates everything above.

You also want to render 3D scenes. That means pushing vertex and texture data to GPU, then having programs do lighting and shading, and then rasterizing the scene. Those programs are called shaders. That is not GPGPU, that is just plain old graphics programming. I have no idea what your code GPGPU != shaders comment means in light of this.

You say .NET != compiled languages. So what you are telling me is that an abstraction suddenly gives you a massive performance loss. Can you tell me how? Have you done any benchmarks? Have you looked at presentations on benchmarks?

You asked for the simplest way to get your work done. You are already a C# programmer. But you think it's simpler to implement all low level plumbing in, say, C++? How do you intend to outperform a solution in .NET, while still shying away from details?

Have you:

- Looked at books on graphics theory? I mentioned Real Time Rendering and Fundamentals of Computer Graphics above.
- Been able to construct any kind of scene by yourself? You can use shaders in XNA, for example. Have you done this?
- Programmed any kind of underlying simulation?
- Benchmarked and collected metrics on performance? Identified bottlenecks appropriately?
- Tried optimizing purely in C#?

It looks like you want to write a high performance solution that beats other abstractions...without actually dealing with the details that abstractions like .NET have to consider. Sounds like you want magic.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1