-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicCubePS.hlsl
More file actions
107 lines (85 loc) · 2.58 KB
/
DynamicCubePS.hlsl
File metadata and controls
107 lines (85 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Geometry Pass Pixel Shader
Texture2D diffuseTex : register(t0);
TextureCube cubeMap : register(t1);
SamplerState wrapSampler : register(s0);
SamplerState clampSampler : register(s1);
struct PixelInput
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD;
float3 normal : NORMAL;
float3 worldPos : WORLDPOS;
};
struct Pixeloutput
{
float4 position : sv_target0;
float3 normal : sv_target1;
float3 worldpos : sv_target2;
float4 diffuse : sv_target3;
float4 ambientmtl : sv_target4;
float4 diffusemtl : sv_target5;
float4 specularmtl : sv_target6;
float4 lightclippos : sv_target7;
};
cbuffer mtlData : register(b0)
{
float4 kA;
float4 kD;
float4 kS;
float4 reflectionColor;
float shine = 1; //shinyness
bool hasReflection = false;
bool isObj = true;
bool isTransparent = false;
bool canMove = false;
float textureIndex = 0;
float index = 0;
}
cbuffer LightMatrix : register(b1)
{
float4x4 lightMatrix;
}
cbuffer CAMERA : register(b2)
{
float3 cameraPosition;
}
//float4 main(PixelInput input) : SV_TARGET
//{
//
// // Interpolating normal can unnormalize it, so normalize it.
//
// // Compute vector from pixel position to eye.
// //float3 toEyeW = normalize(cameraPosition - input.position);
// /* float3 toEyeW = normalize(input.worldPos - cameraPosition);
// float3 reflectVec = reflect(toEyeW, normalize(input.normal));*/
// const float3 normalFrag = normalize(input.normal);
// const float3 camFrag = normalize(cameraPosition - input.worldPos);
//
// float3 vectorReflect = reflect(camFrag, normalFrag);
//
//
//
// // Sample texture
// float4 texColor = float4(cubeMap.Sample(wrapSampler, vectorReflect));
// texColor.w = 1; //force it
// return texColor;
//}
Pixeloutput main(PixelInput input)
{
Pixeloutput output;
const float3 normalFrag = normalize(input.normal.xyz);
const float3 camFrag = normalize(cameraPosition.xyz - input.worldPos.xyz);
float3 vectorReflect = reflect(camFrag, normalFrag);
// Sample texture
float4 texColor = float4(cubeMap.Sample(wrapSampler, vectorReflect));
//texColor.w = 1; //force it
output.position = input.position;
output.normal = input.normal;
output.worldpos = input.worldPos;
output.diffuse = texColor;
output.ambientmtl = 1.0f;
output.diffusemtl = kD;
output.specularmtl = kS;
output.lightclippos = mul(float4(output.worldpos, 1.0f), lightMatrix);
return output;
}