1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-19 11:21:31 +02:00

remove sEnvironment sampler from shaders

This commit is contained in:
Timur Gagiev
2020-11-06 05:06:31 +03:00
parent 1e38d9f2fa
commit 1f6c3a771e
6 changed files with 40 additions and 26 deletions

View File

@@ -44,16 +44,21 @@ struct VS_INPUT {
SamplerState smpLinearWrap : register(s4); SamplerState smpLinearWrap : register(s4);
SamplerComparisonState smpCmp : register(s5); SamplerComparisonState smpCmp : register(s5);
Texture2D sDiffuse : register(t0); #ifdef DIFFUSE_AS_CUBE
#ifdef NORMAL_AS_3D TextureCube sDiffuse : register(t0);
Texture3D sNormal : register(t1); #else
#else Texture2D sDiffuse : register(t0);
Texture2D sNormal : register(t1); #endif
#endif
#ifdef NORMAL_AS_3D
Texture3D sNormal : register(t1);
#else
Texture2D sNormal : register(t1);
#endif
Texture2D sReflect : register(t2); Texture2D sReflect : register(t2);
Texture2D sShadow : register(t3); Texture2D sShadow : register(t3);
TextureCube sEnvironment : register(t4); Texture2D sMask : register(t4);
Texture2D sMask : register(t5);
#define SAMPLE_2D(T,uv) T.Sample(smpDefault, uv) #define SAMPLE_2D(T,uv) T.Sample(smpDefault, uv)
#define SAMPLE_2D_POINT(T,uv) T.Sample(smpPoint, uv) #define SAMPLE_2D_POINT(T,uv) T.Sample(smpPoint, uv)
@@ -64,13 +69,19 @@ struct VS_INPUT {
#define SAMPLE_2D_LOD0(T,uv) T.SampleLevel(smpLinear, uv, 0) #define SAMPLE_2D_LOD0(T,uv) T.SampleLevel(smpLinear, uv, 0)
#define SAMPLE_3D(T,uv) T.SampleLevel(smpLinearWrap, uv, 0) #define SAMPLE_3D(T,uv) T.SampleLevel(smpLinearWrap, uv, 0)
#define SAMPLE_CUBE(T,uv) T.Sample(smpLinear, uv) #define SAMPLE_CUBE(T,uv) T.Sample(smpLinear, uv)
#define POSITION SV_POSITION
#else #else
sampler2D sDiffuse : register(s0); #ifdef DIFFUSE_AS_CUBE
samplerCUBE sDiffuse : register(s0);
#else
sampler2D sDiffuse : register(s0);
#endif
sampler2D sNormal : register(s1); sampler2D sNormal : register(s1);
sampler2D sReflect : register(s2); sampler2D sReflect : register(s2);
sampler2D sShadow : register(s3); sampler2D sShadow : register(s3);
samplerCUBE sEnvironment : register(s4); sampler2D sMask : register(s4);
sampler2D sMask : register(s5);
#define SAMPLE_2D(T,uv) tex2D(T, uv) #define SAMPLE_2D(T,uv) tex2D(T, uv)
#define SAMPLE_2D_POINT(T,uv) tex2D(T, uv) #define SAMPLE_2D_POINT(T,uv) tex2D(T, uv)
@@ -82,7 +93,9 @@ struct VS_INPUT {
#define SAMPLE_3D(T,uv) tex3D(T, uv) #define SAMPLE_3D(T,uv) tex3D(T, uv)
#define SAMPLE_CUBE(T,uv) texCUBE(T, uv) #define SAMPLE_CUBE(T,uv) texCUBE(T, uv)
#define SV_POSITION POSITION #ifdef PIXEL
#define POSITION VPOS
#endif
#endif #endif
float4 uParam : register( c0 ); float4 uParam : register( c0 );

View File

@@ -247,10 +247,10 @@ varying vec4 vTexCoord; // xy - atlas coords, zw - trapezoidal correction
#else #else
uniform sampler2D sDiffuse;
#ifdef TYPE_MIRROR #ifdef TYPE_MIRROR
uniform samplerCube sEnvironment; uniform samplerCube sDiffuse;
#else
uniform sampler2D sDiffuse;
#endif #endif
float unpack(vec4 value) { float unpack(vec4 value) {
@@ -356,7 +356,7 @@ varying vec4 vTexCoord; // xy - atlas coords, zw - trapezoidal correction
vec4 color; vec4 color;
#ifdef TYPE_MIRROR #ifdef TYPE_MIRROR
vec3 rv = reflect(-normalize(vViewVec.xyz), normalize(vNormal.xyz)); vec3 rv = reflect(-normalize(vViewVec.xyz), normalize(vNormal.xyz));
color = textureCube(sEnvironment, normalize(rv)); color = textureCube(sDiffuse, normalize(rv));
#else #else
#ifndef TYPE_SPRITE #ifndef TYPE_SPRITE
#ifdef OPT_TRAPEZOID #ifdef OPT_TRAPEZOID

View File

@@ -1,3 +1,4 @@
#define DIFFUSE_AS_CUBE
#include "common.hlsl" #include "common.hlsl"
struct VS_OUTPUT { struct VS_OUTPUT {
@@ -31,7 +32,7 @@ VS_OUTPUT main(VS_INPUT In) {
float4 main(VS_OUTPUT In) : COLOR0 { float4 main(VS_OUTPUT In) : COLOR0 {
float3 rv = reflect(-In.viewVec.xyz, In.normal.xyz); float3 rv = reflect(-In.viewVec.xyz, In.normal.xyz);
float4 color = SAMPLE_CUBE(sEnvironment, normalize(rv)); float4 color = SAMPLE_CUBE(sDiffuse, normalize(rv));
color *= uMaterial; color *= uMaterial;
color.xyz = saturate(color.xyz); color.xyz = saturate(color.xyz);

View File

@@ -71,14 +71,14 @@ uniform mat4 uViewProj;
#endif #endif
#ifdef FILTER_EQUIRECTANGULAR #ifdef FILTER_EQUIRECTANGULAR
uniform samplerCube sEnvironment; uniform samplerCube sDiffuse;
#define PI 3.14159265358979323846 #define PI 3.14159265358979323846
vec4 equirectangular() { vec4 equirectangular() {
vec2 a = (vTexCoord - 0.5) * vec2(PI * 2.0, PI); vec2 a = (vTexCoord - 0.5) * vec2(PI * 2.0, PI);
vec3 v = vec3(sin(a.x) * cos(a.y), -sin(a.y), cos(a.x) * cos(a.y)); vec3 v = vec3(sin(a.x) * cos(a.y), -sin(a.y), cos(a.x) * cos(a.y));
return textureCube(sEnvironment, normalize(v)); return textureCube(sDiffuse, normalize(v));
} }
#endif #endif

View File

@@ -3,7 +3,7 @@
#include "common.hlsl" #include "common.hlsl"
struct VS_OUTPUT { struct VS_OUTPUT {
float4 pos : SV_POSITION; float4 pos : POSITION;
half4 color : TEXCOORD0; half4 color : TEXCOORD0;
half2 texCoord : TEXCOORD1; half2 texCoord : TEXCOORD1;
float3 coord : TEXCOORD2; float3 coord : TEXCOORD2;

View File

@@ -30,12 +30,12 @@ float boxIntersect(float3 rayPos, float3 rayDir, float3 center, float3 hsize) {
return max(0.0, max(m.x, max(m.y, m.z))); return max(0.0, max(m.x, max(m.y, m.z)));
} }
#ifdef _GAPI_GXM #if defined(_GAPI_GXM)
float4 main(VS_OUTPUT In) : COLOR0 { float4 main(VS_OUTPUT In) : COLOR0 {
float2 pixelCoord = float2(__pixel_x(), __pixel_y()); float2 pixelCoord = float2(__pixel_x(), __pixel_y());
#else defined(_GAPI_D3D11 #else
float4 main(VS_OUTPUT In) : COLOR0 { float4 main(VS_OUTPUT In) : COLOR0 {
float2 pixelCoord = In.pos.xy; float2 pixelCoord = In.pos.xy;
#endif #endif
float3 viewVec = normalize(In.viewVec); float3 viewVec = normalize(In.viewVec);