📄 material.h
字号:
/* Copyright (c) 2007 Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//** * material.h - blue-steel material class * @author Russel Ryan * * Contains the definition of the material structure for holding information related to shading an object * As this single class may represent any of a number of different shaders, the information in the structure * must be filled in as follows (matrix represents the transformation from global to shader coordinates): * * PHONG * arg1_i = exponent * arg1_f = indexOfRefraction * * COOKTORRANCE * arg1_f = indexOfRefraction * arg2_f = roughness * * CHECKERBOARD * colorDSRT_[r,g,b,a] <= matrix * arg1_i = mat1id * arg2_i = mat2id * * WOOD/MARBLE * colorDSRT_[r,g,b,a] <= matrix * arg1_f = frequency * arg2_f = amplitude * arg1_i = mat1id * arg2_i = mat2id * arg3_i = octaves * * NOISE * colorDSRT_[r,g,b,a] <= matrix * arg1_i = mat1id * arg2_i = mat2id * arg3_i = octaves * * BUMPY * arg1_i = sub-material * arg1_f = density * arg2_f = amplitude */#ifndef _MATERIAL_H_#define _MATERIAL_H_#include "common.h"#include "rgbpacket.h"#include "hitpacket.h"#include "raypacket.h"//Material Types#define MATERIAL_PHONG 0 //blinn-torrance#define MATERIAL_COOK_TORRANCE 1#define MATERIAL_CHECKERBOARD 2#define MATERIAL_MARBLE 3#define MATERIAL_WOOD 4#define MATERIAL_BUMP 5//remember to update this#define NUM_MATERIAL_TYPES 6struct material { unsigned char materialType; //allow for 4 color arguments //these 4 are diffuseColor, specularColor, reflectiveColor, and transparentColor in that order union { vector float colorDSRT_r; struct { float diffuse_r; float specular_r; float reflective_r; float transparent_r; }; }; union { vector float colorDSRT_g; struct { float diffuse_g; float specular_g; float reflective_g; float transparent_g; }; }; union { vector float colorDSRT_b; struct { float diffuse_b; float specular_b; float reflective_b; float transparent_b; }; }; union { vector float colorDSRT_a; //alpha blending channel for the hell of it struct { float diffuse_a; float specular_a; float reflective_a; float transparent_a; }; }; //only need 2 float args union { vector float argf_v; struct { float arg1_f; //index of refraction for BRDF, frequency for wood/marble float arg2_f; //roughness for cook torrance, amplitude for wood/marble float arg3_f; float arg4_f; }; }; //only need 3 int args union { vector signed int argi_v; struct { int arg1_i; //exponent for phong, mat1id for proc textures int arg2_i; //mat2id for proc textures int arg3_i; //octaves for noise int arg4_i; //unsigned char materialType, foo1, foo2, foo3; }; };} __attribute__((aligned(16)));//RGBPacket materialShade(const material &mat, const RayPacket &rp, const HitPacket &hp,// const vector float &dirToLight_x, const vector float &dirToLight_y, const vector float &dirToLight_z,// const vector float &lightColor_r, const vector float &lightColor_g, const vector float &lightColor_b,// const vector unsigned int &shadeBits)#define MATERIAL_SHADER(name) \ void name(material* materials, RGBPacket &rgbp, const RayPacket rp, const HitPacket hp, \ const vector float dirToLight_x, const vector float dirToLight_y, const vector float dirToLight_z, \ const vector float lightColor_r, const vector float lightColor_g, const vector float lightColor_b, \ const vector unsigned int shadeBits)#define MATERIAL_SHADER_FP(name) MATERIAL_SHADER((*name))//#define MATERIAL_SHADER_FP(name) \ // void (*name) (material *materials, RGBPacket &rgbp, const RayPacket &rp, const HitPacket &hp, \// const vector float &dirToLight_x, const vector float &dirToLight_y, const vector float &dirToLight_z, \// const vector float &lightColor_r, const vector float &lightColor_g, const vector float &lightColor_b, \// const vector unsigned int &shadeBits)MATERIAL_SHADER(materialShade); //the main shaderMATERIAL_SHADER(materialShadeDummy);MATERIAL_SHADER(material_BRDFStyleShade); //brdf-ish like phong and cooktorranceMATERIAL_SHADER(material_CheckerboardShade);MATERIAL_SHADER(material_BlenderShade);MATERIAL_SHADER(material_BumpShade);#define MATERIAL_SHADER_SPECULAR(name) \ void name(vector unsigned int materials, vector float &specularCoefficients, \ const vector float vx, const vector float vy, const vector float vz, \ const vector float hx, const vector float hy, const vector float hz, \ const vector float nx, const vector float ny, const vector float nz, \ const vector float NL_v, const vector unsigned int shadeBits)//float name(const material &mat, const vector float &v, const vector float &halfangle, const vector float &normal, const float &NL)#define MATERIAL_SHADER_SPECULAR_FP(name) MATERIAL_SHADER_SPECULAR((*name))MATERIAL_SHADER_SPECULAR(material_getSpecularCoefficientDummy);MATERIAL_SHADER_SPECULAR(material_getPhongSpecularCoefficient);MATERIAL_SHADER_SPECULAR(material_getCookTorranceSpecularCoefficient);#define MATERIAL_SHADER_BLENDFACTOR(name) \ void name(const vector unsigned int &materials, vector float &blendFactors, \ const vector float &p_x, const vector float &p_y, const vector float &p_z, const vector unsigned int shadeBits)#define MATERIAL_SHADER_BLENDFACTOR_FP(name) MATERIAL_SHADER_BLENDFACTOR((*name))MATERIAL_SHADER_BLENDFACTOR(material_getBlendFactorDummy);MATERIAL_SHADER_BLENDFACTOR(material_getMarbleBlendFactor);MATERIAL_SHADER_BLENDFACTOR(material_getWoodBlendFactor);#define MATERIAL_SHADER_DIFFUSE(name) \ void name(material *materials, RGBPacket &rgbp, const HitPacket hp, \ const vector float p_x, const vector float p_y, const vector float p_z, const vector unsigned int shadeBits)#define MATERIAL_SHADER_DIFFUSE_FP(name) MATERIAL_SHADER_DIFFUSE((*name))MATERIAL_SHADER_DIFFUSE(material_getDiffuseColor);MATERIAL_SHADER_DIFFUSE(material_getDiffuseColorDummy);MATERIAL_SHADER_DIFFUSE(material_getBRDFDiffuseColor);MATERIAL_SHADER_DIFFUSE(material_getCheckerboardDiffuseColor);MATERIAL_SHADER_DIFFUSE(material_getBlenderDiffuseColor);MATERIAL_SHADER_DIFFUSE(material_getBumpDiffuseColor);//#define MATERIAL_SHADER_DIFFUSE_FP(name) \// RGBPacket (*name)(material *materials, const HitPacket &hp);#define MATERIAL_SHADER_REFLECTIVE(name) \ void name(material *materials, RGBPacket &rgbp, const HitPacket hp, \ const vector float p_x, const vector float p_y, const vector float p_z, const vector unsigned int shadeBits)#define MATERIAL_SHADER_REFLECTIVE_FP(name) MATERIAL_SHADER_DIFFUSE((*name))MATERIAL_SHADER_REFLECTIVE(material_getReflectiveColor);MATERIAL_SHADER_REFLECTIVE(material_getReflectiveColorDummy);MATERIAL_SHADER_REFLECTIVE(material_getBRDFReflectiveColor);MATERIAL_SHADER_REFLECTIVE(material_getCheckerboardReflectiveColor);MATERIAL_SHADER_REFLECTIVE(material_getBlenderReflectiveColor);MATERIAL_SHADER_REFLECTIVE(material_getBumpReflectiveColor);#define MATERIAL_SHADER_TRANSPARENT(name) \ void name(material *materials, RGBPacket &rgbp, const HitPacket &hp, \ const vector float &p_x, const vector float &p_y, const vector float &p_z, const vector unsigned int shadeBits)#define MATERIAL_SHADER_TRANSPARENT_FP(name) MATERIAL_SHADER_TRANSPARENT((*name))MATERIAL_SHADER_TRANSPARENT(material_getTransparentColor);MATERIAL_SHADER_TRANSPARENT(material_getTransparentColorDummy);MATERIAL_SHADER_TRANSPARENT(material_getBRDFTransparentColor);MATERIAL_SHADER_TRANSPARENT(material_getCheckerboardTransparentColor);MATERIAL_SHADER_TRANSPARENT(material_getBlenderTransparentColor);MATERIAL_SHADER_TRANSPARENT(material_getBumpTransparentColor);#define MATERIAL_SHADER_REFRACTIVE(name) \ void name(material *materials, vector float &rindices, const HitPacket hp, \ const vector float p_x, const vector float p_y, const vector float p_z, const vector unsigned int shadeBits)#define MATERIAL_SHADER_REFRACTIVE_FP(name) MATERIAL_SHADER_REFRACTIVE((*name))MATERIAL_SHADER_REFRACTIVE(material_getRefractiveIndex);MATERIAL_SHADER_REFRACTIVE(material_getRefractiveIndexDummy);MATERIAL_SHADER_REFRACTIVE(material_getBRDFRefractiveIndex);MATERIAL_SHADER_REFRACTIVE(material_getCheckerboardRefractiveIndex);MATERIAL_SHADER_REFRACTIVE(material_getBlenderRefractiveIndex);MATERIAL_SHADER_REFRACTIVE(material_getBumpRefractiveIndex);//BUMPMAP UTILITY FUNCTIONvoid material_bumpNormal(material* materials, HitPacket &hp, const vector float p_x, const vector float p_y, const vector float p_z, const vector unsigned int shadeBits);typedef MATERIAL_SHADER_FP(material_shader);typedef MATERIAL_SHADER_SPECULAR_FP(material_shader_specular);typedef MATERIAL_SHADER_BLENDFACTOR_FP(material_shader_blendfactor);typedef MATERIAL_SHADER_DIFFUSE_FP(material_shader_diffuse);typedef MATERIAL_SHADER_REFLECTIVE_FP(material_shader_reflective);typedef MATERIAL_SHADER_TRANSPARENT_FP(material_shader_transparent);typedef MATERIAL_SHADER_REFRACTIVE_FP(material_shader_refractive);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -