33

SA09 Realtime education

  • Upload
    sigtart

  • View
    659

  • Download
    1

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: SA09 Realtime education
Page 2: SA09 Realtime education

Claim back Shader to Softimage artist.

Try Real-time Shader for artist.

CSR&D Support Dept.

Artist

Fumoto Kazuhiro

Page 3: SA09 Realtime education

Summary

• Self-introduction

• The Advantage to the artist

• The Realtime-Shader to perform on Softimage

• Hurdles on learning Shader

– Shading

– NormalMap, EnvironmentMap

– Calculation for expression

• Goal>Result (to Cgfx)

Page 4: SA09 Realtime education

Self-introduction

• About CS R&D Support Dept.

– Graphic library development, Developmental

environment, Investigation and experiment of the next

generation graphic

• About me

Real-time graphic development.

In-house tool (such as plug-in) development and

support (mainly Softimage) for the artist.

→ Technical artist.

Page 5: SA09 Realtime education

An advantage to the artist.

• The adjustment of the Shader parameter is easy.

• WYSIWYG - You can see Game Graphics through data

making.

• You can get clear knowledge about shader.

Express higher graphic by learning about the shader

It doesn’t matter if you can’t write shader code

Page 6: SA09 Realtime education

Face Shader Demo…

• About Fake image based lighting, Fake sub surface

scattering…

Page 7: SA09 Realtime education

Simple IBL

• There are three hurdles to express this Shader.

Page 8: SA09 Realtime education

Hurdle1

• Dot (Inner) product

Page 9: SA09 Realtime education

Hurdle1

• Shading works out with the dot product of the normal

vector and the light vector.

• The expression…

N・L = cosθ

Shading : cosθ

Normar Vector : N

Light Vector : L

Page 10: SA09 Realtime education

Hurdle1

• For example…

The angle of the Normal Vector and the Light Vector is

60 degrees.

→Brightness is 0.5.

Page 11: SA09 Realtime education

Hurdle1

• In Cg Shader…

float dif1 = dot(normal, light);

• The dot() calculates the dot-product which is based on

the data in the parentheses.

• The data in the parenthesis are Normal Vectors and Light

Vectors.

• This expression says that the result which is calculated

by dot() is put in the variable is called dif1, and declares

float (few floating mark).

Page 12: SA09 Realtime education

Hurdle1 struct v2f { float4 hpos : HPOS; float4 color : COL0; }; v2f main ( float4 pos : POSITION, float4 nrml : NORMAL, uniform float4x4 simodelviewproj, uniform float4x4 simodelviewIT, uniform float4x4 simodelview, uniform float3 silightdirection_0 ) { v2f OUT; OUT.hpos = mul(simodelviewproj, pos); float3 normal = normalize(mul(simodelviewIT, nrml).xyz); float3 lDir1 = normalize(silightdirection_0); float dif1 = dot(normal, lDir1); if(dif1 < 0) dif1 = 0; float4 lColor1 = dif1; OUT.color = lColor1; return OUT; }

• Softimage samples.

Page 13: SA09 Realtime education

Hurdle1

{ v2f OUT; OUT.hpos = mul(simodelviewproj, pos); float3 normal = normalize(mul(simodelviewIT,

nrml).xyz); float3 lDir1 = normalize(silightdirection_0); float dif1 = dot(normal, lDir1); if(dif1 < 0) dif1 = 0; float4 lColor1 = dif1; OUT.color = lColor1; return OUT; }

• Softimage samples.

Page 14: SA09 Realtime education

Hurdle1

• Necessary matter

The dot() from two vector data is used to make

Shading.

Page 15: SA09 Realtime education

Hurdle1 Other examples…

• Relations of Vertex Shader and Fragment Shader

• Specular

– Blinn-Phong which uses the half vector.

– Phong which uses the reflection vector.

• Dot product applied use

– Using Eyes Vector in substitution for a light vector.

Page 16: SA09 Realtime education

Hurdle2

• Normal Map 1. Object space

2. Tangent space

• Environment map

Page 17: SA09 Realtime education

Hurdle2

• Normal map.

Page 18: SA09 Realtime education

Hurdle2

• Object space normal map.

The Object Space Normal Map directly uses RGB

brightness of texture as XYZ of Normal data.

• Actually, ( NormalTex – 0.5 ) × 2.

Page 19: SA09 Realtime education

Hurdle2

• Tangent space normal map.

• Need to obtain the Normal vector, Tangent vector,

Binormal vector.

• The value of the texture used as a normal data based

on that data.

Page 20: SA09 Realtime education

Hurdle2

• The kinds of Environment maps.

1. Simple Environment mapping (sphere)

2. Dual-Paraboloid mapping

3. Cube mapping

Page 21: SA09 Realtime education

Hurdle2

• Dual-Paraboloid Environment mapping

Uses two environment textures, each with a parabolic

basis (requires two texture images).

Page 22: SA09 Realtime education

Hurdle1

• In Cg Shaders… if (R.z < 0)

{

tc0.x = ( -(R.x / (2 * (1 - R.z))) + 0.5) * 0.5;

tc0.y = R.y / (2 * (1 - R.z)) + 0.5;

} else if (R.z >= 0)

{

tc0.x = (R.x / (2 * (1 + R.z)) + 0.5) * 0.5 + 0.5;

tc0.y = R.y / (2 * (1 + R.z)) + 0.5;

}

• R:RefrectVector

• Tc0.x:U to UV

• Tc0.y:V to UV

←Front

←Back

Page 23: SA09 Realtime education

Hurdle3

• Shader blending – Calculation technique to the result

– Blurring

Page 24: SA09 Realtime education

Hurdle3

• Calculation technique to the result

Add (+), Subtract (-), Mutiply (*), Divide (/)

Color data such as texture or shading which is for the

final graphic.

Shading × Texture + Flesnel (fake) ×Environmentmap

Page 25: SA09 Realtime education

Hurdle3

• Image Based Lighting (Fake)…

Page 26: SA09 Realtime education

Hurdle3

• Blurring of Texture.

• Program used for blurring a shadow map.

• Environmental map calculated as Specular

+ Environmental map calculated as Diffuse

= Image Based Lighting (Fake)

Page 27: SA09 Realtime education

Hurdle3

• Blur product.

Expert from

GPU Gems

float4 get_softtex(sampler2D map, float2 loc, int siz)

{

float x,y;

float4 sum = 0;

int scl;

float n, v;

float2 uv, texmapscale;

scl = 4;

v = 1.5f*scl;

n = 4.0f*scl;

texmapscale.x = 1.0f/512.0 * siz;

texmapscale.y = 1.0f/512.0 * siz;

for( y=-v ; y<=v ; y+=1.0f ){

for( x=-v; x<= v; x+=1.0f ){

uv.x = loc.x + x * texmapscale;

uv.y = loc.y + y * texmapscale;

sum += tex2D(map, uv);

}

}

sum = sum / (n*n);

sum.a = 1.0f;

return(sum);

}

set a parameter

here

Page 28: SA09 Realtime education

The First Goal

Page 29: SA09 Realtime education

An appendix

• Link of parameter and animation (DEMO1)

Page 30: SA09 Realtime education

An appendix

• Link of parameter and animation (DEMO2)

Page 31: SA09 Realtime education

Next step

• Shader effect file

CgFX, Dxfx…

Page 32: SA09 Realtime education

Document

Page 33: SA09 Realtime education

Q & A…

Thank you…

[email protected]