include/material.h
author Radek Brich <radek.brich@devl.cz>
Wed, 19 Aug 2009 09:18:29 +0200
branchpyrit
changeset 101 50a994a57849
parent 98 64638385798a
permissions -rw-r--r--
vcproj build target only for cc=msvc, fix sdl-config
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
94
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 93
diff changeset
     1
/**
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 93
diff changeset
     2
 * @file  material.h
4c8abb8977dc update README
Radek Brich <radek.brich@devl.cz>
parents: 93
diff changeset
     3
 * @brief Material and Texture classes
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
 *
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
 * This file is part of Pyrit Ray Tracer.
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
 *
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
 * Copyright 2006, 2007, 2008  Radek Brich
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
 *
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
 * of this software and associated documentation files (the "Software"), to deal
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
 * in the Software without restriction, including without limitation the rights
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
 * copies of the Software, and to permit persons to whom the Software is
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
 * furnished to do so, subject to the following conditions:
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
 *
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
 * The above copyright notice and this permission notice shall be included in
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
 * all copies or substantial portions of the Software.
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
 *
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
 * THE SOFTWARE.
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
#ifndef MATERIAL_H
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
#define MATERIAL_H
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
#include "common.h"
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
#include "vector.h"
88
f7edb3b90816 merge pixmap handling from sampler, material.h and ccdemos's image module to new Pixmap class
Radek Brich <radek.brich@devl.cz>
parents: 82
diff changeset
    33
#include "pixmap.h"
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
 * perlin noise
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
Float perlin(Float x, Float y, Float z);
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
 * general texture
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
class Texture
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
public:
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
	virtual ~Texture() {};
98
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
    47
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
    48
	/** evaluate texture colour in the point of space */
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
    49
	virtual Colour evaluate(const Vector &point) = 0;
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    51
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
 * general colour map
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
class ColourMap
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
public:
82
930a2d3ecaed prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents: 81
diff changeset
    58
	virtual ~ColourMap() {};
