Interior Mapping

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!

Postby Oogst » Tue Jun 12, 2007 8:06 pm

I am working on a number of variations now, including adding some form of furniture, varying the sizes of the rooms, varying the lighting per room and varying the textures per room. Some of these require a form of randomness, where I can map en 3D position to a random number. How can I do this in a shader? I saw an implementation using perlin noise that required 70 instructions (!) for the noise alone, which seems way too much. A 3D texture does not seem very proper, because it would require quite a large size to work and sizes of 3D textures explode quickly. What approach would you folks advice?

The very specific requirements I am looking for right now is to generate either a 0 or a 1 from a 3D integer coordinate to decide whether a room is lit or not. I tried using sin in combination with step for this, but that gave repetitions all the time.
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
Oogst
OGRE Expert User
OGRE Expert User
 
Posts: 1034
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby Kencho » Tue Jun 12, 2007 8:53 pm

Hmmm... a cheap method to create some randomness? I think that multiplying the coords by a very large prime, adding another prime, and then using modulus (by another large prime) might work fine, or at least not create such obvious repetitions.
Image
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
 
Posts: 4011
Kudos: 1
Joined: 19 Sep 2003
Location: Burgos, Spain

Postby Oogst » Tue Jun 12, 2007 9:04 pm

Maybe a stupid question, but how can I do modulo in a shader model 2.x shader?
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
Oogst
OGRE Expert User
OGRE Expert User
 
Posts: 1034
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby Kencho » Tue Jun 12, 2007 9:17 pm

I don't really know :? :oops:
Image
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
 
Posts: 4011
Kudos: 1
Joined: 19 Sep 2003
Location: Burgos, Spain

Postby jjp » Tue Jun 12, 2007 9:30 pm

As far as I remember one of the articles in GPU Gems 2 shows how to do 3d-noise with about 50 instructions..
Enough is never enough.
jjp
Silver Sponsor
Silver Sponsor
 
Posts: 597
Kudos: 0
Joined: 07 Jan 2007
Location: Cologne, Germany

Postby inneractive » Tue Jun 12, 2007 9:56 pm

I have to admit that your technique looks very strange and unrealistic for now. It's probably been mentioned in the thread that glass has reflective properties. Perhaps you will need to do another pass that blends the interior with exterior environment reflection to get a more realistic look.
-Joe
User avatar
inneractive
Gnoblar
 
Posts: 19
Kudos: 0
Joined: 03 Jun 2007
Location: Bay Area, California

Postby Prezadent » Wed Jun 13, 2007 12:59 am

A link to the newest demo really needs to be kept in the first post.
Prezadent
Gnoblar
 
Posts: 18
Kudos: 0
Joined: 10 Feb 2007

Postby deficite » Wed Jun 13, 2007 3:42 am

This is wonderful! We sure have some bright minds here at OGRE :D
User avatar
deficite
Gremlin
 
Posts: 160
Kudos: 0
Joined: 15 Oct 2005
Location: TN, USA

Postby dartsman » Wed Jun 13, 2007 4:33 am

wow, this could be used for some awesome city scenes for sure :)

awesome work!

can't wait to try the demo, and for some more screenshots ;)
User avatar
dartsman
Kobold
 
Posts: 38
Kudos: 0
Joined: 02 Jul 2005
Location: Queensland, Australia

Postby Shadow007 » Wed Jun 13, 2007 7:48 am

What you need is a hash function to get int f(x,y,z) = hash(x + hash(y + hash(z)));

You would get 32 bits to choose from :)


Now as a hash, you can use some kind of pseudoRNG (similar to what Kencho suggests).

You can also have a look at the following link :Long Period Hash Functions for Procedural Texturing. http://www.cs.kuleuven.ac.be/~graphics/CGRG.PUBLICATIONS/LagaeDutre2006LongPeriodHashFunctionsForProceduralTexturing


Oogst wrote:Maybe a stupid question, but how can I do modulo in a shader model 2.x shader?


Wouldn't that be a % b = a - (floor(a/b) * b) ?
There may be easier possibilities though.
Shadow007
Gremlin
 
Posts: 185
Kudos: 0
Joined: 07 May 2005

Postby Oogst » Wed Jun 13, 2007 8:00 am

inneractive wrote:I have to admit that your technique looks very strange and unrealistic for now. It's probably been mentioned in the thread that glass has reflective properties. Perhaps you will need to do another pass that blends the interior with exterior environment reflection to get a more realistic look.

Some of the images already do that! It is just that the reflection is set to pretty weak to show the effect of Interior Mapping more clearly for demoing purposes. (is that de-moing or demo-ing?) I think I should also make the balance between reflection and interior depend on the angle with the glass, to make a sort of fresnel-effect.
Shadow007 wrote:What you need is a hash function to get int f(x,y,z) = hash(x + hash(y + hash(z)));

