Vous êtes sur la page 1sur 50
CS 4204 Computer Graphics OOpenpenGLGL ShShaadidingng LLanguageanguage YongYong CaoCao VirVirgginiainia TechTech
CS 4204 Computer Graphics
OOpenpenGLGL ShShaadidingng LLanguageanguage
YongYong CaoCao
VirVirgginiainia TechTech
Reference: Ed Angle, Interactive Computer Graphics, University of New Mexico, class notes
Objectives •• ShaderShader applicationsapplications •• •• VertexVertex shadersshaders FragmentFragment
Objectives
•• ShaderShader applicationsapplications
••
••
VertexVertex shadersshaders
FragmentFragment shadersshaders
•• ProgrammingProgramming shadersshaders
••
CgCg
•• GLSLGLSL
Vertex Shader Applications •• MovingMoving verticesvertices •• MorphingMorphing WaveWave motionmotion ••
Vertex Shader Applications
•• MovingMoving verticesvertices
•• MorphingMorphing
WaveWave motionmotion
•• FractalsFractals
••
•• LightingLighting
•• MoreMore realisticrealistic modelsmodels
•• CartoonCartoon shadersshaders
Fragment Shader Applications PerPer fragmentfragment lightinglighting calculationscalculations per vertex lighting per
Fragment Shader Applications
PerPer fragmentfragment lightinglighting calculationscalculations
per vertex lighting
per fragment lighting
Fragment Shader Applications TextureTextureTextureTexture mappingmappingmappingmapping smooth shading environment bump
Fragment Shader Applications
TextureTextureTextureTexture mappingmappingmappingmapping
smooth shading
environment
bump mapping
mapping
Writing Shaders •• FirstFirst pproroggrammablerammable shadersshaders werewere pproroggrammedrammed inin anan
Writing Shaders
••
FirstFirst pproroggrammablerammable shadersshaders werewere pproroggrammedrammed inin anan
assemblyassembly--likelike mannermanner
••
OpenGLOpenGL extensionsextensions addedadded forfor vertexvertex andand fragmentfragment
shadersshaders
••
CgCg (C(C forfor graphics)graphics) CC--likelike languagelanguage forfor programmingprogramming
shadersshaders
••
••
WorksWorks withwith bothboth OpenGLOpenGL andand DirectXDirectX
InterfaceInterface toto OpenGLOpenGL complexcomplex
••
OOppenGLenGL ShadinShadingg LanLangguauaggee ((GLSLGLSL))
GLSL •• •• •• •• OpenGLOpenGL ShadingShading LanguageLanguage PartPart ofof OpenGLOpenGL 2.02.0
GLSL
••
••
••
••
OpenGLOpenGL ShadingShading LanguageLanguage
PartPart ofof OpenGLOpenGL 2.02.0
HighHigh levellevel CC--likelike languagelanguage
NewNew datadata typestypes
••
MatricesMatrices
••
VectorsVectors
••
SamplersSamplers
••
OpenGLOpenGL statestate availableavailable throughthrough builtbuilt--inin variablesvariables
Simple Vertex Shader constconst vec4vec4 redred == vec4(1vec4(1 voidvoid main(void)main(void) {{ 00,, 00 00,, 00
Simple Vertex Shader
constconst vec4vec4 redred == vec4(1vec4(1
voidvoid main(void)main(void)
{{
00,,
00
00,,
00
00,,
11
0)0);;
gl_Positiongl_Position == gl_ProjectionMatrixgl_ProjectionMatrix
**gl_ModelViewMartrixgl_ModelViewMartrix**gl_Vertexgl_Vertex;;
gl_FrontColorgl_FrontColor == red;red;
}}
Execution Model
Execution Model
Simple Fragment Program voidvoid main(void)main(void) voidvoid main(void)main(void) {{ {{
Simple Fragment Program
voidvoid main(void)main(void)
voidvoid main(void)main(void)
{{ {{
gl_FragColorgl_FragColorgl_FragColorgl_FragColor ==== gl_FrontColor;gl_FrontColor;gl_FrontColor;gl_FrontColor;
}}}}
1
Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005
0
Execution Model 1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 1
Execution Model
1
Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005
1
Data Types •• •• CC types:types: intint,, floatfloat,, boolbool Vectors:Vectors: •• •• floatfloat
Data Types
••
••
CC types:types: intint,, floatfloat,, boolbool
Vectors:Vectors:
••
••
floatfloat vec2vec2,, vecvec 33,, vec4vec4
AlsoAlso intint ((ivecivec)) andand booleanboolean ((bvecbvec))
••
Matrices:Matrices: mat2,mat2, mat3,mat3, mat4mat4
••
••
StoredStored byby columnscolumns
StandardStandard referencingreferencing m[row][column]m[row][column]
••
C++C++ stylestyle constructorsconstructors
••
••
vec3vec3 aa =vec3(1.0,=vec3(1.0, 2.0,2.0, 3.0)3.0)
vec2vec2 bb == vec2(a)vec2(a)
Pointers •• ThereThere areare nono ppointersointers inin GLSLGLSL •• WeWe cancan useuse CC structsstructs
Pointers
••
ThereThere areare nono ppointersointers inin GLSLGLSL
••
WeWe cancan useuse CC structsstructs whichwhich cancan bebe copiedcopied backback fromfrom
functionsfunctions
••
BecauseBecause matricesmatrices andand vectorsvectors areare basicbasic typestypes theythey cancan
bebe passedpassed intointo andand outputoutput fromfrom GLSLGLSL functionsfunctions,, e.g.e.g.
matrix3matrix3 funcfunc(matrix3(matrix3 a)a)
Qualifiers •• GLSLGLSL hashas manymany ofof thethe samesame qualifiersqualifiers suchsuch asas constconst asas
Qualifiers
••
GLSLGLSL hashas manymany ofof thethe samesame qualifiersqualifiers suchsuch asas constconst
asas C/C++C/C++
••
NeedNeed othersothers duedue toto thethe naturenature ofof thethe executionexecution modelmodel
••
VariablesVariables cancan changechange
••
••
••
••
OnceOnce perper primitiveprimitive
OnceOnce perper vertexvertex
OnceOnce perper fragmentfragment
AtAt anyany timetime inin thethe applicationapplication
••
VertexVertex attributesattributes areare interpolatedinterpolated byby thethe rasterizerrasterizer intointo
fragmentfragment attributesattributes
Attribute Qualifier •• AttributeAttribute--qqualifiedualified variablesvariables cancan chanchanggee atat mostmost
Attribute Qualifier
••
AttributeAttribute--qqualifiedualified variablesvariables cancan chanchanggee atat mostmost onceonce
perper vertexvertex
••
CannotCannot bebe usedused inin frafraggmentment shadersshaders
••
BuiltBuilt inin (OpenGL(OpenGL statestate variables)variables)
•• ggll ColorColor
•• gl_ModelViewMatrixgl_ModelViewMatrix
••
UUserser ddeefifinenedd ((iinn appapplilicatcatiionon program)program)
•• attributeattribute floatfloat temperaturetemperature
•• attributeattribute vec3vec3 velocityvelocity
Uniform Qualified •• VVarariiaablbleses ththaatt areare consconsttanantt fforor anan enentitirere primitiveprimitive
Uniform Qualified
•• VVarariiaablbleses ththaatt areare consconsttanantt fforor anan enentitirere
primitiveprimitive
•• CCanan bbee cchhangeangedd iinn appapplilicacatitionon ououttssididee scopescope ooff
glBeginglBegin andand glEndglEnd
•• CannotCannot bebe changedchanged inin shadershader
•• UsedUsed toto ppassass informationinformation toto shadershader suchsuch asas thethe
boundingbounding boxbox ofof aa primitiveprimitive
Varying Qualified •• VariablesVariables thatthat areare ppassedassed fromfrom vertexvertex shadershader toto
Varying Qualified
••
VariablesVariables thatthat areare ppassedassed fromfrom vertexvertex shadershader toto
fragmentfragment shadershader
••
AutomaticallyAutomatically interpolatedinterpolated byby thethe rasterizerrasterizer
••
BuiltBuilt inin
••
••
VertexVertex colorscolors
TextureTexture coordinatescoordinates
••
UUserser ddeefifinenedd
••
RequiresRequires aa useruser defineddefined fragmentfragment shadershader
Example: Vertex Shader constconst vec4vec4 redred == vec4(1vec4(1 varyingvarying vec3vec3 color_out;color_out; vovoidid
Example: Vertex Shader
constconst vec4vec4 redred == vec4(1vec4(1
varyingvarying vec3vec3 color_out;color_out;
vovoidid mamaiinn((vovoid)id)
{{
00,,
00
00,,
00
00,,
11
0)0);;
gl_Positiongl_Position ==
gl_ModelViewProjectionMatrixgl_ModelViewProjectionMatrix**gl_Vertexgl_Vertex;;
color_outcolor_out == red;red;
}}
Required Fragment Shader varvaryyiningg vec3vec3 colorcolor voidvoid main(void)main(void) {{ outout;;
Required Fragment Shader
varvaryyiningg vec3vec3 colorcolor
voidvoid main(void)main(void)
{{
outout;;
gl_FragColorgl_FragColor == color_outcolor_out;;
}}
Passing values •• •• •• •• callcall bbyy valuevalue--returnreturn VariablesVariables areare
Passing values
••
••
••
••
callcall bbyy valuevalue--returnreturn
VariablesVariables areare copiedcopied inin
RReetturneurnedd vavalluesues areare copcopiieedd bbacackk
ThreeThree possibilitiespossibilities
••
inin
••
outout
••
inoutinout
Operators and Functions •• StandardStandard CC functionsfunctions •• •• ••
Operators and Functions
••
StandardStandard CC functionsfunctions
••
••
••
TrigonometricTrigonometric
AArrithithmemetiticc
Normalize,Normalize, reflect,reflect, lengthlength
••
OverloadingOverloading ofof vectorvector andand matrixmatrix typestypes
mat4mat4 a;a;
vecvec44 bb,, c,c, dd;;
cc == b*a;b*a; //// aa columncolumn vectorvector storedstored asas aa 1d1d arrayarray
dd == aa**bb;; //// aa roroww vvectorector storedstored asas aa 1d1d arraarrayy
Swizzling and Selection •• CanCan referrefer toto arrayarray elementselements byby elementelement usingusing [][]
Swizzling and Selection
••
CanCan referrefer toto arrayarray elementselements byby elementelement usingusing [][] oror
selectionselection (.)(.) operatoroperator withwith
••
••
••
x,x, y,y, z,z, ww
r,r, g,g, b,b, aa
s,s, t,t, p,p, qq
•• a[2]a[2],, aa
bb,,
aa
zz,,
aa
pp
areare thethe samesame
••
SwizzlingSwizzling operatoroperator letslets usus manipulatemanipulate componentscomponents
vec4vec4 a;a;
a.yza.yz == vec2(1.0,vec2(1.0, 2.0);2.0);
Objectives •• CouplingCoupling GLSLGLSL toto ApplicationsApplications •• ExampleExample applicationsapplications
Objectives
•• CouplingCoupling GLSLGLSL toto ApplicationsApplications
•• ExampleExample applicationsapplications
Linking Shaders to OpenGL •• OpenGLOpenGL ExtensionsExtensions (With(With GLEWGLEW library)library) ••
Linking Shaders to OpenGL
•• OpenGLOpenGL ExtensionsExtensions (With(With GLEWGLEW library)library)
•• ARB_shader_objectsARB_shader_objects
•• ARB_vertex_shaderARB_vertex_shader
•• AARBRB
frafraggmentment
shadeshaderr
•• OpenGLOpenGL 2.02.0
••
AAlmostlmost identicalidentical toto usingusing extensionsextensions
•• AvoidsAvoids extensionextension suffixessuffixes onon functionfunction namesnames
Program Object •• CCononttaaiinerner fforor sshhaaddersers •• •• CanCan containcontain multiplemultiple
Program Object
•• CCononttaaiinerner fforor sshhaaddersers
••
••
CanCan containcontain multiplemultiple shadersshaders
OtherOther GLSLGLSL functionsfunctions
GLuint myProgObj;
myProgObj = glCreateProgram();
/* define shader objects here */
glUseProgram(myProgObj);
glLinkProgram(myProgObj);
Reading a Shader •• ShShaadderer areare aaddddeedd ttoo ththee programprogram oobbjecjectt anandd compiledcompiled
Reading a Shader
•• ShShaadderer areare aaddddeedd ttoo ththee programprogram oobbjecjectt anandd
compiledcompiled
•• UUsuasuall memeththoodd ooff passpassiingng aa sshhaadderer iiss asas aa nunullll--
terminatedterminated stringstring usingusing thethe functionfunction
gglShlShaaddererSSourcourcee
•• IfIf thethe shadershader isis inin aa file,file, wewe cancan writewrite aa readerreader toto
convertconvert thethe filefile toto aa strinstringg
Shader Reader char* readShaderSource(const char* shaderFile) { struct stat statBuf; FILE* fp = fopen(shaderFile,
Shader Reader
char* readShaderSource(const char* shaderFile)
{
struct stat statBuf;
FILE* fp = fopen(shaderFile, "r");
char* buf;
stat(shaderFile, &statBuf);
buf = (char*) malloc(statBuf.st_size + 1 * sizeof(char));
fread(buf, 1, statBuf.st_size, fp);
buf[statBuf.st_size] = '\0';
fclose(fp);
return buf;
}
Adding a Vertex Shader GLint vShader; GLunit myVertexObj; GLchar vShaderfile[] = “my_vertex_shader”; GLchar*
Adding a Vertex Shader
GLint vShader;
GLunit myVertexObj;
GLchar vShaderfile[] = “my_vertex_shader”;
GLchar* vSource =
readShaderSource(vShaderFile);
glShaderSource(myVertexObj,
1, &vertexShaderFile, NULL);
myVertexObj =
glCreateShader(GL_VERTEX_SHADER);
glCompileShader(myVertexObj);
glAttachObject(myProgObj, myVertexObj);
Vertex Attributes •• VVererttexex aattttrribibuutteses areare namenamedd iinn ththee sshhaaddersers ••
Vertex Attributes
•• VVererttexex aattttrribibuutteses areare namenamedd iinn ththee sshhaaddersers
•• LinkerLinker formsforms aa tabletable
•• ApplicationApplication cancan getget indexindex fromfrom tabletable andand tietie itit
toto anan applicationapplication variablevariable
•• SimilarSimilar processprocess forfor uniformuniform variablesvariables
Vertex Attribute Example GLint colorAttr; colorAttr = glGetAttribLocation(myProgObj, "myColor"); /* myColor is
Vertex Attribute Example
GLint colorAttr;
colorAttr = glGetAttribLocation(myProgObj,
"myColor");
/* myColor is name in shader */
GLfloat color[4];
glVertexAttrib4fv(colorAttrib, color);
/* color is variable in application */
Uniform Variable Example GLint angleParam; angleParam = glGetUniformLocation(myProgObj, "angle"); /* angle
Uniform Variable Example
GLint angleParam;
angleParam = glGetUniformLocation(myProgObj,
"angle");
/* angle defined in shader */
/* my_angle set in application */
GLfloat my_angle;
my_angle = 5.0 /* or some other value */
glUniform1f(myProgObj, angleParam, my_angle);
Vertex Shader Applications •• MovingMoving verticesvertices •• MorphingMorphing WaveWave motionmotion ••
Vertex Shader Applications
•• MovingMoving verticesvertices
•• MorphingMorphing
WaveWave motionmotion
•• FractalsFractals
••
•• LightingLighting
•• MoreMore realisticrealistic modelsmodels
•• CartoonCartoon shadersshaders
Wave Motion Vertex Shader uniform float time; uniform float xs, zs; void main() { float
Wave Motion Vertex Shader
uniform float time;
uniform float xs, zs;
void main()
{
float s;
s = 1.0 + 0.1*sin(xs*time)*sin(zs*time);
gl_Vertex.y = s*gl_Vertex.y;
gl_Position =
gl_ModelViewProjectionMatrix*gl_Vertex;
}
Particle System uniform vec3 init_vel; uniform float g, m, t; void main() { vec3 object_pos;
Particle System
uniform vec3 init_vel;
uniform float g, m, t;
void main()
{
vec3 object_pos;
object_pos.x = gl_Vertex.x + vel.x*t;
object_pos.y = gl_Vertex.y + vel.y*t
+ g/(2.0*m)*t*t;
object_pos.z = gl_Vertex.z + vel.z*t;
gl_Position =
gl_ModelViewProjectionMatrix*
vec4(object_pos,1);
}
Modified Phong Vertex Shader I void main(void) /* modified Phong vertex shader (without distance term)
Modified Phong Vertex Shader I
void main(void)
/* modified Phong vertex shader (without distance term) */
{
float f;
/* compute normalized normal, light vector, view vector,
half-angle vector in eye cordinates */
vec3 norm = normalize(gl_NormalMatrix*gl_Normal);
vec3 lightv = normalize(gl_LightSource[0].position
-gl_ModelViewMatrix*gl_Vertex);
vec3 viewv = -normalize(gl_ModelViewMatrix*gl_Vertex);
vec3 halfv = normalize(lightv + norm);
if(dot(lightv, norm) > 0.0) f = 1.0;
else f = 0.0;
Modified Phong Vertex Shader II /* compute diffuse, ambient, and specular contributions */ vec4 diffuse
Modified Phong Vertex Shader II
/* compute diffuse, ambient, and specular contributions */
vec4 diffuse = max(0, dot(lightv, norm))*gl_FrontMaterial.diffuse
*LightSource[0].diffuse;
vec4 ambient = gl_FrontMaterial.ambient*LightSource[0].ambient;
vec4 specular = f*gl_FrontMaterial.specular*
gl_LightSource[0].specular)
*pow(max(0, dot( norm, halfv)), gl_FrontMaterial.shininess);
vec3 color = vec3(ambient + diffuse + specular)
gl_FrontColor = vec4(color, 1);
gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
}
Pass Through Fragment Shader /* pass-through fragment shader */ void main(void) { gl_FragColor = gl_FrontColor;
Pass Through Fragment Shader
/* pass-through fragment shader */
void main(void)
{
gl_FragColor = gl_FrontColor;
}
Vertex Shader for per Fragment Lighting /* vertex shader for per-fragment Phong shading */ varying
Vertex Shader for per Fragment
Lighting
/* vertex shader for per-fragment Phong shading */
varying vec3 normale;;
varying vec4 positione;
void main()
{
normale = gl_NormalMatrixMatrix*gl_Normal;
positione = gl_ModelViewMatrix*gl_Vertex;
gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
}
Fragment Shader for Modified Phong Lighting I varying vec3 normale; varying vec4 positione; void main()
Fragment Shader for Modified
Phong Lighting I
varying vec3 normale;
varying vec4 positione;
void main()
{
vec3 norm = normalize(normale);
vec3 lightv = normalize(gl_LightSource[0].position-positione.xyz);
vec3 viewv = normalize(positione);
vec3 halfv = normalize(lightv + viewv);
vec4 diffuse = max(0, dot(lightv, viewv))
*gl_FrontMaterial.diffuse*gl_LightSource[0].diffuse;
vec4 ambient = gl_FrontMaterial.ambient*gl_LightSource[0].ambient;
Fragment Shader for Modified Phong Lighting II int f; if(dot(lightv, viewv)> 0.0) f =1.0); else
Fragment Shader for Modified Phong
Lighting II
int f;
if(dot(lightv, viewv)> 0.0) f =1.0);
else f = 0.0;
vec3 specular = f*pow(max(0, dot(norm, halfv),
gl_FrontMaterial.shininess)
*gl_FrontMaterial.specular*gl_LightSource[0].specular);
vec3 color = vec3(ambient + diffuse + specular);
gl_FragColor = vec4(color, 1.0);
}
Vertex vs Fragment Shader per vertex lighting per fragment lighting
Vertex vs Fragment Shader
per vertex lighting
per fragment lighting
Samplers •• ProvidesProvides accessaccess toto aa texturetexture objectobject •• DefinedDefined forfor 1,1,
Samplers
••
ProvidesProvides accessaccess toto aa texturetexture objectobject
••
DefinedDefined forfor 1,1, 2,2, andand 33 dimensionaldimensional texturestextures andand forfor
cubecube mapsmaps
••
InIn shadershader::
uniformuniform sampler2Dsampler2D myTexturemyTexture;;
Vec2Vec2 texcoordtexcoord;;
Vec4Vec4 texcolortexcolor == texture2Dtexture2D((mytexturemytexture,, ttexcoordexcoord));;
••
InIn application:application:
texMatexMappLocationLocation ==
glGetUniformLocationglGetUniformLocation((myProg,“myTexturemyProg,“myTexture”);”);
glUniform1i(glUniform1i(texMapLocationtexMapLocation,, 0);0);
//** assignsassigns toto texturetexture unitunit 00 **//
Fragment Shader Applications TextureTexture mappingmapping smooth shading environment bump mapping mapping
Fragment Shader Applications
TextureTexture mappingmapping
smooth shading
environment
bump mapping
mapping
Cube Maps •• WWee cancan fformorm aa cucubbee mapmap ttexexttureure bbyy ddeefifinniingng ssiixx 2D2D texturetexture
Cube Maps
•• WWee cancan fformorm aa cucubbee mapmap ttexexttureure bbyy ddeefifinniingng ssiixx
2D2D texturetexture mapsmaps thatthat correspondcorrespond toto thethe sidessides ofof
aa boxbox
•• SupportedSupported byby OpenGLOpenGL
•• AlsoAlso supportedsupported inin GLSLGLSL throughthrough cubemapcubemap
samplersampler
vec4vec4 texColortexColor == textureCubetextureCube((mycubemycube,, texcoord);texcoord);
•• TextureTexture coordinatescoordinates mustmust bebe 3D3D
Environment Map UseUse reflectionreflection vectorvector toto locatelocate texturetexture inin cubecube mapmap
Environment Map
UseUse reflectionreflection vectorvector toto locatelocate texturetexture inin
cubecube mapmap
Environment Maps with Shaders •• EEnvnviironmenronmentt mapmap usuausuallllyy compucomputteedd iinn worworldld
Environment Maps with Shaders
•• EEnvnviironmenronmentt mapmap usuausuallllyy compucomputteedd iinn worworldld
coordinatescoordinates whichwhich cancan differdiffer fromfrom objectobject
coordinatescoordinates becausebecause ofof modelinmodelingg matrixmatrix
••
MayMay havehave toto keepkeep tracktrack ofof modelingmodeling matrixmatrix andand passpass itit
shadershader asas aa uniformuniform variablevariable
•• CanCan alsoalso useuse reflectionreflection mapmap oror refractionrefraction mapmap
(for(for exampleexample toto simulatesimulate water)water)
Environment Map Vertex Shader uniform mat4 modelMat; uniform mat3 invModelMat; uniform vec4 eyew; void main(void)
Environment Map Vertex Shader
uniform mat4 modelMat;
uniform mat3 invModelMat;
uniform vec4 eyew;
void main(void)
{
vec4 positionw = modelMat*gl_Vertex;
vec3 normw = normalize(gl_Normal*invModelMat.xyz);
vec3 lightw = normalize(eyew.xyz-positionw.xyz);
eyew = reflect(normw, eyew);
gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
}
Environment Map Fragment Shader /* fragment shader for reflection map */ varying vec3 reflectw; uniform
Environment Map Fragment Shader
/* fragment shader for reflection map */
varying vec3 reflectw;
uniform samplerCube MyMap;
void main(void)
{
gl_FragColor = textureCube(myMap, reflectw);
}
Bump Mapping •• PerturbPerturb normalnormal forfor eacheach fragmentfragment •• StoreStore
Bump Mapping
•• PerturbPerturb normalnormal forfor eacheach fragmentfragment
•• StoreStore perturbationperturbation asas texturestextures
Normalization Maps •• CCuubbee mapsmaps cancan bbee vviieweewedd asas llooookkupup ttaablbleses 11--44
Normalization Maps
•• CCuubbee mapsmaps cancan bbee vviieweewedd asas llooookkupup ttaablbleses 11--44
dimensionaldimensional variablesvariables
•• VVececttoror ffromrom ororiiggiinn iiss popoiinntterer iinnttoo ttaablblee
•• Example:Example: storestore normalizednormalized valuevalue ofof vectorvector inin
thethe mapmap
••
••
••
SameSame forfor allall pointspoints onon thatthat vectorvector
UseUse “normalization“normalization map”map” insteadinstead ofof normalizationnormalization functionfunction
LookuLookupp rerepplaceslaces ssqqrtrt,, multsmults andand addsadds