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!
Post Reply
Oogst
OGRE Expert User
OGRE Expert User
Posts: 1067
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 43
Contact:

Post by Oogst »

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.
My dev blog
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/X1/PS3/PS4)
Blightbound: coop online dungeon crawler (PC)
Swords & Soldiers: side-scrolling RTS (Switch/PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
The Ageless Gate: cello album
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

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
Oogst
OGRE Expert User
OGRE Expert User
Posts: 1067
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 43
Contact:

Post by Oogst »

Maybe a stupid question, but how can I do modulo in a shader model 2.x shader?
My dev blog
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/X1/PS3/PS4)
Blightbound: coop online dungeon crawler (PC)
Swords & Soldiers: side-scrolling RTS (Switch/PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
The Ageless Gate: cello album
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

I don't really know :? :oops:
Image
jjp
Silver Sponsor
Silver Sponsor
Posts: 597
Joined: Sun Jan 07, 2007 11:55 pm
Location: Cologne, Germany
Contact:

Post by jjp »

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.
User avatar
inneractive
Gnoblar
Posts: 19
Joined: Sun Jun 03, 2007 2:32 am
Location: Bay Area, California
Contact:

Post by inneractive »

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
Prezadent
Gnoblar
Posts: 18
Joined: Sat Feb 10, 2007 11:59 pm

Post by Prezadent »

A link to the newest demo really needs to be kept in the first post.
User avatar
deficite
Gremlin
Posts: 160
Joined: Sat Oct 15, 2005 4:31 pm
Location: TN, USA
Contact:

Post by deficite »

This is wonderful! We sure have some bright minds here at OGRE :D
User avatar
dartsman
Kobold
Posts: 38
Joined: Sat Jul 02, 2005 2:40 pm
Location: Queensland, Australia
Contact:

Post by dartsman »

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 ;)
Shadow007
Gremlin
Posts: 185
Joined: Sat May 07, 2005 3:27 pm

Post by Shadow007 »

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/ ... lTexturing

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.
Oogst
OGRE Expert User
OGRE Expert User
Posts: 1067
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 43
Contact:

Post by Oogst »

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/ ... lTexturing
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
My dev blog
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/X1/PS3/PS4)
Blightbound: coop online dungeon crawler (PC)
Swords & Soldiers: side-scrolling RTS (Switch/PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
The Ageless Gate: cello album
User avatar
inneractive
Gnoblar
Posts: 19
Joined: Sun Jun 03, 2007 2:32 am
Location: Bay Area, California
Contact:

Post by inneractive »

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
Shadow007
Gremlin
Posts: 185
Joined: Sat May 07, 2005 3:27 pm

Post by Shadow007 »

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
Joined: Sat May 07, 2005 3:27 pm

Post by Shadow007 »

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
Oogst
OGRE Expert User
OGRE Expert User
Posts: 1067
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 43
Contact:

Post by Oogst »

(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.
My dev blog
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/X1/PS3/PS4)
Blightbound: coop online dungeon crawler (PC)
Swords & Soldiers: side-scrolling RTS (Switch/PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
The Ageless Gate: cello album
Shadow007
Gremlin
Posts: 185
Joined: Sat May 07, 2005 3:27 pm

Post by Shadow007 »

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.
Oogst
OGRE Expert User
OGRE Expert User
Posts: 1067
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 43
Contact:

Post by Oogst »

Would that formula not give a very regular increase over z?
My dev blog
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/X1/PS3/PS4)
Blightbound: coop online dungeon crawler (PC)
Swords & Soldiers: side-scrolling RTS (Switch/PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
The Ageless Gate: cello album
Shadow007
Gremlin
Posts: 185
Joined: Sat May 07, 2005 3:27 pm

Post by Shadow007 »

Yes, it would ... I once again forgot to apply an operator :
apply a %67 after the square operation...
Oogst
OGRE Expert User
OGRE Expert User
Posts: 1067
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 43
Contact:

Post by Oogst »

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. :)
My dev blog
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/X1/PS3/PS4)
Blightbound: coop online dungeon crawler (PC)
Swords & Soldiers: side-scrolling RTS (Switch/PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
The Ageless Gate: cello album
Shadow007
Gremlin
Posts: 185
Joined: Sat May 07, 2005 3:27 pm

Post by Shadow007 »

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 ?"
Oogst
OGRE Expert User
OGRE Expert User
Posts: 1067
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 43
Contact:

Post by Oogst »

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.
My dev blog
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/X1/PS3/PS4)
Blightbound: coop online dungeon crawler (PC)
Swords & Soldiers: side-scrolling RTS (Switch/PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
The Ageless Gate: cello album
Shadow007
Gremlin
Posts: 185
Joined: Sat May 07, 2005 3:27 pm

Post by Shadow007 »

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 ...
JRowe47
Gnoblar
Posts: 13
Joined: Tue Jun 26, 2007 11:02 am

Post by JRowe47 »

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 :)
User avatar
Lee04
Minaton
Posts: 945
Joined: Mon Jul 05, 2004 4:06 pm
Location: Sweden
x 1

I worked on something similar for a game company.

Post by Lee04 »

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
Shadow007
Gremlin
Posts: 185
Joined: Sat May 07, 2005 3:27 pm

Post by Shadow007 »

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).
Post Reply