mirror of
https://github.com/microsoft/DirectXTex.git
synced 2026-02-09 14:26:12 +01:00
Started texenvmap tool
This commit is contained in:
49
Texenvmap/Shaders/CompileShaders.cmd
Normal file
49
Texenvmap/Shaders/CompileShaders.cmd
Normal file
@@ -0,0 +1,49 @@
|
||||
@echo off
|
||||
rem Copyright (c) Microsoft Corporation.
|
||||
rem Licensed under the MIT License.
|
||||
|
||||
setlocal
|
||||
set error=0
|
||||
|
||||
if %PROCESSOR_ARCHITECTURE%.==ARM64. (set FXCARCH=arm64) else (if %PROCESSOR_ARCHITECTURE%.==AMD64. (set FXCARCH=x64) else (set FXCARCH=x86))
|
||||
|
||||
set FXCOPTS=/nologo /WX /Ges /Zi /Zpc /Qstrip_reflect /Qstrip_debug
|
||||
|
||||
set PCFXC="%WindowsSdkVerBinPath%%FXCARCH%\fxc.exe"
|
||||
if exist %PCFXC% goto continue
|
||||
set PCFXC="%WindowsSdkBinPath%%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
|
||||
if exist %PCFXC% goto continue
|
||||
set PCFXC="%WindowsSdkDir%bin\%WindowsSDKVersion%\%FXCARCH%\fxc.exe"
|
||||
if exist %PCFXC% goto continue
|
||||
|
||||
set PCFXC=fxc.exe
|
||||
|
||||
:continue
|
||||
if not defined CompileShadersOutput set CompileShadersOutput=Compiled
|
||||
set StrTrim=%CompileShadersOutput%##
|
||||
set StrTrim=%StrTrim: ##=%
|
||||
set CompileShadersOutput=%StrTrim:##=%
|
||||
@if not exist "%CompileShadersOutput%" mkdir "%CompileShadersOutput%"
|
||||
call :CompileShader Texenvmap vs VSBasic
|
||||
|
||||
call :CompileShader Texenvmap ps PSBasic
|
||||
call :CompileShader Texenvmap ps PSEquiRect
|
||||
|
||||
echo.
|
||||
|
||||
if %error% == 0 (
|
||||
echo Shaders compiled ok
|
||||
) else (
|
||||
echo There were shader compilation errors!
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
endlocal
|
||||
exit /b 0
|
||||
|
||||
:CompileShader
|
||||
set fxc=%PCFXC% %1.fx %FXCOPTS% /T%2_4_0 /E%3 /Fh%CompileShadersOutput%\%1_%3.inc /Fd%CompileShadersOutput%\%1_%3.pdb /Vn%1_%3
|
||||
echo.
|
||||
echo %fxc%
|
||||
%fxc% || set error=1
|
||||
exit /b
|
||||
65
Texenvmap/Shaders/Texenvmap.fx
Normal file
65
Texenvmap/Shaders/Texenvmap.fx
Normal file
@@ -0,0 +1,65 @@
|
||||
//--------------------------------------------------------------------------------------
|
||||
// File: Texenvmap.fx
|
||||
//
|
||||
// DirectX Texture environment map tool shaders
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
Texture2D<float4> Texture : register(t0);
|
||||
sampler Sampler : register(s0);
|
||||
|
||||
cbuffer Parameters : register(b0)
|
||||
{
|
||||
float4x4 Transform;
|
||||
}
|
||||
|
||||
struct VSInput
|
||||
{
|
||||
float4 Position : SV_Position;
|
||||
float2 TexCoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct VSOutput
|
||||
{
|
||||
float4 PositionPS : SV_Position;
|
||||
float2 TexCoord : TEXCOORD0;
|
||||
float3 LocalPos : TEXCOORD1;
|
||||
};
|
||||
|
||||
// Vertex shader: basic.
|
||||
VSOutput VSBasic(VSInput vin)
|
||||
{
|
||||
VSOutput vout;
|
||||
|
||||
vout.LocalPos = vin.Position.xyz;
|
||||
vout.PositionPS = mul(vin.Position, Transform);
|
||||
vout.TexCoord = vin.TexCoord;
|
||||
|
||||
return vout;
|
||||
}
|
||||
|
||||
// Pixel shader: basic
|
||||
float4 PSBasic(VSOutput pin) : SV_Target0
|
||||
{
|
||||
float3 color = Texture.Sample(Sampler, pin.TexCoord).rgb;
|
||||
return float4(color, 1.0);
|
||||
}
|
||||
|
||||
// Pixel shader: Equirectangular projection to cubemap
|
||||
float2 SphereMap(float3 vec)
|
||||
{
|
||||
float2 uv = float2(atan2(vec.z, vec.x), asin(vec.y));
|
||||
uv *= float2(0.1591, 0.3183);
|
||||
uv += 0.5;
|
||||
return uv;
|
||||
}
|
||||
|
||||
float4 PSEquiRect(VSOutput pin) : SV_Target0
|
||||
{
|
||||
float2 uv = SphereMap(normalize(pin.LocalPos));
|
||||
|
||||
float3 color = Texture.Sample(Sampler, uv).rgb;
|
||||
return float4(color, 1.0);
|
||||
}
|
||||
Reference in New Issue
Block a user