You would get 32 bits to choose from :)

Now as a hash, you can use some kind of pseudoRNG (similar to what Kencho suggests).

You can also have a look at the following link :Long Period Hash Functions for Procedural Texturing. http://www.cs.kuleuven.ac.be/~graphics/CGRG.PUBLICATIONS/LagaeDutre2006LongPeriodHashFunctionsForProceduralTexturing

That sounds interesting, but also very complex. Also, shader model 2 does not let me look at individual bits. I have not had a detailed look at the Kencho-paper now, though, so I will look at that as soon as I have the time.
Shadow007 wrote:Wouldn't that be a % b = a - (floor(a/b) * b) ?
There may be easier possibilities though.

Doh! I should have been able to think of that myself! :o
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
Oogst
OGRE Expert User
OGRE Expert User
 
Posts: 1034
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby inneractive » Wed Jun 13, 2007 9:36 am

Oogst wrote:Some of the images already do that! It is just that the reflection is set to pretty weak to show the effect of Interior Mapping more clearly for demoing purposes. (is that de-moing or demo-ing?) I think I should also make the balance between reflection and interior depend on the angle with the glass, to make a sort of fresnel-effect.


Oh okay, sorry I missed that. I think this will be great for city scenes. A fresnel effect would be really nice.
-Joe
User avatar
inneractive
Gnoblar
 
Posts: 19
Kudos: 0
Joined: 03 Jun 2007
Location: Bay Area, California

Postby Shadow007 » Wed Jun 13, 2007 9:51 am

Found an other source for what you want :
http://www.csee.umbc.edu/~olano/s2005c37/ch04.pdf

I've got some source code :
Code: Select all
// vertex to fragment communication for noise shaders
varying vec3 Nin;
// 2D noise texture
uniform sampler2D ntex;
modulus for random hash
const float modulus = 61;
void
main()
{
// integer and fractional components of input
float fracArg = fract(modulus*Nin.z);
float intArg = floor(modulus*Nin.z);
// hash z & z+1 to get offsets for noise slices
vec2 hash = mod(intArg,modulus);
hash.y = hash.y+1;
hash = mod(hash*hash,modulus);
hash = hash/modulus;
// look up noise and blend slices
vec2 g0, g1;
g0 = texture2D(ntex, vec2(Nin.x,Nin.y+hash.x)).ra*2-1;
g1 = texture2D(ntex, vec2(Nin.x,Nin.y+hash.y)).ra*2-1;
float noise = mix( g0.x+g0.y*fracArg,
g1.x+g1.y*(fracArg-1),
smoothstep(0,1,fracArg));
// combine with lighting
gl_FragColor = (noise*.5+.5)*gl_Color;
}

you don't need to do the "noise steps" ... just check the result with < or > ...
Shadow007
Gremlin
 
Posts: 185
Kudos: 0
Joined: 07 May 2005

Postby Shadow007 » Wed Jun 13, 2007 4:01 pm

Of course, the easiest solution would be to use a "Noise" 2D Texture.To get a 3D result, you can do : ((h2d(x,y) + z)% 61)^2
Shadow007
Gremlin
 
Posts: 185
Kudos: 0
Joined: 07 May 2005

Postby Oogst » Sun Jun 24, 2007 7:30 pm

(I am sorry for not reacting any earlier, but I had some school work to do and had no time to try these things until now.)
Shadow007 wrote:Of course, the easiest solution would be to use a "Noise" 2D Texture.To get a 3D result, you can do : ((h2d(x,y) + z)% 61)^2

Hmm, that one looks really simple, but I do not get how it can work. What is that "h2d"-thing? Do you mean a texture read there? In that case the formula seems wrong, because the texture will result in a float between 0 and 1, which will be almost fully cancelled out by the much larger value in z.

As an alternative, I tried something really stupid that kind of works:
Code: Select all
float calculateBinaryNoise(float3 position, sampler2D noiseTexture, float threshold)
{
   float3 noises = float3(tex2D(noiseTexture, float2(position.x, position.y) / 32).r,
                           tex2D(noiseTexture, float2(position.z, position.x) / 32).r,
                           tex2D(noiseTexture, float2(position.y, position.z) / 32).r);
   float result = noises.x + noises.y + noises.z;
   result /= 3;
   result = step(result, threshold);
   return result;
}


It does not seem to be perfectly noisy, though, and it requires three texture reads, which seems like quite a lot. The result of switching of lights is kind of fun, however:

Image

I have made a button to increase the threshold, thus slowly turning on all the lights in the building. That looks funky. Can't wait to do that in an entire city and make a timelapse of the sun lowering and the city turning on.
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
Oogst
OGRE Expert User
OGRE Expert User
 
Posts: 1034
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby Shadow007 » Mon Jun 25, 2007 11:09 am

