struct VertexData{ float4 position:POSITION; float4 texcoord:TEXCOORD0; float4 normal:NORMAL; float4 tangent:TANGENT; }; struct VSOut{ float4 position:SV_POSITION; float4 normal:NORMAL; float4 texcoord:TEXCOORD0; }; static const float PI=3.141592; cbuffer globalConstants:register(b0){ float4 misc; }; Texture2D T_DiffuseTexture:register(t0); SamplerState samplerState:register(s0); struct MaterialData{ float r; }; StructuredBuffer materialData:register(t0,space1); cbuffer DefaultVertexCB:register(b1){ float4x4 ProjectionMatrix; float4x4 ViewMatrix; float4x4 ModelMatrix; float4x4 IT_ModelMatrix; float4x4 ReservedMemory[1020]; }; VSOut MainVS(VertexData inVertexData){ VSOut vo; vo.normal=mul(IT_ModelMatrix,inVertexData.normal); float4 positionWS=mul(ModelMatrix,inVertexData.position); float4 positionVS=mul(ViewMatrix,positionWS); vo.position=mul(ProjectionMatrix,positionVS); //vo.position=float4(positionWS.xyz+vo.normal.xyz*sin(misc.x)*0.2f,1.0f); vo.texcoord=inVertexData.texcoord; return vo; } [maxvertexcount(4)] void MainGS(triangle VSOut inPoint[3],uint inPrimitiveID:SV_PrimitiveID, inout TriangleStream outTriangleStream){ outTriangleStream.Append(inPoint[0]); outTriangleStream.Append(inPoint[1]); outTriangleStream.Append(inPoint[2]); /*VSOut vo; float3 positionWS=inPoint[0].position.xyz; float3 N=normalize(inPoint[0].normal.xyz); vo.normal=float4(N,0.0f); float3 helperVec=abs(N.y)>0.999?float3(0.0f,0.0f,1.0f):float3(0.0f,1.0f,0.0f); float3 tangent=normalize(cross(N,helperVec));//u float3 bitangent=normalize(cross(tangent,N));//v float scale=materialData[inPrimitiveID].r; float3 p0WS=positionWS-(bitangent*0.5f-tangent*0.5f)*scale;//left bottom float4 p0VS=mul(ViewMatrix,float4(p0WS,1.0f)); vo.position=mul(ProjectionMatrix,p0VS); vo.texcoord=float4(0.0f,1.0f,0.0f,0.0f); outTriangleStream.Append(vo); float3 p1WS=positionWS-(bitangent*0.5f+tangent*0.5f)*scale;//right bottom float4 p1VS=mul(ViewMatrix,float4(p1WS,1.0f)); vo.position=mul(ProjectionMatrix,p1VS); vo.texcoord=float4(1.0f,1.0f,0.0f,0.0f); outTriangleStream.Append(vo); float3 p2WS=positionWS+(bitangent*0.5f+tangent*0.5f)*scale;//left top float4 p2VS=mul(ViewMatrix,float4(p2WS,1.0f)); vo.position=mul(ProjectionMatrix,p2VS); vo.texcoord=float4(0.0f,0.0f,0.0f,0.0f); outTriangleStream.Append(vo); float3 p3WS=positionWS+(bitangent*0.5f-tangent*0.5f)*scale;//right top float4 p3VS=mul(ViewMatrix,float4(p3WS,1.0f)); vo.position=mul(ProjectionMatrix,p3VS); vo.texcoord=float4(1.0f,0.0f,0.0f,0.0f); outTriangleStream.Append(vo);*/ } float4 MainPS(VSOut inPSInput):SV_TARGET{ float3 N=normalize(inPSInput.normal.xyz); float3 bottomColor=float3(0.1f,0.4f,0.6f); float3 topColor=float3(0.7f,0.7f,0.7f); float theta=asin(N.y);//-PI/2 ~ PI/2 theta/=PI;//-0.5~0.5 theta+=0.5f;//0.0~1.0 float ambientColorIntensity=1.0; float3 ambientColor=lerp(bottomColor,topColor,theta)*ambientColorIntensity; float4 diffuseColor=T_DiffuseTexture.Sample(samplerState,inPSInput.texcoord.xy); float3 surfaceColor=diffuseColor.rgb; return float4(surfaceColor,1.0f); }