public static Vector3 GetCloudColor( Texture2DResource cloudTexture, SamplerResource samplerState, Vector2 cloudUV) { return(Sample(cloudTexture, samplerState, cloudUV).XYZ()); }
private void FormGame_Load(object sender, EventArgs e) { if (DesignMode) { return; } var resolver = new GenericFileResolver("GameContent"); var resourceManager = new ResourceManager(resolver); resourceManager.RegisterLoader(new Model3DLoader(), ".fbx"); resourceManager.RegisterLoader(new Texture2DLoader(), ".png;.jpg;.bmp;.tga;.dds"); model = resourceManager.Load <Model3DResource>("material_sample.fbx"); floor = resourceManager.Load <Model3DResource>("floor.fbx"); texture[0] = resourceManager.Load <Texture2DResource>("DefaultMaterial_Base_Color.png"); normalmap[0] = resourceManager.Load <Texture2DResource>("DefaultMaterial_Normal_DirectX.png"); metallicmap[0] = resourceManager.Load <Texture2DResource>("DefaultMaterial_Metallic.png"); roughnessmap[0] = resourceManager.Load <Texture2DResource>("DefaultMaterial_Roughness.png"); texture[1] = resourceManager.Load <Texture2DResource>("t1_c.png"); normalmap[1] = resourceManager.Load <Texture2DResource>("t1_n.png"); metallicmap[1] = resourceManager.Load <Texture2DResource>("t1_m.png"); roughnessmap[1] = resourceManager.Load <Texture2DResource>("t1_r.png"); texture[2] = resourceManager.Load <Texture2DResource>("t2_c.png"); normalmap[2] = resourceManager.Load <Texture2DResource>("t2_n.png"); metallicmap[2] = resourceManager.Load <Texture2DResource>("t2_m.png"); roughnessmap[2] = resourceManager.Load <Texture2DResource>("t2_r.png"); texture[3] = resourceManager.Load <Texture2DResource>("floor_c.png"); normalmap[3] = resourceManager.Load <Texture2DResource>("floor_n.png"); metallicmap[3] = resourceManager.Load <Texture2DResource>("floor_m.png"); roughnessmap[3] = resourceManager.Load <Texture2DResource>("floor_r.png"); cubemap = resourceManager.Load <Texture2DResource>("yoko.dds"); control = new ControlViewport() { Dock = DockStyle.Fill }; control.CustomRender += ControlOnCustomRender; Controls.Add(control); control.MouseMove += ControlOnMouseMove; control.KeyDown += ControlOnKeyDown; control.KeyUp += ControlOnKeyUp; gameLoopWatch = Stopwatch.StartNew(); gameTimer = new Timer(); gameTimer.Interval = 15; gameTimer.Tick += GameTimerOnTick; gameTimer.Start(); camera.Position = Vector3.ForwardLH * 10f; }
private Vector4 SampleTexture( Vector3 worldNormal, Vector2 uv, Vector2 screenPosition, TextureMapping textureMapping, Texture2DResource diffuseTexture, Vector3 viewVector) { const float twoPi = 2 * 3.1415926535f; var t = GlobalConstantsShared.TimeInSeconds; switch (textureMapping.MappingType) { case 0: // TEXTURE_MAPPING_UV { uv = new Vector2(uv.X, 1 - uv.Y); break; } case 1: // TEXTURE_MAPPING_ENVIRONMENT { uv = (Vector3.Reflect(viewVector, worldNormal).XY() / 2.0f) + new Vector2(0.5f, 0.5f); break; } case 2: // TEXTURE_MAPPING_LINEAR_OFFSET { var offset = textureMapping.UVPerSec * t; uv = new Vector2(uv.X, 1 - uv.Y) + offset; uv *= textureMapping.UVScale; break; } case 3: // TEXTURE_MAPPING_ROTATE { var angle = textureMapping.Speed * t * twoPi; var s = Sin(angle); var c = Cos(angle); uv -= textureMapping.UVCenter; var rotatedPoint = new Vector2( uv.X * c - uv.Y * s, uv.X * s + uv.Y * c); uv = rotatedPoint + textureMapping.UVCenter; uv *= textureMapping.UVScale; break; } case 4: // TEXTURE_MAPPING_SINE_LINEAR_OFFSET { uv.X += textureMapping.UVAmplitude.X * Sin(textureMapping.UVFrequency.X * t * twoPi - textureMapping.UVPhase.X * twoPi); uv.Y += textureMapping.UVAmplitude.Y * Cos(textureMapping.UVFrequency.Y * t * twoPi - textureMapping.UVPhase.Y * twoPi); break; } case 5: // TEXTURE_MAPPING_SCREEN { uv = (screenPosition / GlobalConstantsPS.ViewportSize) * textureMapping.UVScale; break; } case 6: // TEXTURE_MAPPING_SCALE { uv *= textureMapping.UVScale; break; } case 7: // TEXTURE_MAPPING_GRID { uv = new Vector2(uv.X, 1 - uv.Y); // TODO: This should really use a uint overload of Pow. var numFramesPerSide = Pow(2f, textureMapping.Log2Width); var numFrames = numFramesPerSide * numFramesPerSide; var currentFrame = Mod(t * textureMapping.FPS, numFrames); var currentFrameU = Mod(currentFrame, numFramesPerSide); var currentFrameV = currentFrame / numFramesPerSide; uv.X += currentFrameU / numFramesPerSide; uv.Y += currentFrameV / numFramesPerSide; break; } } return(Sample(diffuseTexture, Sampler, uv)); }
public static Vector4 Sample(Texture2DResource texture, SamplerResource sampler, Vector2 texCoords) => throw new ShaderBuiltinException();
private Vector4 SampleTexture(Texture2DResource myTexture, SamplerResource mySampler) { return(Sample(myTexture, mySampler, Vector2.Zero)); }
private Vector4 SampleTexture( Vector3 worldNormal, Vector2 uv, Vector2 screenPosition, TextureMapping textureMapping, Texture2DResource diffuseTexture, Vector3 viewVector) { const float twoPi = 2 * 3.1415926535f; var t = GlobalConstantsShared.TimeInSeconds; switch (textureMapping.MappingType) { case TextureMappingType.Uv: { uv = new Vector2(uv.X, 1 - uv.Y); break; } case TextureMappingType.Environment: { uv = (Vector3.Reflect(viewVector, worldNormal).XY() / 2.0f) + new Vector2(0.5f, 0.5f); break; } case TextureMappingType.LinearOffset: { var offset = textureMapping.UVPerSec * t; uv = new Vector2(uv.X, 1 - uv.Y) + offset; uv *= textureMapping.UVScale; break; } case TextureMappingType.Rotate: { var angle = textureMapping.Speed * t * twoPi; var s = Sin(angle); var c = Cos(angle); uv -= textureMapping.UVCenter; var rotatedPoint = new Vector2( uv.X * c - uv.Y * s, uv.X * s + uv.Y * c); uv = rotatedPoint + textureMapping.UVCenter; uv *= textureMapping.UVScale; break; } case TextureMappingType.SineLinearOffset: { uv.X += textureMapping.UVAmplitude.X * Sin(textureMapping.UVFrequency.X * t * twoPi - textureMapping.UVPhase.X * twoPi); uv.Y += textureMapping.UVAmplitude.Y * Cos(textureMapping.UVFrequency.Y * t * twoPi - textureMapping.UVPhase.Y * twoPi); break; } case TextureMappingType.Screen: { uv = (screenPosition / GlobalConstantsPS.ViewportSize) * textureMapping.UVScale; break; } case TextureMappingType.Scale: { uv *= textureMapping.UVScale; break; } case TextureMappingType.Grid: { uv = new Vector2(uv.X, 1 - uv.Y); // TODO: This should really use a uint overload of Pow. var numFramesPerSide = Pow(2f, textureMapping.Log2Width); var numFrames = numFramesPerSide * numFramesPerSide; var currentFrame = Mod(t * textureMapping.Fps, numFrames); var currentFrameU = Mod(currentFrame, numFramesPerSide); var currentFrameV = currentFrame / numFramesPerSide; uv.X += currentFrameU / numFramesPerSide; uv.Y += currentFrameV / numFramesPerSide; break; } } return(Sample(diffuseTexture, Sampler, uv)); }