Oogst wrote:
Shadow007 wrote:To get a 3D result, you can do : ((h2d(x,y) + z)% 61)^2

Hmm, that one looks really simple, but I do not get how it can work. What is that "h2d"-thing? Do you mean a texture read there? In that case the formula seems wrong, because the texture will result in a float between 0 and 1, which will be almost fully cancelled out by the much larger value in z.


Of course you're right. you can then scale that one to :
Code: Select all
(floor((h2d(x,y) * 61)+ floor(z))% 61)^2

That result then needs to be re-moded to something like 59 or 67.
Shadow007
Gremlin
 
Posts: 185
Kudos: 0
Joined: 07 May 2005

Postby Oogst » Tue Jun 26, 2007 10:43 am

Would that formula not give a very regular increase over z?
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
Oogst
OGRE Expert User
OGRE Expert User
 
Posts: 1034
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby Shadow007 » Tue Jun 26, 2007 12:55 pm

Yes, it would ... I once again forgot to apply an operator :
apply a %67 after the square operation...
Shadow007
Gremlin
 
Posts: 185
Kudos: 0
Joined: 07 May 2005

Postby Oogst » Tue Jun 26, 2007 1:06 pm

Code: Select all
((floor((h2d(x,y) * 61)+ floor(z))% 61)^2) % 61

At least it looks pretty complicated now... :shock:

I cannot try it here at school, but I will try this new one soon. :)
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
Oogst
OGRE Expert User
OGRE Expert User
 
Posts: 1034
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby Shadow007 » Tue Jun 26, 2007 2:02 pm

Perhaps you can try with not "flooring" the intermediary results.
It may be complicated, but it's only 1 texture read ...

And I guess you can save a few instructions at the end by not remultiplying the "rest" by 61 at the last mod (you need a value between 0-1 right ?)

BTW I find the "On/Off" interior mapping quite convincing :)
Did you get any results with the "furniture ?"
Shadow007
Gremlin
 
Posts: 185
Kudos: 0
Joined: 07 May 2005

Postby Oogst » Wed Jun 27, 2007 7:59 am

I don't have time to work on it this week, but I already have the way the furniture and animated characters are going to work on paper. I just need to code it, but I am again too busy with school to work on it this week. I will have a demo of these things in a couple of weeks, though. And I am writing a paper on the whole topic as well.
blog.oogst3d.net: my dev blog and portfolio
Ronimo Games: my game dev company
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/PS3/PS4)
Swords & Soldiers: side-scrolling RTS (PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
Oogst
OGRE Expert User
OGRE Expert User
 
Posts: 1034
Kudos: 33
Joined: 29 Mar 2004
Location: the Netherlands

Postby Shadow007 » Wed Jun 27, 2007 8:13 am

Take your time :))

Just a note : going through the paper that suggests the (h(x,y) + z)mod M
http://www.csee.umbc.edu/~olano/papers/mNoise.pdf,
I found out that I forgot one "cool" thing about it : Using 4 channels of colors, you can get 4 independent values out of 1 sequence of operations.

So, you can have lit/unlit, furniture, people, doors ... with 1 texture lookup and the following mod operations ...
Shadow007
Gremlin
 
Posts: 185
Kudos: 0
Joined: 07 May 2005

Postby JRowe47 » Wed Jun 27, 2007 8:14 am

How expensive would render to texture be, to show actors moving around inside and so on? That would be awesome, if feasible... silhouettes on shades, an ogre looking out the window from his or her desk... objects in a room?

Really neat, can't wait to read your paper :)
JRowe47
Gnoblar
 
Posts: 13
Kudos: 0
Joined: 26 Jun 2007

I worked on something similar for a game company.

Postby Lee04 » Wed Jun 27, 2007 8:24 am

Super great work!

I worked on something similar for a game company.
It also had an "old glass" effect on the windows.

They did a game set in New York, still the TD killed this and said we already have so many materials for the engine (they used Unreal 3 engine) why are you doing this? He asked...

Instead they modeled all windows...

And then they wondered why it was so slow....rendering.
Ph.D. student in game development
User avatar
Lee04
Minaton
 
Posts: 944
Kudos: 2
Joined: 05 Jul 2004
Location: Sweden

Postby Shadow007 » Wed Jun 27, 2007 8:50 am

JRowe47 wrote:How expensive would render to texture be, to show actors moving around inside and so on? That would be awesome, if feasible... silhouettes on shades, an ogre looking out the window from his or her desk... objects in a room?

Moving around would be quite difficult I think :)



JRowe47 wrote:Really neat, can't wait to read your paper :)

Seconded :)

BTW it seems I forgot to tell you how great I find the "preview" you did a few days ago (cf the image upper in this page).
Shadow007
Gremlin
 
Posts: 185
Kudos: 0
Joined: 07 May 2005

PreviousNext

Return to Showcase

Who is online

Users browsing this forum: No registered users and 4 guests