98
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
    59
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
    60
	/** map float value to colour */
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
	virtual Colour map(const Float &val) = 0;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    63
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    64
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    65
 * linear colour map
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    66
 * maps value lineary between two colours
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    67
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    68
class LinearColourMap: public ColourMap
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    69
{
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
    70
	Colour col, cdiff;
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    71
public:
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    72
	LinearColourMap(const Colour &clow, const Colour &chigh):
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    73
		col(clow), cdiff(chigh-clow) {};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    74
	Colour map(const Float &val) { return col + cdiff*val; };
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    75
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    76
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    77
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    78
 * bound colour map
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    79
 * initialize with two arrays, bounds and colours, of same size
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    80
 * bounds must contain numbers between 0 and 1 in rising order,
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    81
 * last number should be larger than max 'val'
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    82
 * colours are mapped to slices between bounds (with zero being
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    83
 * implicit bottom bound)
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    84
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    85
class BoundColourMap: public ColourMap
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    86
{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    87
	Float *bounds;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    88
	Colour *colours;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    89
public:
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    90
	BoundColourMap(Float *abounds, Colour *acolours):
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    91
		bounds(abounds), colours(acolours) {};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    92
	Colour map(const Float &val)
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    93
	{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    94
		Float *b = bounds;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    95
		Colour *c = colours;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    96
		while (val > *b)
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    97
		{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    98
			b++;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    99
			c++;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   100
		}
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   101
		return *c;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   102
	};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   103
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   104
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   105
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   106
 * general texture mapping
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   107
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   108
class TextureMap
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   109
{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   110
protected:
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   111
	Vector center;
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   112
	Float invsize;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   113
public:
98
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   114
	/**
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   115
	 * texture map constructor
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   116
	 * @param[in] acenter  central point of texture mapping
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   117
	 * @param[in] size     Size of the texture.
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   118
	 *                     One world space unit is mapped to one texture size
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   119
	 *                     divided by this number.
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   120
	 */
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   121
	TextureMap(const Vector &acenter, const Float &size):
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   122
		center(acenter), invsize(1.0f/size) {};
82
930a2d3ecaed prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents: 81
diff changeset
   123
	virtual ~TextureMap() {};
98
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   124
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   125
	/**
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   126
	 * map 3D space point to 2D u,v coordinates
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   127
	 * @param[in] point  a point in 3D space
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   128
	 * @param[out] u     horizontal texture coordinate
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   129
	 * @param[out] v     vertical texture coordinate
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   130
	 */
96
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
   131
	virtual void map(const Vector &point, Float &u, Float &v) const = 0;
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   132
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   133
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   134
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   135
 * planar mapping
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   136
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   137
class PlanarMap: public TextureMap
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   138
{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   139
public:
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   140
	PlanarMap(const Vector &acenter, const Float &size):
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   141
		TextureMap(acenter, size) {};
96
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
   142
	void map(const Vector &point, Float &u, Float &v) const
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   143
	{
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   144
		const Vector p = point - center;
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   145
		u = p.x*invsize;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   146
		v = p.y*invsize;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   147
	};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   148
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   149
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   150
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   151
 * cubic mapping
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   152
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   153
class CubicMap: public TextureMap
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   154
{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   155
public:
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   156
	CubicMap(const Vector &acenter, const Float &size):
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   157
		TextureMap(acenter, size) {};
96
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
   158
	void map(const Vector &point, Float &u, Float &v) const
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   159
	{
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   160
		const Vector p = point - center;
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   161
		if (fabs(p.x) > fabs(p.y))
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   162
		{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   163
			if (fabs(p.x) > fabs(p.z))
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   164
			{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   165
				if (p.x < 0)
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   166
					u = -p.y;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   167
				else
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   168
					u = p.y;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   169
				v = p.z;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   170
			}
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   171
			else
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   172
			{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   173
				if (p.z < 0)
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   174
					u = -p.x;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   175
				else
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   176
					u = p.x;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   177
				v = p.y;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   178
			}
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   179
		}
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   180
		else
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   181
		{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   182
			if (fabs(p.y) > fabs(p.z))
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   183
			{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   184
				if (p.y < 0)
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   185
					u = -p.x;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   186
				else
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   187
					u = p.x;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   188
				v = p.z;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   189
			}
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   190
			else
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   191
			{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   192
				if (p.z < 0)
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   193
					u = -p.x;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   194
				else
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   195
					u = p.x;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   196
				v = p.y;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   197
			}
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   198
		}
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   199
		u = u*invsize;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   200
		v = v*invsize;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   201
	};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   202
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   203
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   204
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   205
 * cylindrical mapping
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   206
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   207
class CylinderMap: public TextureMap
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   208
{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   209
public:
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   210
	CylinderMap(const Vector &acenter, const Float &size):
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   211
		TextureMap(acenter, size) {};
96
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
   212
	void map(const Vector &point, Float &u, Float &v) const
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   213
	{
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   214
		const Vector p = point - center;
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   215
		u = ( PI + atan2(p.z, p.x) ) * invsize;
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   216
		v = p.y * invsize;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   217
	};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   218
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   219
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   220
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   221
 * spherical mapping
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   222
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   223
class SphereMap: public TextureMap
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   224
{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   225
public:
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   226
	SphereMap(const Vector &acenter, const Float &size):
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   227
		TextureMap(acenter, size) {};
96
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
   228
	void map(const Vector &point, Float &u, Float &v) const
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   229
	{
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   230
		const Vector p = point - center;
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   231
		u = ( PI + atan2(p.z, p.x) ) * invsize;
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   232
		v = acos(p.y / p.mag()) * invsize;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   233
	};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   234
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   235
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   236
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   237
 * general 2D texture
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   238
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   239
class Texture2D: public Texture
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   240
{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   241
protected:
96
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
   242
	const TextureMap *map;
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   243
public:
96
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
   244
	Texture2D(const TextureMap *amap): map(amap) {};
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   245
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   246
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   247
/**
81
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   248
 * 2D image texture
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   249
 */
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   250
class ImageTexture: public Texture2D
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   251
{
96
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
   252
	const Pixmap *pixmap;
81
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   253
public:
96
9eb71e76c7fd added Python binding for material.h classes
Radek Brich <radek.brich@devl.cz>
parents: 94
diff changeset
   254
	ImageTexture(const TextureMap *tmap, const Pixmap *image):
81
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   255
		Texture2D(tmap), pixmap(image) {};
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   256
	Colour evaluate(const Vector &point)
81
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   257
	{
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   258
		Float u,v;
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   259
		map->map(point, u,v);
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   260
		u = u - 0.5f;
81
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   261
		u -= floor(u);
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   262
		v = -(v - 0.5f);
81
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   263
		v -= floor(v);
82
930a2d3ecaed prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents: 81
diff changeset
   264
		return pixmap->get((int)(u*pixmap->getWidth()), (int)(v*pixmap->getHeight()));
81
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   265
	};
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   266
};
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   267
9dbb9c8c115b add 2D pixmap texture class
Radek Brich <radek.brich@devl.cz>
parents: 80
diff changeset
   268
/**
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   269
 * 2D checkers texture
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   270
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   271
class CheckersTexture: public Texture2D
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   272
{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   273
	ColourMap *colourmap;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   274
public:
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   275
	CheckersTexture(TextureMap *tmap, ColourMap *cmap):
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   276
		Texture2D(tmap), colourmap(cmap) {};
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   277
	Colour evaluate(const Vector &point)
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   278
	{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   279
		Float u,v, val;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   280
		map->map(point, u,v);
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   281
		val = 0.5f*(floor(0.5f + u - floor(u)) + floor(0.5f + v - floor(v)));
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   282
		return colourmap->map(val);
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   283
	};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   284
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   285
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   286
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   287
 * 3D perlin cloud texture
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   288
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   289
class CloudTexture: public Texture
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   290
{
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   291
	ColourMap *colourmap;
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   292
	Float detail;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   293
public:
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   294
	CloudTexture(const Float &adetail, ColourMap *cmap):
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   295
		colourmap(cmap), detail(adetail) {};
91
9d66d323c354 packetize Phong shader
Radek Brich <radek.brich@devl.cz>
parents: 88
diff changeset
   296
	Colour evaluate(const Vector &point)
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   297
	{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   298
		Float sum = 0.0;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   299
		for (int i = 1; i < detail; i++)
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   300
			sum += fabs(perlin(point.x*i, point.y*i, point.z*i))/i;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   301
		//Float value = sinf(point.x + sum)/2 + 0.5;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   302
		return colourmap->map(sum);
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   303
	};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   304
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   305
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   306
/**
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   307
 * material
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   308
 */
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   309
class Material
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   310
{
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   311
public:
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   312
	Colour colour;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   313
	Texture *texture;
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   314
	Float ambient, diffuse, specular, shininess; // Phong constants
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   315
	Float reflectivity; // how much reflective is the surface
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   316
	Float transmissivity, refract_index; // part of light which can be refracted; index of refraction
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   317
	int smooth; // triangle smoothing
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   318
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   319
	Material(const Colour &acolour): colour(acolour), texture(NULL), smooth(false)
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   320
	{
92
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   321
		ambient = 0.2f;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   322
		diffuse = 0.8f;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   323
		specular = 0.2f;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   324
		shininess = 0.5f;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   325
		reflectivity = 0.2f;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   326
		transmissivity = 0.0f;
9af5c039b678 add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents: 91
diff changeset
   327
		refract_index = 1.3f;
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   328
	}
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   329
98
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   330
	/** set Phong parameters */
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   331
	void setPhong(const Float amb, const Float dif, const Float spec, const Float shin)
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   332
		{ ambient = amb; diffuse = dif; specular = spec; shininess = shin; };
98
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   333
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   334
	/** set fraction of light to be reflected */
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   335
	void setReflectivity(const Float refl) { reflectivity = refl; };
98
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   336
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   337
	/** set fraction of light to be refracted
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   338
	 * @param[in] trans  the transmissivity amount
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   339
	 * @param[in] rinde  index of refraction
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   340
	 */
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   341
	void setTransmissivity(const Float trans, const Float rindex)
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   342
		{ transmissivity = trans; refract_index = rindex; };
98
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   343
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   344
	/** allow triangle smoothing */
93
96d65f841791 more build script tuning
Radek Brich <radek.brich@devl.cz>
parents: 92
diff changeset
   345
	void setSmooth(int sm) { smooth = sm; };
98
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   346
64638385798a add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents: 96
diff changeset
   347
	/** set the texture */
80
907929fa9b59 remove forgotten noise.h includes
Radek Brich <radek.brich@devl.cz>
parents: 79
diff changeset
   348
	void setTexture(Texture *tex) { texture = tex; };
79
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   349
};
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   350
062b1c4143f7 material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   351
#endif